比较bloc检测和opencv中的结构分析和形状描述符

时间:2014-02-09 09:29:18

标签: opencv computer-vision blob shape

我需要使用斑点检测和结构分析和形状描述符(更具体地说是findContoursdrawContoursmoments)来检测图像中的彩色圆圈。我需要知道每种方法的优缺点,哪种方法更好。有人能告诉我这两种方法之间的区别吗?

1 个答案:

答案 0 :(得分:1)

正如@ scap3y在评论中所建议的那样,我会采用更简单的方法。在这些情况下,我一直在做的事情与此类似:

// Convert your image to HSV color space
Mat hsv;
hsv.create(originalImage.size(), CV_8UC3);
cvtColor(originalImage,hsv,CV_RGB2HSV);

// Chose the range in each of hue, saturation and value and threshold the other pixels
Mat thresholded;
uchar loH = 130, hiH = 170;
uchar loS = 40, hiS = 255;
uchar loV = 40, hiV = 255;
inRange(hsv, Scalar(loH, loS, loV), Scalar(hiH, hiS, hiV), thresholded);

// Find contours in the image (additional step could be to 
// apply morphologyEx() first)
vector<vector<Point>> contours;
findContours(thresholded,contours,CV_RETR_EXTERNAL,CHAIN_APPROX_SIMPLE);

// Draw your contours as ellipses into the original image
for(i=0;i<(int)valuable_rectangle_indices.size();i++) {
    rect=minAreaRect(contours[valuable_rectangle_indices[i]]);
    ellipse(originalImage, rect, Scalar(0,0,255));  // draw ellipse
}

现在唯一要做的就是找出HSV color space中标记的范围。