-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy patha1_part1.cpp
More file actions
57 lines (47 loc) · 1.19 KB
/
Copy patha1_part1.cpp
File metadata and controls
57 lines (47 loc) · 1.19 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
#include <stdio.h>
#include <iostream>
#include <opencv2/opencv.hpp>
#include <bits/stdc++.h>
#include <vector>
using namespace cv;
using namespace std;
vector<Point2f> pts_src(4);
int i = 0;
void click_event(int event, int x, int y, int flag, void *param)
{
if(event == EVENT_LBUTTONDOWN || event == EVENT_RBUTTONDOWN || event == EVENT_MBUTTONDOWN)
{
pts_src[i] = Point2f(x,y);
i++;
}
return;
}
int main(){
string InputImage;
cin >> InputImage;
Mat I = imread(InputImage, IMREAD_GRAYSCALE);
imshow("InputImage", I);
for(int j = 0; j< 4; j++){
setMouseCallback("InputImage", click_event);
}
waitKey(0);
vector<Point2f> pts_dst(4);
pts_dst[0] = Point2f(472,52);
pts_dst[1] = Point2f(472,830);
pts_dst[2] = Point2f(800,830);
pts_dst[3] = Point2f(800,52);
Mat h = findHomography(pts_src, pts_dst);
Mat Rin;
Rin = Mat::zeros(I.rows, I.cols, I.type());
warpPerspective(I,Rin,h,I.size());
imwrite("Transformed.jpg", Rin);
imshow("Transformed",Rin);
waitKey(0);
Mat ROI(Rin, Rect(472,52,328,778));
Mat croppedImage;
// Copy the data into new matrix
ROI.copyTo(croppedImage);
imwrite("Final_cropped.jpg", croppedImage);
imshow("Final_cropped",croppedImage);
waitKey(0);
}