如何用OpenCV将图像分成四个象限,并将象限1和象限4旋转180度
How to divide an image in four quadrants and rotate 180 degrees the quadrant 1 and 4 with OpenCV?
所以,当我必须拍摄图像时,我有这个活动,将其分为四个象限,然后在同一图像中旋转象限1和4,而不创建另一个窗口。我已经有了这段代码,但我只需要在不同的窗口中进行旋转,这是我的主要问题。如果这有帮助,我在Visual Studio中使用CLR项目编写代码。谢谢你。
#include "stdafx.h"
#include <iostream>
#include <opencvcv.h>
#include <opencvcxcore.h>
#include <opencvhighgui.h>
#include <cmath>
using namespace System;
using namespace std;
using namespace cv;
int main( int argc, char** argv ){
CvPoint pt1, pt2;
int width;
int height;
IplImage* img = cvLoadImage("C:/Users/Munii/Documents/Visual Studio 2010/Projects/Proyecto/Proyecto/Imagen.jpg");
pt1.x=0;
pt1.y=0;
pt2.x = (img->width)/2;
pt2.y = (img->height)/2;
width = img->width;
height = img->height;
IplImage* rotated=cvCreateImage(cvGetSize(img),IPL_DEPTH_8U,img->nChannels);
CvPoint2D32f center;
float angle=180;
CvMat* M = cvCreateMat(2,3,CV_32FC1);
center.x = (img->width)/2.0;
center.y = (img->height)/2.0;
cv2DRotationMatrix(center,angle,1.0,M);
cvWarpAffine(img,rotated,M,CV_INTER_LINEAR+CV_WARP_FILL_OUTLIERS, cvScalarAll(0));
cvSetImageROI(rotated, cvRect( pt1.x, pt1.y, pt2.x, pt2.y));
pt1.x = (img->width)/2;
pt1.y = (img->height)/2;
pt2.x = img->width;
pt2.y = img->height;
IplImage* rot=cvCreateImage(cvGetSize(img),IPL_DEPTH_8U,img->nChannels);
center.x=img->width/2.0;
center.y=img->height/2.0;
cv2DRotationMatrix(center,angle,1.0,M);
cvWarpAffine(img,rot,M,CV_INTER_LINEAR+CV_WARP_FILL_OUTLIERS, cvScalarAll(0));
cvSetImageROI(rot, cvRect( pt1.x, pt1.y, pt1.x, pt2.y));
cvNamedWindow("Ejemplo 3", CV_WINDOW_AUTOSIZE); //creamos una ventana con el nombre Ejemplo 3
cvNamedWindow("ROI", CV_WINDOW_AUTOSIZE);
cvNamedWindow("RO", CV_WINDOW_AUTOSIZE); //creamos una ventana con el nombre ROI donde estará la región de interes
cvShowImage("Ejemplo 3", img);
cvShowImage("ROI",rotated);
cvShowImage("RO",rot); //mostramos la imagen en la ventana anteriormente creada
cvSaveImage("C:/Users/Munii/Documents/Visual Studio 2010/Projects/Proyecto/Proyecto/RotacionI.jpg", rotated);
cvSaveImage("C:/Users/Munii/Documents/Visual Studio 2010/Projects/Proyecto/Proyecto/RotacionIV.jpg", rot);
cvWaitKey(0);
cvDestroyWindow("ROI" );
cvDestroyWindow("RO" );
cvReleaseImage( &img );
cvDestroyWindow("Ejemplo3" );
cvReleaseImage(&rotated);
cvReleaseMat(&M);
}
所以,谢谢你帮助我。我已经可以解决这个问题,一个朋友告诉我,越factible得到我想要的结果是把图像分成四个象限使用矩形函数,然后创建函数旋转象限我要和getRotationMatrix2D()和warpAffine()和最后我使用函数hconcat()和vconcat()加入四个图片我从原始图像到之前创建一个新窗口并显示合成图像。
下面是c++代码,不多不少:
const int rot180 {-1};
cv::Mat img = cv::imread("path/to/your/image");
cv::imshow("Original", img);
cv::Mat upLeft = img({0, img.rows/2}, {0, img.cols/2});
cv::flip(upLeft, upLeft, rot180);
cv::Mat downRight = img({img.rows/2, img.rows}, {img.cols/2, img.cols});
cv::flip(downRight, downRight, rot180);
cv::imshow("Rotated", img);
cv::imwrite("path/to/your/new/image", img);
cv::waitKey();
cv::destroyAllWindows();
upLeft
和downRight
都是直接作用于img
的roi。
请随意在:
cv::Mat src = img.clone();
相关文章:
- 在C++中使用OpenCV矩阵中的特征将图像旋转90度
- 顺时针旋转 M*N 矩阵 90 度,C++
- 从iPhone相机拍摄的视频似乎被OpenCV旋转了90度?我该如何解决这个问题?
- 顺时针旋转90度图像
- 将矩阵逆时针旋转 180 度的问题
- C++向量的向量.阵列旋转 90 度
- 如何使用四元数来描述超过360度的旋转角度?
- 在C 中旋转矩阵(2D阵列)45度
- 在C 中旋转像素阵列90度
- 将轴对齐的矩形旋转90度
- 如何使OpenGL相机旋转360度
- 在 iOS 中将 Spirte 矩形旋转 90 度不会显示纵横比
- OpenCV从T形主体获得360度旋转
- 将2D转换的1D阵列顺时针旋转90度
- 对象不沿其面向的方向移动,除非旋转为 0 度或 180 度
- 如何用OpenCV将图像分成四个象限,并将象限1和象限4旋转180度
- OpenGl -对象在旋转180度后反转
- 将Opencv矩阵旋转90、180、270度
- 从帧缓冲区创建的JPEG被旋转180度
- 在c++中以任意给定度旋转像素数组(例如45度)