Reputation: 5422
I'm trying to get contours from my frame and this is what I have done:
cv::Mat frame,helpframe,yframe,frame32f;
Videocapture cap(1);
.......
while(waitkey()){
cv::Mat result = cv::Mat::zeros(height,width,CV_32FC3);
cap >> frame; // get a new frame from camera
frame.convertTo(frame32f,CV_32FC3);
for ( int w = 0; w< 10;w ++){
result += frame32f;
}
//Average the frame values.
result *= (1.0/10);
result /= 255.0f;
cvtColor(result,yframe,CV_RGB2YCrCb); // converting to Ycbcr///// the code work fine when I use frame instead of result
extractChannel(yframe,helpframe,0); //extracting the Y channel
cv::minMaxLoc(helpframe,&minValue,&maxValue,&min,&max);
std::vector<std::vector<cv::Point>> contours;
cv::findContours(helpframe, contours,CV_RETR_LIST /*CV_RETR_EXTERNAL*/, CV_CHAIN_APPROX_SIMPLE);
....................................................
the program crashs at findcontours
, and I debbug I get this error message:
OpenCV Error: Unsupported format or combination of formats ([Start]FindContours support only 8uC1 and 32sC1 images) in unknown function, file ......\src\openc v\modules\imgproc\src\contours.cpp, line 196
@Niko thanks for help I think that I have to convert helpframe to another type.
when I use result I get for
helpframe.type() => 5
and with frame I get 0
I don't know what does it mean ? but I'll try to find a way to convert helpframe.
after converting helpframe with : helpframe.convertTo(helpframe2,CV_8U)
I get nothing helpframe2 is = 0 ?? and when I try the same with frame instead of resultframe the conversion works ??
Any idea how I should change the helpframe type because I use result instead of frame?
Upvotes: 3
Views: 4315
Reputation: 26730
You need to reduce the image to a binary image before you can identify contours. This can be done by, e.g., applying some kind of edge detection algorithm or by simple thresholding:
// Binarize the image
cv::threshold(helpframe, helpframe, 50, 255, CV_THRESH_BINARY);
// Convert from 32F to 8U
cv::Mat helpframe2;
helpframe.convertTo(helpframe2, CV_8U);
cv::findContours(helpframe2, ...);
Upvotes: 7