程序环境:windows10系统
opencv3
vs 2013
步骤:1.手动选点
(分析:由于图像是黑色和绿色的,用红色打点做标记。为了算得矫正的标准尺寸,通过原
坐标点横纵坐标算取平均值)
2.利用RGB色域转换为HAV色域得到只有坐标点的图像
其目的是为了算取变换后的标准大小(其值等于横纵点间隔的平均值)1 #include "stdafx.h"
2 #include <stdio.h>
3 //include cv
4 #include "opencv2/highgui/highgui.hpp"
5 #include <opencv2>
6 #include "opencv2/imgproc/imgproc.hpp"
7 #include "opencv2\\features2d\\features2d.hpp"
8 #include "opencv2/calib3d/calib3d.hpp"
9 using namespace cv;
10 using namespace std;
11 #define WINDOW_NAME1 "【原始图窗口】" //为窗口标题定义的宏
12 #define WINDOW_NAME2 "【效果图窗口】" //为窗口标题定义的宏
13 #define WINDOW_NAME3 "【原始变形窗口】" //为窗口标题定义的宏
14 #define WINDOW_NAME4 "【效果变形后图窗口】" //为窗口标题定义的宏
15 #define WINDOW_NAME5 "【截图】" //为窗口标题定义的宏
16 void yuzhi();
17 static int iLowH = 0;
18 static int iHighH = 0;
19
20 static int iLowS = 0;
21 static int iHighS = 0;
22
23 static int iLowV = 0;
24 static int iHighV = 0;
25 int main(){
26
27 cv::namedWindow("Control", WINDOW_NORMAL); //create a window called"Control"
28 cv::createTrackbar("LowH", "Control", &iLowH, 359);
29 cv::createTrackbar("HighH", "Control", &iHighH, 259);
30
31 cv::createTrackbar("LowS", "Control", &iLowS, 255); //Saturation (0 ‐255)
32 cv::createTrackbar("HighS", "Control", &iHighS, 255);
33
34 cv::createTrackbar("LowV", "Control", &iLowV, 255); //Value (0 ‐ 255)
35 cv::createTrackbar("HighV", "Control", &iHighV, 255);//创建3个bar存三个值
36 double scale = 0.5;
37 //cvsize sz;
38 // Cam >> frame;
39 //sz.width = frame.width *0.5;
40 Mat gray,frame;
41 Mat HSVpic;
42 Mat imgThresholded;
43
44 std::vector
45 std::vector
46 frame = imread("biaoji2.jpg", 1);
47 imshow("Control", frame);
48 cv::cvtColor(frame, gray, COLOR_BGR2GRAY);
49 cvtColor(frame, HSVpic, COLOR_BGR2HSV);
50
51 split(HSVpic, hsvchannel);
52 //equalizeHist(hsvchannel[2], hsvchannel[2]);
53 merge(hsvchannel, HSVpic);
54
55 //inRange(HSVpic, Scalar(iLowH, iLowS, iLowV), Scalar(iHighH, iHighS,iHighV), imgThresholded); //Threshold the image
56 inRange(HSVpic, Scalar(0, 100, 100), Scalar(40, 250, 250), imgThresholded);//1575168255
57 //‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐//
58 int zhongx = 0;
59 int zhongy = 0;
60 Mat image1 = imgThresholded;
61
62 imshow("hsv", imgThresholded);
63 //sprintf(filename2, "D://pos2//(%d).jpg", i);
64 cv::imwrite("chulihou.jpg", imgThresholded);
65 //on_ContoursChange(0, 0);//回调函数
66
67 waitKey(0);
68 return 0;
69 }
70
閱讀更多 程序分享聯盟 的文章