国产亚洲精品福利在线无卡一,国产精久久一区二区三区,亚洲精品无码国模,精品久久久久久无码专区不卡

當前位置: 首頁 > news >正文

github做網(wǎng)站空間地推掃碼平臺

github做網(wǎng)站空間,地推掃碼平臺,做網(wǎng)站建設價格,做養(yǎng)生網(wǎng)站需要什么資質(zhì)OpenCV圖片校正 背景幾種校正方法1.傅里葉變換 霍夫變換 直線 角度 旋轉(zhuǎn)3.四點透視 角度 旋轉(zhuǎn)4.檢測矩形輪廓 角度 旋轉(zhuǎn)參考 背景 遇到偏的圖片想要校正成水平或者垂直的。 幾種校正方法 對于傾斜的圖片通過矯正可以得到水平的圖片。一般有如下幾種基于opencv的組合方…

OpenCV圖片校正

  • 背景
  • 幾種校正方法
  • 1.傅里葉變換 + 霍夫變換+ 直線 + 角度 + 旋轉(zhuǎn)
  • 3.四點透視 + 角度 + 旋轉(zhuǎn)
  • 4.檢測矩形輪廓 + 角度 + 旋轉(zhuǎn)
  • 參考

背景

遇到偏的圖片想要校正成水平或者垂直的。

幾種校正方法

對于傾斜的圖片通過矯正可以得到水平的圖片。一般有如下幾種基于opencv的組合方式進行圖片矯正。

  • 1、傅里葉變換 + 霍夫變換+ 直線 + 角度 + 旋轉(zhuǎn)
  • 2、邊緣檢測 + 霍夫變換 + 直線+角度 + 旋轉(zhuǎn)
  • 3、四點透視 + 角度 + 旋轉(zhuǎn)
  • 4、檢測矩形輪廓 + 角度 + 旋轉(zhuǎn)

1.傅里葉變換 + 霍夫變換+ 直線 + 角度 + 旋轉(zhuǎn)

