網(wǎng)站建設(shè)合同印花稅稅目外鏈收錄網(wǎng)站
圖像的縮放
resize(image, image, Size(round(image.cols * 0.5), round(image.rows * 0.5)));
?輸入圖像 輸出圖像 大小變換
canny邊緣算子的使用
cvtColor(image, gray, COLOR_BGR2GRAY);Canny(gray, canny_mat, 40, 100);
?必須先轉(zhuǎn)化為灰度圖,作為輸入 超過100是真的邊緣 低于40是確定不是邊緣 在中間若連接邊緣 則為邊緣?
普通旋轉(zhuǎn)縮放變換(仿射變換)
?獲取仿射變換矩陣
float angel = -10.0, scale = 1;Mat dstmat;Point2f center(image.cols * 0.5, image.rows * 0.5);Mat affine_matrix = getRotationMatrix2D(center, angel, scale);
獲取仿射變換的矩陣 中心點 旋轉(zhuǎn)角度 大小是否變換
-10是順時針轉(zhuǎn)
仿射變換函數(shù)
warpAffine(image, dstmat, affine_matrix,image.size());
輸入圖 輸出圖 仿射變換矩陣 畫布的大小?
這樣的仿射變換有旋轉(zhuǎn)的缺陷,因為大小和原圖一樣,但旋轉(zhuǎn)后,外接矩形肯定大于原圖,所以溢出的部分會看不到,后期會更新改進版
點到點的仿射變換(6變量?所以要3個點對3個點)
Mat affine_Mat;const cv::Point2f src_pt[] = {cv::Point2f(100,100),cv::Point2f(20,30),cv::Point2f(70,90),};const cv::Point2f warp_pt[] = {cv::Point2f(50,100),cv::Point2f(50,20),cv::Point2f(70,96),};Mat affine_matrix2 = cv::getAffineTransform(src_pt, warp_pt);warpAffine(image, affine_Mat, affine_matrix2,image.size());
一個點對應(yīng)一個點?
計算機會幫我們求出仿射變換的矩陣
點到點的透射變換(8變量?所以要4個點對4個點)
Mat perspective_Mat;cv::Point2f pts1[] = {cv::Point2f(150,150),cv::Point2f(150,300),cv::Point2f(350,300),cv::Point2f(350,150),};cv::Point2f pts2[] = {cv::Point2f(200,150),cv::Point2f(200,300),cv::Point2f(340,270),cv::Point2f(340,180),};Mat perspective_matrix = cv::getPerspectiveTransform(pts1, pts2);warpPerspective(image, perspective_Mat, perspective_matrix, image.size());
?總體代碼:
#include <opencv2/opencv.hpp>
#include<iostream>
using namespace std;
using namespace cv;int main() {Mat image = imread("lena.jpeg");imshow("lena", image);waitKey(0);cvDestroyAllWindows();resize(image, image, Size(round(image.cols * 0.5), round(image.rows * 0.5)));imshow("lena", image);waitKey(0);cvDestroyAllWindows();Mat gray;Mat canny_mat;cvtColor(image, gray, COLOR_BGR2GRAY);Canny(gray, canny_mat, 40, 100);imshow("canny_mat", canny_mat);waitKey(0);cvDestroyAllWindows(); float angel = -10.0, scale = 1;Mat dstmat;Point2f center(image.cols * 0.5, image.rows * 0.5);Mat affine_matrix = getRotationMatrix2D(center, angel, scale);warpAffine(image, dstmat, affine_matrix,image.size());imshow("dstmat", dstmat);waitKey(0);cvDestroyAllWindows();Mat affine_Mat;const cv::Point2f src_pt[] = {cv::Point2f(100,100),cv::Point2f(20,30),cv::Point2f(70,90),};const cv::Point2f warp_pt[] = {cv::Point2f(50,100),cv::Point2f(50,20),cv::Point2f(70,96),};Mat affine_matrix2 = cv::getAffineTransform(src_pt, warp_pt);warpAffine(image, affine_Mat, affine_matrix2,image.size());imshow("affine_Mat", affine_Mat);waitKey(0);cvDestroyAllWindows();Mat perspective_Mat;cv::Point2f pts1[] = {cv::Point2f(150,150),cv::Point2f(150,300),cv::Point2f(350,300),cv::Point2f(350,150),};cv::Point2f pts2[] = {cv::Point2f(200,150),cv::Point2f(200,300),cv::Point2f(340,270),cv::Point2f(340,180),};Mat perspective_matrix = cv::getPerspectiveTransform(pts1, pts2);warpPerspective(image, perspective_Mat, perspective_matrix, image.size());imshow("perspective_Mat", perspective_Mat);waitKey(0);cvDestroyAllWindows();//疑問 圖像的平移如何實現(xiàn) image.size()是什么個東西 如何改變圖像大小?return 0;
}