-
Notifications
You must be signed in to change notification settings - Fork 0
/
task_2.cpp
96 lines (95 loc) · 2.15 KB
/
task_2.cpp
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
#include"opencv2/highgui/highgui.hpp"
#include"opencv2/imgproc/imgproc.hpp"
#include"opencv2/core/core.hpp"
#include<bits/stdc++.h>
using namespace cv;
using namespace std;
Mat img1 = imread("left_image.jpg",0);
Mat img2 = imread("right_image.jpg",0);
map<pair<int,int>,double> mp;
double dist(int sx,int sy,int dx,int dy){
return sqrt((sx-dx)*(sx-dx) + (sy-dy)*(sy-dy));
}
int main()
{
int rows = img1.rows, cols = img1.cols;
int arr[img1.rows+1][img1.cols+1];
int x,y,i,j,k,l;
for( x=0;x<img1.rows;x++)
{
for( y=0;y<img1.cols;y++)
{
arr[x][y] = 0;
}
}
cout<<"a"<<endl;
for( i=0;i<rows;++i)
{
for( j=0;j<cols;++j)
{
// store the pixel color of (i,j)
bool flag=false;
int steps;
for( steps=10;flag!=true && steps < 300;steps+=10)
{
int left = max(0,j-steps);
int right= min(cols,j+steps);
int up = max(0,i-steps);
int down = min(rows,i+rows);
cout<<"b"<<endl;
for( k=up;k<down;++k)
{
for( l=left;l<right;++l)
{
//check if pixel color of (i,j) & (k,l)
// is same
//if yes then do following
if(img1.at<uchar>(i,j) == img2.at<uchar>(k,l))
{
pair<int,int> p = make_pair(i,j);
arr[i][j] = (int)dist(i,j,k,l);
flag=true;
cout<<"c"<<endl;
break;
}
}
if(flag)
{
break;
}
}
if(flag)
{
break;
}
}
}
}
//create a new image
Mat img3(img1.rows,img1.cols,CV_8UC1,Scalar(0));
double max =0,min =1234;
for(int x=0;x<img1.rows;x++)
{
for(int y=0;y<img1.cols;y++)
{
if(arr[x][y] > max)
max = arr[x][y];
if(arr[x][y] < min)
min = arr[x][y];
cout<<"d"<<endl;
}
}
for(x=0;x<img1.rows;x++)
{
for(y=0;y<img1.cols;y++)
{
arr[x][y] = (int)( 255 * ((double)arr[x][y] / (max-min)));
img3.at<uchar>(x,y) = arr[x][y];
cout<<"e"<<endl;
}
}
cout<<"f"<<endl;
namedWindow("win",WINDOW_NORMAL);
imshow("win", img3);
waitKey(0);
}