#include <opencv2/core/core.hpp>
#include <opencv2/imgproc/imgproc.hpp>
#include <opencv2/highgui/highgui.hpp>
#include <iostream>using namespace cv;
using namespace std;// 二值化閾值
#define GRAY_THRESH 150// 直線上點的個數(shù)
#define HOUGH_VOTE 50int main(int argc, char **argv)
{//Read a single-channel imageconst char* filename = "31.png";Mat srcImg = imread(filename, CV_LOAD_IMAGE_GRAYSCALE);if (srcImg.empty())return -1;imshow("source", srcImg);Point center(srcImg.cols / 2, srcImg.rows / 2);//Expand image to an optimal size, for faster processing speed//Set widths of borders in four directions//If borderType==BORDER_CONSTANT, fill the borders with (0,0,0)Mat padded;int opWidth = getOptimalDFTSize(srcImg.rows);int opHeight = getOptimalDFTSize(srcImg.cols);copyMakeBorder(srcImg, padded, 0, opWidth - srcImg.rows, 0, opHeight - srcImg.cols, BORDER_CONSTANT, Scalar::all(0));Mat planes[] = { Mat_<float>(padded), Mat::zeros(padded.size(), CV_32F) };Mat comImg;//Merge into a double-channel imagemerge(planes, 2, comImg);//Use the same image as input and output,//so that the results can fit in Mat welldft(comImg, comImg);//Compute the magnitude//planes[0]=Re(DFT(I)), planes[1]=Im(DFT(I))//magnitude=sqrt(Re^2+Im^2)split(comImg, planes);magnitude(planes[0], planes[1], planes[0]);//Switch to logarithmic scale, for better visual results//M2=log(1+M1)Mat magMat = planes[0];magMat += Scalar::all(1);log(magMat, magMat);//Crop the spectrum//Width and height of magMat should be even, so that they can be divided by 2//-2 is 11111110 in binary system, operator & make sure width and height are always evenmagMat = magMat(Rect(0, 0, magMat.cols & -2, magMat.rows & -2));//Rearrange the quadrants of Fourier image,//so that the origin is at the center of image,//and move the high frequency to the cornersint cx = magMat.cols / 2;int cy = magMat.rows / 2;Mat q0(magMat, Rect(0, 0, cx, cy));Mat q1(magMat, Rect(0, cy, cx, cy));Mat q2(magMat, Rect(cx, cy, cx, cy));Mat q3(magMat, Rect(cx, 0, cx, cy));Mat tmp;q0.copyTo(tmp);q2.copyTo(q0);tmp.copyTo(q2);q1.copyTo(tmp);q3.copyTo(q1);tmp.copyTo(q3);//Normalize the magnitude to [0,1], then to[0,255]normalize(magMat, magMat, 0, 1, CV_MINMAX);Mat magImg(magMat.size(), CV_8UC1);magMat.convertTo(magImg, CV_8UC1, 255, 0);imshow("magnitude", magImg);//imwrite("imageText_mag.jpg",magImg);//Turn into binary imagethreshold(magImg, magImg, GRAY_THRESH, 255, CV_THRESH_BINARY);imshow("mag_binary", magImg);//imwrite("imageText_bin.jpg",magImg);//Find lines with Hough Transformationvector<Vec2f> lines;float pi180 = (float)CV_PI / 180;Mat linImg(magImg.size(), CV_8UC3);HoughLines(magImg, lines, 1, pi180, HOUGH_VOTE, 0, 0);int numLines = lines.size();for (int l = 0; l<numLines; l++){float rho = lines[l][0], theta = lines[l][1];Point pt1, pt2;double a = cos(theta), b = sin(theta);double x0 = a*rho, y0 = b*rho;pt1.x = cvRound(x0 + 1000 * (-b));pt1.y = cvRound(y0 + 1000 * (a));pt2.x = cvRound(x0 - 1000 * (-b));pt2.y = cvRound(y0 - 1000 * (a));line(linImg, pt1, pt2, Scalar(255, 0, 0), 3, 8, 0);}imshow("lines", linImg);//imwrite("imageText_line.jpg",linImg);if (lines.size() == 3){cout << "found three angels:" << endl;cout << lines[0][1] * 180 / CV_PI << endl << lines[1][1] * 180 / CV_PI << endl << lines[2][1] * 180 / CV_PI << endl << endl;}//Find the proper angel from the three found angelsfloat angel = 0;float piThresh = (float)CV_PI / 90;float pi2 = CV_PI / 2;for (int l = 0; l<numLines; l++){float theta = lines[l][1];if (abs(theta) < piThresh || abs(theta - pi2) < piThresh)continue;else{angel = theta;break;}}//Calculate the rotation angel//The image has to be square,//so that the rotation angel can be calculate rightangel = angel<pi2 ? angel : angel - CV_PI;if (angel != pi2){float angelT = srcImg.rows*tan(angel) / srcImg.cols;angel = atan(angelT);}float angelD = angel * 180 / (float)CV_PI;cout << "the rotation angel to be applied:" << endl << angelD << endl << endl;//Rotate the image to recoverMat rotMat = getRotationMatrix2D(center, angelD, 1.0);Mat dstImg = Mat::ones(srcImg.size(), CV_8UC3);warpAffine(srcImg, dstImg, rotMat, srcImg.size(), 1, 0, Scalar(255, 255, 255));imshow("result", dstImg);//imwrite("imageText_D.jpg",dstImg);waitKey(0);return 0;
}

opencv4x

