ROI,感兴趣区域(region of interest),截取图像
方法1:使用Rect
cv::Mat src=cv::imread("*.bmp");//读取原图
cv::Mat matROI = src(cv::Rect(100,200,50,100));//截取原图,矩形区域
方法2:使用Range
cv::Mat src=cv::imread("*.bmp");//读取原图
cv::Mat matROI = src(cv::Range(100,150),cv::Range(200,300));//截取原图,矩形区域
注:Mat类型中copyTo函数和clone函数和赋值操作符操作。
stringstream ss;
cv::Mat src = cv::imread("BK5.jpg");//3通道彩图
cv::Mat* srcPointer = &src;
cv::Mat srcROI = src(cv::Rect(src.rows / 2 - 100, src.cols / 2 - 100, 100, 100));
ss << "src.isContinuous=" << src.isContinuous() <
指针版
stringstream ss;
cv::Mat src = cv::imread("BK5.jpg");//3通道彩图
cv::Mat srcROI = src(cv::Rect(src.rows / 2 - 100, src.cols / 2 - 100, 100, 100));
cv::Mat* srcROIPointer = &srcROI;
ss << "src.isContinuous=" << src.isContinuous() <rows, srcROIPointer->cols, srcROIPointer->type(), cv::Scalar(0));
srcROI_End.copyTo(*srcROIPointer);
ss << "srcROI - Memery Address:" << &srcROI << endl;
cv::imshow("srcROI", *srcROIPointer);
cv::imshow("src-Result", src);
qDebug() << ss.str().c_str();
src.isContinuous=1
src.type=16
srcROI - Memery Address:000000EF810FF980
srcROI - Memery Address:000000EF810FF980
原图的ROI区域,图片被处理。
类型/尺寸相同,copyTo时,ROI图元修改会生效到原图中。
stringstream ss;
cv::Mat src = cv::imread("BK5.jpg");//3通道彩图
cv::Mat* srcPointer = &src;
cv::Mat srcROI = src(cv::Rect(src.rows / 2 - 100, src.cols / 2 - 100, 100, 100));
ss << "src.isContinuous=" << src.isContinuous() <
src.isContinuous=1
src.type=16
srcROI - Memery Address:000000EF810FF980
srcROI - Memery Address:000000EF810FF980
原图的ROI区域,无处理效果。
类型不同,尺寸相同,copyTo时,ROI图元不会生效到原图中。
stringstream ss;
cv::Mat src = cv::imread("BK5.jpg");//3通道彩图
cv::Mat* srcPointer = &src;
cv::Mat srcROI = src(cv::Rect(src.rows / 2 - 100, src.cols / 2 - 100, 100, 100));
ss << "src.isContinuous=" << src.isContinuous() <
src.isContinuous=1
src.type=16
srcROI - Memery Address:000000FC6E10F8E0
srcROI - Memery Address:000000FC6E10F8E0
原图的ROI区域,无处理效果。
类型相同,尺寸不同,copyTo时,ROI图元不会生效到原图中。
stringstream ss;
cv::Mat src = cv::imread("BK5.jpg");//3通道彩图
cv::Mat* srcPointer = &src;
cv::Mat srcROI = src(cv::Rect(src.rows / 2 - 100, src.cols / 2 - 100, 100, 100));
ss << "src.isContinuous=" << src.isContinuous() <
src.isContinuous=1
src.type=16
srcROI - Memery Address:00000006268FF560
srcROI - Memery Address:00000006268FF560
原图的ROI区域,无处理效果。
clone时,ROI图元不会生效到原图中。
绿色掩膜
stringstream ss;
cv::Mat src = cv::imread("BK5.jpg");//3通道彩图
cv::Mat srcROI = src(cv::Rect(src.rows / 2 - 100, src.cols / 2 - 100, 100, 100));
cv::Mat* srcROIPointer = &srcROI;
ss << "src.isContinuous=" << src.isContinuous() << endl;
ss << "src.type=" << src.type() << endl;
ss << "srcROI - Memery Address:" << &srcROI << endl;
cv::Mat srcROI_End = cv::Mat(srcROIPointer->rows, srcROIPointer->cols, srcROIPointer->type(), cv::Scalar(0, 255, 0));
cv::Mat srcROI_Mask = cv::Mat(srcROIPointer->rows, srcROIPointer->cols, srcROIPointer->type(), cv::Scalar(0, 255, 0));
srcROI_End.copyTo(*srcROIPointer, srcROI_Mask);
ss << "srcROI - Memery Address:" << &srcROI << endl;
cv::imshow("srcROI", *srcROIPointer);
cv::imshow("src-Result", src);
qDebug() << ss.str().c_str();