您好,我的代码有一个小问题。我已经编写了完整的代码来识别感兴趣的区域。我有一个小型静态相机,可以捕获空的停车位。我需要定义一个感兴趣的静态区域,当相机捕获第一个图像时,请定义感兴趣的位置。
void regionOfInterest(Mat& frame){
Mat hsvImage;
cvtColor(frame,hsvImage,COLOR_RGB2HSV);
vector<Mat>HSV_CHANNELS;
split(hsvImage, HSV_CHANNELS);
Mat hueImage = HSV_CHANNELS[0];
Mat hueMask;
inRange(hueImage, hueValue - hueRange, hueValue + hueRange, hueMask);
if (hueValue - hueRange < 0 || hueValue + hueRange > 180){
Mat hueMaskUpper;
int upperHueValue = hueValue + 180;
inRange(hueImage, upperHueValue - hueRange, upperHueValue + hueRange, hueMaskUpper);
hueMask = hueMask | hueMaskUpper;
}
Mat saturationMask = HSV_CHANNELS[1] > minSaturation;
Mat valueMask = HSV_CHANNELS[2] > minValue;
hueMask = (hueMask & saturationMask) & valueMask;
vector<Vec4i> lines;
HoughLinesP(hueMask, lines, 1, CV_PI/360, 50, 50, 10);
for (unsigned int i = 0; i < lines.size(); ++i){
Point(lines[i][0], lines[i][1]);
Point(lines[i][2], lines[i][3]);
}
vector<Point>pts;
for(unsigned int i = 0; i < lines.size(); i++){
pts.push_back(Point(lines[i][0],lines[i][1]));
pts.push_back(Point(lines[i][2],lines[i][3]));
}
/*GET THE PREVIOUS POINTS DETECTED IN THE IMAGE*/
Rect box = boundingRect(pts);
/*DRAW RECTANGLE REGION OF INTEREST*/
rectangle(frame, box.tl(), box.br(), Scalar(0, 255, 0), 2);
}