-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbucktfill.cpp
More file actions
125 lines (94 loc) · 2.02 KB
/
Copy pathbucktfill.cpp
File metadata and controls
125 lines (94 loc) · 2.02 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
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
#include <iostream>
#include <stdio.h>
//#include <math.h>
#include <stdlib.h>
#include<deque>
#include <opencv2/imgproc/imgproc.hpp>
#include <opencv2/highgui/highgui.hpp>
#include<opencv2/core/core.hpp>
using namespace cv;
using namespace std;
typedef struct _point{
unsigned int i,j;
}point;
Mat src,op;
int isred(Mat G, int i, int j){
if(G.at<Vec3b>(i,j)[0]>100 && G.at<Vec3b>(i,j)[1]>100)
return 1;
else return 0;
}
void CallBackFunc(int event, int x, int y, int flags, void* userdata){
if (event==EVENT_LBUTTONDOWN) {
point beg;
op=src.clone();
//imshow("OP",src);
beg.i=y;
beg.j=x;
deque<point>Q;//double ended queue
point r,u;
int i1,i2,j1,j2;
r.i=beg.i;
r.j=beg.j;
Q.push_back(r);
// n_blobs++;
while(!Q.empty()) {
//BFS
u=Q.front();
Q.pop_front();
i2=u.i;
j2=u.j;
//cout<<"ENT ";
i1=i2;j1=j2-1;
if(i1>0 && i1<src.rows && j1>0 && j1<src.cols) {
if(isred(op,i1,j1)){
op.at<Vec3b>(i1,j1)[0]=0;
op.at<Vec3b>(i1,j1)[1]=0;
r.i=i1;
r.j=j1;
Q.push_back(r);
}
}
i1=i2-1;j1=j2;
if(i1>0 && i1<src.rows && j1>0 && j1<src.cols){
if(isred(op,i1,j1)){
op.at<Vec3b>(i1,j1)[0]=0;
op.at<Vec3b>(i1,j1)[1]=0;
r.i=i1;
r.j=j1;
Q.push_back(r);
}
}
i1=i2+1;j1=j2;
if(i1>0 && i1<src.rows && j1>0 && j1<src.cols){
if(isred(op,i1,j1)){
op.at<Vec3b>(i1,j1)[0]=0;
op.at<Vec3b>(i1,j1)[1]=0;
r.i=i1;
r.j=j1;
Q.push_back(r);
}
}
i1=i2;j1=j2+1;
if(i1>0 && i1<src.rows && j1>0 && j1<src.cols){
if(isred(op,i1,j1)){
op.at<Vec3b>(i1,j1)[0]=0;
op.at<Vec3b>(i1,j1)[1]=0;
r.i=i1;
r.j=j1;
Q.push_back(r);
}
}
}
src=op.clone();
imshow("IP",op);
}
}
int main(){
src=imread("draw.png",1);
namedWindow( "IP",WINDOW_AUTOSIZE );
imshow("IP",src);
setMouseCallback("IP",CallBackFunc,NULL);
// CallBackFunc(0,0,0,0,NULL);
waitKey(0);
return 0;
}