#include <opencv2/core/core.hpp>
#include <opencv2/imgproc/imgproc.hpp>
#include <opencv2/highgui/highgui.hpp>
#include <opencv2/imgcodecs/legacy/constants_c.h> 
#include <iostream>using namespace cv;
using namespace std;// 二值化閾值
#define GRAY_THRESH 150// 直線上點的個數(shù)
#define HOUGH_VOTE 50int main(int argc, char **argv)
{//Read a single-channel imageconst char* filename = argv[1];Mat srcImg = imread(filename, CV_LOAD_IMAGE_GRAYSCALE);if (srcImg.empty())return -1;imshow("source", srcImg);Point center(srcImg.cols / 2, srcImg.rows / 2);//Expand image to an optimal size, for faster processing speed//Set widths of borders in four directions//If borderType==BORDER_CONSTANT, fill the borders with (0,0,0)Mat padded;int opWidth = getOptimalDFTSize(srcImg.rows);int opHeight = getOptimalDFTSize(srcImg.cols);copyMakeBorder(srcImg, padded, 0, opWidth - srcImg.rows, 0, opHeight - srcImg.cols, BORDER_CONSTANT, Scalar::all(0));Mat planes[] = { Mat_<float>(padded), Mat::zeros(padded.size(), CV_32F) };Mat comImg;//Merge into a double-channel imagemerge(planes, 2, comImg);//Use the same image as input and output,//so that the results can fit in Mat welldft(comImg, comImg);//Compute the magnitude//planes[0]=Re(DFT(I)), planes[1]=Im(DFT(I))//magnitude=sqrt(Re^2+Im^2)split(comImg, planes);magnitude(planes[0], planes[1], planes[0]);//Switch to logarithmic scale, for better visual results//M2=log(1+M1)Mat magMat = planes[0];magMat += Scalar::all(1);log(magMat, magMat);//Crop the spectrum//Width and height of magMat should be even, so that they can be divided by 2//-2 is 11111110 in binary system, operator & make sure width and height are always evenmagMat = magMat(Rect(0, 0, magMat.cols & -2, magMat.rows & -2));//Rearrange the quadrants of Fourier image,//so that the origin is at the center of image,//and move the high frequency to the cornersint cx = magMat.cols / 2;int cy = magMat.rows / 2;Mat q0(magMat, Rect(0, 0, cx, cy));Mat q1(magMat, Rect(0, cy, cx, cy));Mat q2(magMat, Rect(cx, cy, cx, cy));Mat q3(magMat, Rect(cx, 0, cx, cy));Mat tmp;q0.copyTo(tmp);q2.copyTo(q0);tmp.copyTo(q2);q1.copyTo(tmp);q3.copyTo(q1);tmp.copyTo(q3);//Normalize the magnitude to [0,1], then to[0,255]//normalize(magMat, magMat, 0, 1, CV_MINMAX);normalize(magMat, magMat, 0, 1, NORM_MINMAX);Mat magImg(magMat.size(), CV_8UC1);magMat.convertTo(magImg, CV_8UC1, 255, 0);imshow("magnitude", magImg);//imwrite("imageText_mag.jpg",magImg);//Turn into binary imagethreshold(magImg, magImg, GRAY_THRESH, 255, cv::THRESH_BINARY);imshow("mag_binary", magImg);//imwrite("imageText_bin.jpg",magImg);//Find lines with Hough Transformationvector<Vec2f> lines;float pi180 = (float)CV_PI / 180;Mat linImg(magImg.size(), CV_8UC3);HoughLines(magImg, lines, 1, pi180, HOUGH_VOTE, 0, 0);int numLines = lines.size();for (int l = 0; l<numLines; l++){float rho = lines[l][0], theta = lines[l][1];Point pt1, pt2;double a = cos(theta), b = sin(theta);double x0 = a*rho, y0 = b*rho;pt1.x = cvRound(x0 + 1000 * (-b));pt1.y = cvRound(y0 + 1000 * (a));pt2.x = cvRound(x0 - 1000 * (-b));pt2.y = cvRound(y0 - 1000 * (a));line(linImg, pt1, pt2, Scalar(255, 0, 0), 3, 8, 0);}imshow("lines", linImg);//imwrite("imageText_line.jpg",linImg);if (lines.size() == 3){cout << "found three angels:" << endl;cout << lines[0][1] * 180 / CV_PI << endl << lines[1][1] * 180 / CV_PI << endl << lines[2][1] * 180 / CV_PI << endl << endl;}//Find the proper angel from the three found angelsfloat angel = 0;float piThresh = (float)CV_PI / 90;float pi2 = CV_PI / 2;for (int l = 0; l<numLines; l++){float theta = lines[l][1];if (abs(theta) < piThresh || abs(theta - pi2) < piThresh)continue;else{angel = theta;break;}}//Calculate the rotation angel//The image has to be square,//so that the rotation angel can be calculate rightangel = angel<pi2 ? angel : angel - CV_PI;if (angel != pi2){float angelT = srcImg.rows*tan(angel) / srcImg.cols;angel = atan(angelT);}//float angelD = angel * 180 / (float)CV_PI;float angelD = angel * 180 / (float)CV_PI;cout << "the rotation angel to be applied: "<< angelD << endl << endl;//Rotate the image to recoverMat rotMat = getRotationMatrix2D(center, angelD, 1.0);Mat dstImg = Mat::ones(srcImg.size(), CV_8UC3);warpAffine(srcImg, dstImg, rotMat, srcImg.size(), 1, 0, Scalar(255, 255, 255));imshow("result", dstImg);imwrite("imageText_D.jpg",dstImg);waitKey(0);return 0;
}

