-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathhough.cpp
More file actions
88 lines (68 loc) · 1.9 KB
/
hough.cpp
File metadata and controls
88 lines (68 loc) · 1.9 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
#include <iostream>
#include <stdio.h>
#include<deque>
#include <opencv2/imgproc/imgproc.hpp>
#include <opencv2/highgui/highgui.hpp>
#include<opencv2/core/core.hpp>
using namespace cv;
using namespace std;
# define THD 1 //threshold on max dist abt. a line segment
# define THL 31 //threshold on the min no of points to be present for it to be called a "line"
int main(){
int ptdist;
Mat src=imread("human.jpg",0);
Mat op(src.rows,src.cols,CV_8UC1,Scalar(0));
//to binary
for(int i=0;i<src.rows;i++){
for(int j=0;j<src.cols;j++){
int avg=src.at<uchar>(i,j);
op.at<uchar>(i,j)=(avg<150)?0:255;
}
}
src=op.clone();
namedWindow("IP",WINDOW_NORMAL);
int maxd=sqrt(src.rows*src.rows + src.cols*src.cols);
short int data[maxd][180];
for(int i=0;i<maxd;i++){
for (int j=0;j<180;j++){
data[i][j]=0;
}
}
for(int m=0;m<src.rows;m++){//row no
for(int n=0;n<src.cols;n++) {//col no
if(src.at<uchar>(m,n)==255){//this point "exists" in the image
for(int i=0;i<maxd;i++){//perp dist
for(int j=0;j<180;j++){ //generate data[i][(3.14*j)/180]
ptdist=abs(n*cos(j*3.14/180)+m*sin(j*3.14/180)-i);
if(ptdist<THD)
data[i][j]++;
}
}
}
}
}
//cout<<"DONE2"<<endl<<endl;
Mat op2(src.rows,src.cols,CV_8UC1,Scalar(0));
op=op2.clone();
for (int i=0;i<maxd; i++){//perp dist
for (int j=0;j<180;j++){//angle
if(data[i][j]>=THL) { //retain
//cout<<"CRSD:"<<i<<","<<j<<endl;
for(int m=0;m<src.rows;m++){//row
for (int n=0;n<src.cols;n++){//col
// if(src.at<uchar>(m,n)==255){//this point "exists" in the image
ptdist=abs(n*cos(j*3.14/180)+m*sin(j*3.14/180)-i);
if(ptdist<THD)
op.at<uchar>(m,n)=255;
}
}
//}
}
}
}
imshow("IP",src);
namedWindow("OP",WINDOW_NORMAL);
imshow("OP",op);
waitKey(0);
return 0;
}