opencv 设置Roi release 问题

时间:20220812

问题描述:

将小图贴到大图中的指定区域,release下没报中断情况下失效

int fingerPrintImg_W = 640 * 4;// 640
int fingerPrintImg_H = 640 * 4;// 640

cv::Mat fingerPrintImg = cv::Mat(cv::Size(fingerPrintImg_W, fingerPrintImg_H), CV_8UC1);
fingerPrintImg.setTo(255); // 成功

int centerh = colorInversionRet.rows / 2;
int centerw = colorInversionRet.cols / 2;

int x_S, x_E, y_S, y_E;
if (colorInversionRet.cols > fingerPrintImg_W)
{
	x_S = centerw - fingerPrintImg_W / 2;
	x_E = centerw + fingerPrintImg_W / 2;
}
else
{
	x_S = 0;
	x_E = colorInversionRet.cols;
}

if (colorInversionRet.rows > fingerPrintImg_H)
{
	y_S = centerh - fingerPrintImg_H / 2;
	y_E = centerh + fingerPrintImg_H / 2;
}
else
{
	y_S = 0;
	y_E = colorInversionRet.rows;
}

	 
int fp_x_S, fp_x_E, fp_y_S, fp_y_E;
int fingerPrintImg_centerw = fingerPrintImg_W / 2;
int fingerPrintImg_centerh = fingerPrintImg_H / 2;
int roi_w = x_E - x_S;
int roi_h = y_E - y_S;
fp_x_S = fingerPrintImg_centerw - roi_w / 2;
fp_x_E = fingerPrintImg_centerw + roi_w / 2;
fp_y_S = fingerPrintImg_centerh - roi_h / 2;
fp_y_E = fingerPrintImg_centerh + roi_h / 2;

cv::Mat colorInversionRet_roi = colorInversionRet(cv::Rect(cv::Point2i(x_S, y_S), cv::Point2i(x_E, y_E)));

cv::Mat fingerPrintImg_roi = cv::Mat(fingerPrintImg, cv::Rect(cv::Point2i(fp_x_S, fp_y_S), cv::Point2i(fp_x_E, fp_y_E)));

colorInversionRet_roi.copyTo(fingerPrintImg_roi);

图像拷贝到fingerPrintImg_roi,但fingerPrintImg没有相应的改变。

最后发现:

fp_x_S = fingerPrintImg_centerw - roi_w / 2;
fp_x_E = fingerPrintImg_centerw + roi_w / 2;
fp_y_S = fingerPrintImg_centerh - roi_h / 2;
fp_y_E = fingerPrintImg_centerh + roi_h / 2;

导致fingerPrintImg_roi与colorInversionRet_roi大小不一致,从而导致修改fingerPrintImg的ROI区域失败。

这个问题奇怪的是fingerPrintImg_roi被填充了,也没报错!!!

记录下,一个是有整除的注意像素偏移和大小改变,改为下面这种形式会好点:

fp_x_S = fingerPrintImg_centerw - roi_w / 2;
fp_x_E = fp_x_S + roi_w;
fp_y_S = fingerPrintImg_centerh - roi_h / 2;
fp_y_E = fp_y_S + roi_h;

另一个的在debug下进行调试。

你可能感兴趣的:(opencv,opencv)