Skip to content

Latest commit

 

History

History
132 lines (113 loc) · 3.83 KB

File metadata and controls

132 lines (113 loc) · 3.83 KB

#HSLIDE

Robot vision tutorial with OpenCV

Part One


Find Wally

#HSLIDE

Goals of this Tutorial

  • find Wally :-)
  • integrating YARP with OpenCV
  • yarp::os::RFModule
  • Thrift services
  • performing simple image processing operations

#VSLIDE

Let's plan what to do...

  • Change CMakeLists.txt to find OpenCV correctly
  • Load image containing the full scene.
  • Display it: stream it through a yarp port to a yarpviewer.
  • Load wally's template and run the template matching algorithm with correct method to figure out where wally is in the scene
  • Modify the streamed image to display the location of wally.

#HSLIDE

CMakeLists modifications

#VSLIDE

CMakeLists modifications

######

CMakeLists additions

find_package(YARP 3.1.101 REQUIRED)
find_package(ICUBcontrib REQUIRED)
find_package(OpenCV REQUIRED)
include_directories(${YARP_INCLUDE_DIRS} ${OpenCV_INCLUDE_DIRS})
target_link_libraries(${PROJECT_NAME} ${YARP_LIBRARIES}
                                      ${OpenCV_LIBS})

######

Code headers additions

#include <opencv2/core/core.hpp>
#include <opencv2/opencv.hpp>

#HSLIDE

Load an image

#VSLIDE

Load an image

######

IDL Services

/**
 * Load the two required images.
 * @param mainImage name of the image to be loaded.
 * @return true/false on success/failure.
 */
bool load(1:string image);

######

Code

yarp::os::ResourceFinder rf;
rf.setVerbose();
rf.setDefaultContext(this->rf->getContext().c_str());

std::string imageStr = rf.findFile(image.c_str());

cv::Mat inputImage;
inputImage = cv::imread(imageStr, CV_LOAD_IMAGE_COLOR);

#HSLIDE

Stream the image onto a YARP port

#VSLIDE

Stream the image onto a YARP port

yarp::os::BufferedPort<yarp::sig::ImageOf<yarp::sig::PixelRgb>> imageOutPort;

imageOutPort.open(("/"+getName("/image:o")).c_str());

imageOutPort.close();

yarp::sig::ImageOf<yarp::sig::PixelRgb> &outImg = imageOutPort.prepare();
outImg = yarp::cv::fromCvMat<yarp::sig::PixelRgb>(out_image);
imageOutPort.write();

#HSLIDE

Run the template tracker algorithm

#VSLIDE

Run the template tracker algorithm

######

IDL Services

/**
 * use template matching on image with desired template and
 * desired method
 * @param template name of the image to be loaded.
 * @param name of method: 0=SQDIFF, 1=SQDIFF NORMED,
 * 2=TM CCORR, 3=TM CCORR NORMED, 4=TM COEFF, 5=TM COEFF NORMED
 * @return Bottle containing the 2D position.
 */
Bottle templateMatch(1:string image, 2:i32 method);

######

template methods

//Use the OpenCV function matchTemplate to search for matches between an
//image patch and an input image
void matchTemplate(InputArray image, InputArray templ, OutputArray result, int method);
//Use the OpenCV function minMaxLoc to find the maximum and minimum values
//(as well as their positions) in a given array.
void minMaxLoc( result, &minVal, &maxVal, &minLoc, &maxLoc, cv::Mat() );

#HSLIDE The End :)