Hough circle transform error(opencv,openfxcv, opengui)

vector circles;
HoughCircles(matCamEdge, circles, CV_HOUGH_GRADIENT, 2, 50, 30, 100, 30, 50);
for (int i = 0; i < circles.size(); i++) {
ofSetColor(255, 0, 0);
ofDrawCircle(circles[i][0], circles[i][1], circles[i][2]);
}

why when i add this to my code,
error occurs?

Error: Assertion failed (!_image.empty() && _image.type() == CV_8UC1 && (_image.isMat() || _image.isUMat())) in cv::HoughCircles

p.s.matCamEdge is born from this: setFromPixels(myVideoGrabber.getPixels())>>toCV>>cvtcolor to gray image>> canny

Hi @dreamercleohope,

I’ve never worked with HoughCircles, so I may not be much help. But from your description of the error, I’m thinking that the image may be causing the “Assertion failed”. Did you call matCamEdge.update() after you .setFromPixels(), but before converting it to an openCV image? Then, it looks like the image type must be CV_8UC1, which is an 8-bit unsigned image with 1 color. So you may want to set the ofImage type to OF_GRAYSCALE_IMAGE before you convert it to a CV image; you can do this when you call .setFromPixels(). matCamEdge must also return true for .isMat() or .isUMat(). So, if you can get matCamEdge to satisfy both requirements, it should pass the assertion.

Sometimes it helps to evaluate small pieces of code when troubleshooting these types of errors, starting with a simple (base) case and adding complexity until you get what you want.