'm trying to make a roi of detected circles by HoughCircle so I type the following code:
vector<Vec3f> v3fCircles;
HoughCircles(region2, v3fCircles, HOUGH_GRADIENT, 2, 120, 70, 35, 40, 45);
for (int i = 0; i < v3fCircles.size(); i++) {
cout << v3fCircles[i][0] << "," << v3fCircles[i][1] << endl;
Rect box(v3fCircles[i][0] - v3fCircles[i][2], v3fCircles[i][1] - v3fCircles[i][2], 2 * v3fCircles[i][2], 2 * v3fCircles[i][2]);
Mat roi = mask(box);
circle(region2,
Point(v3fCircles[i][0], v3fCircles[i][1]),
3,
Scalar(0, 255, 255),
CV_FILLED);
circle(region2,
Point(v3fCircles[i][0], v3fCircles[i][1]),
v3fCircles[i][2],
Scalar(255, 0, 0),
2);}
Where region2 is another ROI of the original image (right 1/2 of the image where i detect circles)
The console output give me this after i=5
Error: Assertion failed (0 <= roi.x && 0 <= roi.width && roi.x + roi.width <= m.cols && 0 <= roi.y && 0 <= roi.height && roi.y + roi.height <= m.rows) in cv::Mat::Mat, file C:\build\3_4_winpack-build-win64-vc14\opencv\modules\core\src\matrix.cpp
Basically it says the rectangle roi is out of image range? what is wrong?