11. opencv图像处理编程实践
#include <opencv2/core/core.hpp>#include <opencv2/highgui/highgui.hpp>#include <opencv2/imgproc/imgproc.hpp>#include <iostream>using namespace cv;using namespace st...
#include <opencv2/core/core.hpp>
#include <opencv2/highgui/highgui.hpp>
#include <opencv2/imgproc/imgproc.hpp>
#include <iostream>
using namespace cv;
using namespace std;
int main(int argc, char **argv)
{
Mat srcImage;
srcImage = imread("../1.jpg");
if(!srcImage.data)
{
cout<<"error";
return 0;
}
// 输出矩阵定义
Mat resultImage(srcImage.size(), srcImage.type());
// x与y方向矩阵
Mat xMapImage(srcImage.size(), CV_32FC1); // 960*600
Mat yMapImage(srcImage.size(), CV_32FC1); // 960*600
cout << yMapImage.cols << endl;
int rows = srcImage.rows;
int cols = srcImage.cols;
// 图像遍历
for(int j = 0; j < rows; j++)
{
for(int i = 0; i < cols; i++)
{
// x与y均翻转
xMapImage.at<float>(j, i) = cols - i;
yMapImage.at<float>(j, i) = rows - j;
}
}
// 重映射操作
remap(srcImage, resultImage, xMapImage, yMapImage, INTER_LINEAR, BORDER_CONSTANT, Scalar(0, 0, 0));
imshow("srcImage",srcImage);
imshow("resultImage", resultImage);
waitKey(0);
return 0;
}
更多推荐
所有评论(0)