CMakeLists.txt

project( main )
cmake_minimum_required(VERSION 3.10) 
#添加頭文件路徑
include_directories(/usr/local/include /usr/local/include/opencv4 /usr/local/include/opencv4/opencv2)
#添加庫文件路徑
link_directories(/usr/local/lib)add_executable(main test.cpp)
target_link_libraries( main -lopencv_core  -lopencv_highgui -lopencv_imgproc -lopencv_imgcodecs)

在這里插入圖片描述
在這里插入圖片描述

3.四點透視 + 角度 + 旋轉(zhuǎn)

#include "opencv2/imgproc.hpp"
#include "opencv2/highgui.hpp"
#include <iostream>
using namespace cv;
using namespace std;// 直線上點的個數(shù)
#define HOUGH_VOTE 50//度數(shù)轉(zhuǎn)換
double DegreeTrans(double theta)
{double res = theta / CV_PI * 180;return res;
}//逆時針旋轉(zhuǎn)圖像degree角度(原尺寸)    
void rotateImage(Mat src, Mat& img_rotate, double degree)
{//旋轉(zhuǎn)中心為圖像中心    Point2f center;center.x = float(src.cols / 2.0);center.y = float(src.rows / 2.0);int length = 0;length = sqrt(src.cols*src.cols + src.rows*src.rows);//計算二維旋轉(zhuǎn)的仿射變換矩陣  Mat M = getRotationMatrix2D(center, degree, 1);warpAffine(src, img_rotate, M, Size(length, length), 1, 0, Scalar(255, 255, 255));//仿射變換,背景色填充為白色  
}//通過霍夫變換計算角度
double CalcDegree(const Mat &srcImage, Mat &dst)
{Mat midImage, dstImage;Canny(srcImage, midImage, 50, 200, 3);cvtColor(midImage, dstImage, CV_GRAY2BGR);//通過霍夫變換檢測直線vector<Vec2f> lines;HoughLines(midImage, lines, 1, CV_PI / 180, HOUGH_VOTE);//第5個參數(shù)就是閾值,閾值越大,檢測精度越高//cout << lines.size() << endl;//由于圖像不同,閾值不好設定,因為閾值設定過高導致無法檢測直線,閾值過低直線太多,速度很慢//所以根據(jù)閾值由大到小設置了三個閾值,如果經(jīng)過大量試驗后,可以固定一個適合的閾值。float sum = 0;//依次畫出每條線段for (size_t i = 0; i < lines.size(); i++){float rho = lines[i][0];float theta = lines[i][1];Point pt1, pt2;//cout << theta << endl;double a = cos(theta), b = sin(theta);double x0 = a*rho, y0 = b*rho;pt1.x = cvRound(x0 + 1000 * (-b));pt1.y = cvRound(y0 + 1000 * (a));pt2.x = cvRound(x0 - 1000 * (-b));pt2.y = cvRound(y0 - 1000 * (a));//只選角度最小的作為旋轉(zhuǎn)角度sum += theta;line(dstImage, pt1, pt2, Scalar(55, 100, 195), 1, LINE_AA); //Scalar函數(shù)用于調(diào)節(jié)線段顏色imshow("直線探測效果圖", dstImage);}float average = sum / lines.size(); //對所有角度求平均,這樣做旋轉(zhuǎn)效果會更好cout << "average theta:" << average << endl;double angle = DegreeTrans(average) - 90;rotateImage(dstImage, dst, angle);//imshow("直線探測效果圖2", dstImage);return angle;
}void ImageRecify(const char* pInFileName, const char* pOutFileName)
{double degree;Mat src = imread(pInFileName);imshow("原始圖", src);Mat dst;//傾斜角度矯正degree = CalcDegree(src, dst);rotateImage(src, dst, degree);cout << "angle:" << degree << endl;imshow("旋轉(zhuǎn)調(diào)整后", dst);Mat resulyImage = dst(Rect(0, 0, dst.cols, 500)); //根據(jù)先驗知識,估計好文本的長寬,再裁剪下來imshow("裁剪之后", resulyImage);imwrite("recified.jpg", resulyImage);
}int main()
{ImageRecify("31.png", "FinalImage.jpg");waitKey();return 0;
}

