Skip to content

Latest commit

 

History

History
99 lines (87 loc) · 3.34 KB

PITCHME.md

File metadata and controls

99 lines (87 loc) · 3.34 KB

#HSLIDE

Robot vision tutorial with OpenCV

Part Two


YARP & OPENCV

#HSLIDE

Goals of this Tutorial

  • 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

Let's plan what to do...

  • 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

Read an Image from a stream using port callback

#VSLIDE

Read an Image from a stream using port callback

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

Some Image Processing techniques

#VSLIDE

Some Image Processing techniques

######

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

Draw and display results

#VSLIDE

Draw and display results

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 :)