您好目前有一些代码可以使用蒙版拉动感兴趣的区域。我想反过来消除ROI并只使用背景。这是我目前的代码。任何人的帮助都应该是相当微不足道的,但我不太了解openCV。
cv::Mat detectLanes::createTrapezoidROIInverse(cv::Mat TargetImg , vector<Vec2f> laneEndPoints)
{
// float height = TargetImg.rows;
// float width = TargetImg.cols;
// account for 5% error
cout<<"laneEP"<<laneEndPoints[0][0]<<endl;
Point LLBI(laneEndPoints[0][0]*1.05,laneEndPoints[0][1]);
Point LLTI(laneEndPoints[1][0]*1.05,laneEndPoints[1][1]);
Point RLBI(laneEndPoints[2][0]*0.95,laneEndPoints[2][1]);
Point RLTI(laneEndPoints[3][0]*0.95,laneEndPoints[3][1]);
//create Mask to Pull out ROI
Mat mask = cv::Mat::zeros(TargetImg.size(),CV_8UC1);
vector< vector<Point> > co_ordinates;
co_ordinates.push_back(vector<Point>());
co_ordinates[0].push_back(LLBI);
co_ordinates[0].push_back(LLTI);
co_ordinates[0].push_back(RLTI);
co_ordinates[0].push_back(RLBI);
drawContours( mask,co_ordinates,0, Scalar(255),CV_FILLED, 8 );
// mask(Rect(0.1*width,0.3*height,0.55*width,0.5*height)) = 255;
TargetImg &= mask;
return TargetImg;
}
答案 0 :(得分:0)
使用时不用担心简单:
TargetImg - = mask;
代替。