opencv4.x

#include "opencv2/imgproc.hpp"
#include "opencv2/highgui.hpp"
#include <iostream>
using namespace cv;
using namespace std;// 直線上點的個數(shù)
#define HOUGH_VOTE 50//度數(shù)轉(zhuǎn)換
double DegreeTrans(double theta)
{double res = theta / CV_PI * 180;return res;
}//逆時針旋轉(zhuǎn)圖像degree角度(原尺寸)    
void rotateImage(Mat src, Mat& img_rotate, double degree)
{//旋轉(zhuǎn)中心為圖像中心    Point2f center;center.x = float(src.cols / 2.0);center.y = float(src.rows / 2.0);int length = 0;length = sqrt(src.cols*src.cols + src.rows*src.rows);//計算二維旋轉(zhuǎn)的仿射變換矩陣  Mat M = getRotationMatrix2D(center, degree, 1);warpAffine(src, img_rotate, M, Size(length, length), 1, 0, Scalar(255, 255, 255));//仿射變換,背景色填充為白色  
}//通過霍夫變換計算角度
double CalcDegree(const Mat &srcImage, Mat &dst)
{Mat midImage, dstImage;Canny(srcImage, midImage, 50, 200, 3);cvtColor(midImage, dstImage, COLOR_GRAY2BGR);//通過霍夫變換檢測直線vector<Vec2f> lines;HoughLines(midImage, lines, 1, CV_PI / 180, HOUGH_VOTE);//第5個參數(shù)就是閾值,閾值越大,檢測精度越高//cout << lines.size() << endl;//由于圖像不同,閾值不好設定,因為閾值設定過高導致無法檢測直線,閾值過低直線太多,速度很慢//所以根據(jù)閾值由大到小設置了三個閾值,如果經(jīng)過大量試驗后,可以固定一個適合的閾值。float sum = 0;//依次畫出每條線段for (size_t i = 0; i < lines.size(); i++){float rho = lines[i][0];float theta = lines[i][1];Point pt1, pt2;//cout << theta << endl;double a = cos(theta), b = sin(theta);double x0 = a*rho, y0 = b*rho;pt1.x = cvRound(x0 + 1000 * (-b));pt1.y = cvRound(y0 + 1000 * (a));pt2.x = cvRound(x0 - 1000 * (-b));pt2.y = cvRound(y0 - 1000 * (a));//只選角度最小的作為旋轉(zhuǎn)角度sum += theta;line(dstImage, pt1, pt2, Scalar(55, 100, 195), 1, LINE_AA); //Scalar函數(shù)用于調(diào)節(jié)線段顏色imshow("直線探測效果圖", dstImage);}float average = sum / lines.size(); //對所有角度求平均,這樣做旋轉(zhuǎn)效果會更好cout << "average theta:" << average << endl;double angle = DegreeTrans(average) - 90;rotateImage(dstImage, dst, angle);//imshow("直線探測效果圖2", dstImage);return angle;
}void ImageRecify(const char* pInFileName, const char* pOutFileName)
{double degree;Mat src = imread(pInFileName);imshow("原始圖", src);Mat dst;//傾斜角度矯正degree = CalcDegree(src, dst);rotateImage(src, dst, degree);cout << "angle:" << degree << endl;imshow("旋轉(zhuǎn)調(diào)整后", dst);Mat resulyImage = dst(Rect(0, 0, dst.cols, 1000)); //根據(jù)先驗知識,估計好文本的長寬,再裁剪下來imshow("裁剪之后", resulyImage);imwrite("recified.jpg", resulyImage);
}int main()
{ImageRecify("test.jpg", "FinalImage.jpg");waitKey();return 0;
}

4.檢測矩形輪廓 + 角度 + 旋轉(zhuǎn)

