-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdoc_scanner.cpp
More file actions
97 lines (72 loc) · 2.99 KB
/
Copy pathdoc_scanner.cpp
File metadata and controls
97 lines (72 loc) · 2.99 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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
//this code rotates and fits to screen the document, no matter how the image of the document was originally taken
//set the 4 points specifying the corners of the page in CW sense, starting from the top left
#include <bits/stdc++.h>
#include "opencv2/highgui/highgui.hpp"
#include "opencv2/imgproc/imgproc.hpp"
#include "opencv2/core/core.hpp"
#include "opencv2/opencv.hpp"
#include "/usr/include/eigen3/Eigen/Dense"
#include "/usr/include/eigen3/Eigen/Core"
using namespace std;
using namespace cv;
vector<Point2f> fv_points; //image will be of the front view
//these are the series of points which we will mark in the front view image
//for training, i.e to make the homography matrix, we take 4 points
vector<Point2f> tv_points;//these are the points which are supposed to be in the place defined here according to our calculations
//these are the correspoding 4 points , that we will input on our own
Mat img;
//Mat img1;
/*Mat h;*/
void CallBackFunc(int event, int x, int y, int flags, void* userdata)
{
if ( event == EVENT_RBUTTONDOWN )
{
cout << "(" << x << ", " << y << ")" << endl;
fv_points.push_back(Point2f(x,y));
if (fv_points.size() == 4)
{
Mat top(img.rows, img.cols, CV_8UC3, Scalar(0,0,0));
//Mat top1(img.rows, img.cols, CV_8UC3, Scalar(0,0,0));
Mat h = findHomography(fv_points, tv_points);
cout << "homography matrix" << endl;
cout << h << endl;
// cout << "-------------------------" << endl;
// cout << "pixelpermetre " << ppcm*100 << endl;
// cout << "yshift " << botfront_firstview << endl;
warpPerspective(img, top, h, Size(img.cols, img.rows));
//warpPerspective(img1, top1, h, Size(img.cols, img.rows));
namedWindow("top view", 0);
//namedWindow("top view1", 0);
imshow("top view", top);
//imshow("top view1", top1);
waitKey(0);
}
}
}
int main(int argc, char** argv)
{
img = imread("calibration.jpg",1);
//img1 = imread("test.jpg",1);
//resize(img, img, Size(img.cols/4, img.rows/4));
/*Mat front = imread("front.jpg",1);
Mat front_top(front.rows, front.cols, CV_8UC3, Scalar(0,0,0));
*/
namedWindow("front view", 0);
//namedWindow("front view1", 0);
namedWindow("top view", 0);
float pp_cm_y = (img.rows/105.5); //pixels per cm
//int c3, c4, c5, c6, c7, c8;
//we want the 4 corners of the page, to be the 4 corners of the image
tv_points.push_back( Point2f(0,0) );
tv_points.push_back( Point2f(0,img.cols-1) );
tv_points.push_back( Point2f(img.rows-1, img.cols-1) );
tv_points.push_back( Point2f(img.rows-1, 0) );
setMouseCallback("front view", CallBackFunc, NULL);
//imshow("front view1", img1);
imshow("front view", img);
/*warpPerspective(front, front_top, h, Size(img.rows, img.cols));
namedWindow("top view", 0);
imshow("top view", front_top);*/
waitKey(0);
return 0;
}