I have a Point array (i have 4 coordinates at all) and need to set custom ROI by those. But all examples i was able to find only use 2 coordinates of an image. In addiction when i try to use cv::Point to set ROI, i am getting an error
error: cannot convert 'cv::Point' to 'int' for argument '1' to 'CvRect cvRect(int, int, int, int)'
Would be realy thankful for help, if someone can explain me how it works.
Sure, here it is:
cv::Point pointArray[4];
int i = 0;
cv::Mat ref = cv::imread("image.png");
cv::GaussianBlur(ref, ref, cv::Size(5, 5), 0, 0);
cv::Mat tpl = cv::imread("template1.png");
if (ref.empty() || tpl.empty())
return -1;
cv::Mat gref, gtpl;
cv::cvtColor(ref, gref, CV_BGR2GRAY);
cv::cvtColor(tpl, gtpl, CV_BGR2GRAY);
cv::Mat res(ref.rows-tpl.rows+1, ref.cols-tpl.cols+1, CV_32FC1);
cv::matchTemplate(gref, gtpl, res, CV_TM_CCOEFF_NORMED);
cv::threshold(res, res, 0.8, 1., CV_THRESH_TOZERO);
while (true)
{
double minval, maxval, threshold = 0.8; cv::Point minloc, maxloc; cv::minMaxLoc(res, &minval, &maxval, &minloc, &maxloc);
if (maxval >= threshold)
{
cv::floodFill(res, maxloc, cv::Scalar(0), 0, cv::Scalar(.1), cv::Scalar(1.));
int x = maxloc.x + tpl.cols/2;
int y = maxloc.y + tpl.rows/2;
pointArray[i] = cv::Point(x,y);
i++;
cv::circle(ref, cv::Point(x, y), 2, CV_RGB(0, 0, 255));
} else
break;
// cvSetImageROI(ref, cvRect(pointArray[1],pointArray[2]));
}