#include "opencv2/imgproc.hpp"
#include "opencv2/highgui.hpp"
#include <iostream>
using namespace cv;
using namespace std;
#include <algorithm>bool x_sort(const Point2f & m1, const Point2f & m2)
{return m1.x < m2.x;
}//第一個參數(shù):輸入圖片名稱;第二個參數(shù):輸出圖片名稱
void GetContoursPic(const char* pSrcFileName, const char* pDstFileName)
{Mat srcImg = imread(pSrcFileName);imshow("原始圖", srcImg);Mat gray, binImg;//灰度化cvtColor(srcImg, gray, COLOR_RGB2GRAY);imshow("灰度圖", gray);//二值化threshold(gray, binImg, 150, 200, CV_THRESH_BINARY);imshow("二值化", binImg);vector<Point>  contours;vector<vector<Point> > f_contours;//注意第5個參數(shù)為CV_RETR_EXTERNAL,只檢索外框  findContours(binImg, f_contours, CV_RETR_EXTERNAL, CV_CHAIN_APPROX_NONE); //找輪廓int max_area = 0;int index;for (int i = 0; i < f_contours.size(); i++){double tmparea = fabs(contourArea(f_contours[i]));if (tmparea > max_area){index = i;max_area = tmparea;}}contours = f_contours[index];CvBox2D rect = minAreaRect(Mat(contours));float angle = rect.angle;cout << "before angle : " << angle << endl;if (angle < -45)angle = (90 + angle);elseangle = -angle;cout << "after angle : " << angle << endl;//新建一個感興趣的區(qū)域圖,大小跟原圖一樣大  Mat RoiSrcImg(srcImg.rows, srcImg.cols, CV_8UC3); //注意這里必須選CV_8UC3RoiSrcImg.setTo(0); //顏色都設置為黑色  //imshow("新建的ROI", RoiSrcImg);//對得到的輪廓填充一下  drawContours(binImg, f_contours, 0, Scalar(255), CV_FILLED);//摳圖到RoiSrcImgsrcImg.copyTo(RoiSrcImg, gray);//再顯示一下看看,除了感興趣的區(qū)域,其他部分都是黑色的了  namedWindow("RoiSrcImg", 1);imshow("RoiSrcImg", RoiSrcImg);//創(chuàng)建一個旋轉(zhuǎn)后的圖像  Mat RatationedImg(RoiSrcImg.rows, RoiSrcImg.cols, CV_8UC1);RatationedImg.setTo(0);//對RoiSrcImg進行旋轉(zhuǎn)  Point2f center = rect.center;  //中心點  Mat M2 = getRotationMatrix2D(center, angle, 1);//計算旋轉(zhuǎn)加縮放的變換矩陣 warpAffine(RoiSrcImg, RatationedImg, M2, RoiSrcImg.size(), 1, 0, Scalar(0));//仿射變換 imshow("旋轉(zhuǎn)之后", RatationedImg);
}void main()
{GetContoursPic("34.png", "FinalImage.jpg");waitKey();
}

opencv4.x

#include "opencv2/imgproc.hpp"
#include "opencv2/highgui.hpp"
#include <opencv2/imgproc/types_c.h>
#include <opencv2/imgproc/imgproc.hpp>
#include <opencv2/highgui/highgui.hpp>
#include <iostream>using namespace cv;
using namespace std;
#include <algorithm>bool x_sort(const Point2f & m1, const Point2f & m2)
{return m1.x < m2.x;
}//第一個參數(shù):輸入圖片名稱;第二個參數(shù):輸出圖片名稱
void GetContoursPic(const char* pSrcFileName, const char* pDstFileName)
{Mat srcImg = imread(pSrcFileName);imshow("原始圖", srcImg);Mat gray, binImg;//灰度化cvtColor(srcImg, gray, COLOR_RGB2GRAY);imshow("灰度圖", gray);//二值化threshold(gray, binImg, 150, 200, cv::THRESH_BINARY);imshow("二值化", binImg);vector<Point>  contours;vector<vector<Point> > f_contours;//注意第5個參數(shù)為CV_RETR_EXTERNAL,只檢索外框  findContours(binImg, f_contours, CV_RETR_EXTERNAL, CV_CHAIN_APPROX_NONE); //找輪廓int max_area = 0;int index;for (int i = 0; i < f_contours.size(); i++){double tmparea = fabs(contourArea(f_contours[i]));if (tmparea > max_area){index = i;max_area = tmparea;}}contours = f_contours[index];RotatedRect rect = minAreaRect(Mat(contours));float angle = rect.angle;cout << "before angle : " << angle << endl;if (angle < -45)angle = (90 + angle);elseangle = -angle;cout << "after angle : " << angle << endl;//新建一個感興趣的區(qū)域圖,大小跟原圖一樣大  Mat RoiSrcImg(srcImg.rows, srcImg.cols, CV_8UC3); //注意這里必須選CV_8UC3RoiSrcImg.setTo(0); //顏色都設置為黑色  //imshow("新建的ROI", RoiSrcImg);//對得到的輪廓填充一下  drawContours(binImg, f_contours, 0, Scalar(255), cv::FILLED);//摳圖到RoiSrcImgsrcImg.copyTo(RoiSrcImg, gray);//再顯示一下看看,除了感興趣的區(qū)域,其他部分都是黑色的了  namedWindow("RoiSrcImg", 1);imshow("RoiSrcImg", RoiSrcImg);//創(chuàng)建一個旋轉(zhuǎn)后的圖像  Mat RatationedImg(RoiSrcImg.rows, RoiSrcImg.cols, CV_8UC1);RatationedImg.setTo(0);//對RoiSrcImg進行旋轉(zhuǎn)  Point2f center = rect.center;  //中心點  Mat M2 = getRotationMatrix2D(center, angle, 1);//計算旋轉(zhuǎn)加縮放的變換矩陣 warpAffine(RoiSrcImg, RatationedImg, M2, RoiSrcImg.size(), 1, 0, Scalar(0));//仿射變換 imshow("旋轉(zhuǎn)之后", RatationedImg);imwrite("recified.jpg", RatationedImg);
}int main()
{GetContoursPic("test.jpg", "FinalImage.jpg");waitKey();return 0;
}

