Mat 变换错误排查

6 篇文章 0 订阅

 

背景

想执行一个平移变换

try
{
        cv::Mat original_points = (cv::Mat_<int>(3, 2, CV_8UC1) << 1, 1, 1, 2, 3, 1);

		// Define the transformed coordinates
		cv::Mat transformed_points = (cv::Mat_<int>(3, 2) << 2, 2, 2, 3, 4, 2);

		// Calculate the transformation matrix
		cv::Mat T = cv::getAffineTransform(original_points, transformed_points);

		// Print the transformation matrix
		/*qDebug() << "Transformation matrix:";
		qDebug() << cv::format(original_points, cv::Formatter::FMT_C);*/
		std::cout << "T value is: \r\n" << original_points << "\r\n channels:" <<             
        original_points.channels() << std::endl;
		std::cout << "T value is: \r\n" << T << std::endl;
		//qDebug() << T ;
		 //Use the transformation matrix to transform a new point
		cv::Mat new_point = (cv::Mat_<float>(1, 1) << 4);
		cv::Mat transformed_point;
		cv::transform(new_point, transformed_point, T);

		// Print the transformed point
		std::cout << "Transformed point:" << std::endl;
		std::cout << transformed_point << std::endl;

	}
	catch (const cv::Exception& e)
	{
		std::cout << e.what();
	}

结果报错:

Error: Assertion failed (src.checkVector(2, CV_32F) == 3 && dst.checkVector(2, CV_32F) == 3) in cv::getAffineTransform, file D:\opencv\opencv-3.4.16\modules\imgproc\src\imgwarp.cpp, line 3407

将矩阵的类型修改如下:

cv::Mat transformed_points = (cv::Mat_<float>(3, 2) << 2, 2, 2, 3, 4, 2);

此问题解决,但是报错:

Assertion failed (scn == m.cols || scn + 1 == m.cols) in cv::transform, file D:\opencv\opencv-3.4.16\modules\core\src\matmul.dispatch.cpp

 error: (-215:Assertion failed) scn == m.cols || scn + 1 == m.cols in function 'cv::transform'

这个问题在于transform()用错了,gpt有毒啊,这里应该用warpAffine();

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值