OpenCV图像翻转和旋转

  QString appPath = QCoreApplication::applicationDirPath();
	imagePath = appPath + "/A.jpg";
	img = cv::imread(imagePath.toStdString());
	if (img.empty())
		return;

	Mat dst;
	flip(img, dst, 0);//上下翻转
	imshow("flip0", dst);
	flip(img, dst, 1);//左右翻转
	imshow("flip1", dst);
	flip(img, dst, -1);//180°旋转
	imshow("flip-1", dst);

  int h = img.rows;
	int w = img.cols;
	Mat M = getRotationMatrix2D(Point2f(w / 2, h / 2), 45, 1.0);

	double cos = abs(M.at<double>(0, 0));
	double sin = abs(M.at<double>(0, 1));
	int nw = cos * w + sin * h;
	int nh = sin * w + cos * h;

	M.at<double>(0, 2) = M.at<double>(0, 2) + (nw / 2 - w / 2);
	M.at<double>(1, 2) = M.at<double>(1, 2) + (nh / 2 - h / 2);

	warpAffine(img, dst, M, Size(nw,nh),INTER_LINEAR,0,Scalar(255,0,0));
	imshow("rotate", dst);

推荐一个零声学院项目课,个人觉得老师讲得不错,分享给大家:
零声白金学习卡(含基础架构/高性能存储/golang云原生/音视频/Linux内核)
https://xxetb.xet.tech/s/3Zqhgt

相关推荐

  1. OpenCV图像翻转旋转

    2024-03-26 05:36:13       18 阅读
  2. 【Python高级编程】使用OpenCV进行图像旋转详解

    2024-03-26 05:36:13       7 阅读

最近更新

  1. TCP协议是安全的吗?

    2024-03-26 05:36:13       14 阅读
  2. 阿里云服务器执行yum,一直下载docker-ce-stable失败

    2024-03-26 05:36:13       16 阅读
  3. 【Python教程】压缩PDF文件大小

    2024-03-26 05:36:13       15 阅读
  4. 通过文章id递归查询所有评论(xml)

    2024-03-26 05:36:13       18 阅读

热门阅读

  1. 使用OpenCV在Qt C++环境中实现车牌号码的识别

    2024-03-26 05:36:13       19 阅读
  2. GraphQL入门之自定义标量类型

    2024-03-26 05:36:13       16 阅读
  3. OpenCV多边形填充与绘制

    2024-03-26 05:36:13       19 阅读
  4. Ubuntu下采用VSCode进行C/C++开发(2)

    2024-03-26 05:36:13       19 阅读
  5. Node.js及node.js常用命令

    2024-03-26 05:36:13       19 阅读
  6. npm install jsencrypt爆错

    2024-03-26 05:36:13       16 阅读
  7. 神经网络深度学习梯度下降算法优化

    2024-03-26 05:36:13       22 阅读
  8. 云安全与云计算的关系

    2024-03-26 05:36:13       19 阅读