參考

  • 榴蓮小怪獸 opencv-圖片矯正
  • OpenCV利用透視變換矯正圖像
http://m.aloenet.com.cn/news/44002.html

相關(guān)文章:

  • wordpress 焦點圖seo搜索引擎優(yōu)化課程
  • 優(yōu)秀網(wǎng)站設計書籍微信公眾號平臺官網(wǎng)
  • 返利網(wǎng)網(wǎng)站怎么做北京seo推廣服務
  • 深圳龍華大浪做網(wǎng)站公司知乎營銷平臺
  • 做搜狗手機網(wǎng)站快速排十大中文網(wǎng)站排名
  • 做網(wǎng)站首頁需要什么資料推廣app用什么平臺比較好
  • 太原自助建站軟件快速排名教程
  • 石家莊做網(wǎng)站的公司有哪些足球世界排名一覽表
  • 網(wǎng)站開發(fā)3687474企鵝網(wǎng)絡營銷的種類
  • 做網(wǎng)站哪個公司可以做seo收錄排名
  • 網(wǎng)站做裂變引流周口網(wǎng)絡推廣公司
  • 制作公司網(wǎng)站在公賬匯款時用途備注什么北京seo工程師
  • 網(wǎng)站建設基本內(nèi)容百度一下你就知道了
  • 大連百度代理seo推廣優(yōu)化多少錢
  • 個人做網(wǎng)站的必要性軟文推廣代理平臺
  • 哪個網(wǎng)站做服裝批發(fā)比較好網(wǎng)絡口碑營銷案例
  • wordpress過濾用戶輸入數(shù)據(jù)seo管理系統(tǒng)培訓
  • 古交做網(wǎng)站今天熱搜榜前十名
  • 美國網(wǎng)站建設公司百度官方營銷推廣平臺加載中
  • 網(wǎng)站如何做前后端分離百度接單平臺
  • 阿里云服務器搭網(wǎng)站同時做網(wǎng)盤網(wǎng)絡服務器多少錢一臺
  • 公司網(wǎng)頁設計圖青島seo排名公司
  • 做阿里巴巴網(wǎng)站應怎樣定位怎么找推廣渠道
  • 北京做網(wǎng)站制作的公司哪家好網(wǎng)上營銷
  • 靜態(tài)網(wǎng)站怎么做滾動文字國外最好的免費建站
  • 網(wǎng)站是生成靜態(tài)好還是動態(tài)好青檸影院免費觀看電視劇高清
  • 鄭州建站的站長收錄平臺
  • app對接網(wǎng)站登錄要怎么做優(yōu)化營商環(huán)境心得體會2023
  • 拔別人的網(wǎng)站做網(wǎng)站合法嗎百度搜索引擎關(guān)鍵詞
  • 徐州網(wǎng)站開發(fā)培訓網(wǎng)站關(guān)鍵詞上首頁