#HSLIDE
#HSLIDE
- Track something round and red :-)
- integrating YARP with OpenCV while getting live image streams.
- yarp::os::RFModule with port Callbacks
- Thrift services
- performing simple image processing operations
#VSLIDE
- Receive a stream of images from a port
- Use some image processing techniques to make things easier.
- Display it: stream it through a yarp port to a yarpviewer.
- Modify the streamed image to display the location of the red and round object.
#HSLIDE
#VSLIDE
class Module : public yarp::os::RFModule, public yarpOpencv_IDL
{
...
class Processing : public yarp::os::BufferedPort<yarp::sig::ImageOf<yarp::sig::PixelRgb> >
{
bool open(){
this->useCallback();
BufferedPort<yarp::sig::ImageOf<yarp::sig::PixelRgb> >::open( "/" + moduleName + "/image:i" );
...
}
void interrupt(){
BufferedPort<yarp::sig::ImageOf<yarp::sig::PixelRgb> >::interrupt();
}
void close()(){
BufferedPort<yarp::sig::ImageOf<yarp::sig::PixelRgb> >::close();
}
void onRead( yarp::sig::ImageOf<yarp::sig::PixelRgb> &img ){
cv::Mat in_cv = yarp::cv::toCvMat( img );
}
#HSLIDE
#VSLIDE
######
Spatial Filters
cv::GaussianBlur(redBallOnly, redBallOnly, cv::Size(gausian_size, gausian_size), 2, 2);
######
Morphology
cv::dilate(redBallOnly, redBallOnly, cv::Mat(), cv::Point(-1,-1), dilate_niter, cv::BORDER_CONSTANT, cv::morphologyDefaultBorderValue());
cv::erode(redBallOnly, redBallOnly, cv::Mat(), cv::Point(-1,-1), erode_niter, cv::BORDER_CONSTANT, cv::morphologyDefaultBorderValue());
######
Detect Circles
cv::HoughCircles(redBallOnly, circles, CV_HOUGH_GRADIENT, 1, redBallOnly.rows / 8, HIGH_THRESHOLD, HOUGH_MIN_VOTES, HOUGH_MIN_RADIUS, HOUGH_MAX_RADIUS);
#HSLIDE
#VSLIDE
for (size_t i = 0; i < circles.size(); i++)
{
cv::Point center(cvRound(circles[i][0]), cvRound(circles[i][1]));
int radius = cvRound(circles[i][2]);
// circle center
circle(in_cv, center, 3, cv::Scalar(0, 255, 0), -1, 8, 0);
// circle outline
circle(in_cv, center, radius, cv::Scalar(0, 0, 255), 3, 8, 0);
yarp::os::Bottle &t=outTargets.addList();
t.addDouble(center.x);
t.addDouble(center.y);
}
#HSLIDE The End :)