???????????????C++???????
???????????? ???????[ 2014/10/14 13:30:21 ] ??????????????? C++
?????????????????????????£??????????????????
????(1) ??????????????????????????????(x?? y)?????
????(2) ?ж???????????????????????????????????????????????????????(x?? y)??y????????????
????(3) ???????(x?? y)?????????????????????????????????????硣????????ε????????????xLeft??xRight??
????(4) ??????????????????y - 1??y + 1???????????????[xLeft?? xRight]?е????????xLeft?????xRight????????????????????δ????????????????Щ????????????????????????????????????????У????????2??????
??????????c++???????????£?
1 //????????????????????????????????????????
2 #include <iostream>
3 #include "cv.h"
4 #include "highgui.h"
5 #include <stack>
6 #include <list>
7 #include <string>
8
9 using namespace std;
10 int ScanLine_SeedFillingAlgoE(IplImage *src??IplImage *dst??int MinCutNumb);//?????????????????????
11 int main()
12 {
13 IplImage *ipl_origin;
14 IplImage *ipl_target;
15 string fname = "C:/Users/zcx/Desktop/???????????/?????????????/Fight1save";
16 cvNamedWindow("????");
17 cvNamedWindow("???????");
18 for (int k=0;k<246;k++)
19 {
20 string filename="";
21 char tmp[20];
22 _itoa_s(k??tmp??20??10);
23 filename+=tmp;
24 filename+=".bmp";
25 filename=fname+filename;
26 ipl_origin=cvLoadImage(filename.c_str()??-1);
27 //ipl_target=cvCreateImage(cvGetSize(ipl_origin)??8??1);//cvCloneImage(ipl_origin);
28
29 //cvZero(ipl_target);
30 cvShowImage("????"??ipl_origin);
31 int s=clock();
32 ScanLine_SeedFillingAlgoE(ipl_origin??ipl_origin??125);
33 int e=clock();
34 std::cout<<" "<<e-s;
35 cvShowImage("???????"??ipl_origin);
36 cvWaitKey(1);
37
38 }
39
40
41
42
43
44
45 cvWaitKey(0);
46 cvReleaseImage(&ipl_origin);
47 //cvReleaseImage(&ipl_target);
48 cvDestroyWindow("????");
49 cvDestroyWindow("???????");
50
51 }
52 //MinCutNumb??????????С??MinCutNumb?????
53 //????????????
54 int ScanLine_SeedFillingAlgoE(IplImage *src??IplImage *dst??int MinCutNumb)
55 {
56 int width = src->width;
57 int height = src->height;
58 int targetSumNumb=0;//?????
59 int area;//???????
60 int rcount=0??lcount=0;//??????????????????
61 int yLeft??yRight;//????????????
62 //IplImage *src=cvCreateImage(cvGetSize(p_src)??8??1);//cvCloneImage(p_src);
63 //cvCopy(p_src??src);
64 CvPoint direction_4[]={{-1?? 0}?? {0?? 1}?? {1?? 0}?? {0?? -1}};//????????
65 //CvPoint direction_8[] = { {-1?? 0}?? {-1?? 1}?? {0?? 1}?? {1?? 1}?? {1?? 0}?? {1?? -1}?? {0?? -1}?? {-1?? -1} };//????
66 int n_Count=sizeof(direction_4)/sizeof(CvPoint);//???????????
67 std::list<CvPoint> stk;//stl?
68 std::list<CvPoint> lst;//stl????
69
70 IplImage *tempimage=cvCreateImage(cvGetSize(src)??8??1);//??????????????????????????????????????
71 int t_i??t_j;//????????λ??
72 int rt_j??lt_j;//????????
73 cvZero(tempimage);//???????????????0
74 for (int i=1;i<height-1;i++)
75 {
76 for (int j=1;j<width-1;j++)
77 {
78 //int s=clock();
79
80 //
81 if (src->imageData[i*width+j])
82 {
83 targetSumNumb++;
84 stk.push_back(cvPoint(i??j));//?????????
85 lst.push_back(cvPoint(i??j));
86 src->imageData[i*width+j]=0;//??????
87 //tempimage->imageData[i*width+j]=255;
88 area=1;
89 while (!stk.empty())
90 {
91 CvPoint seed=stk.back();//???????
92 stk.pop_back();
93 t_i=seed.x;
94 rt_j=lt_j=t_j=seed.y;
95 if (t_i<=0||t_i>=height)//??????????
96 continue;
97 //???????
98 rcount=0??lcount=0;
99 while (rt_j<width)
100 {
101 //++t_j;
102 if (src->imageData[t_i*width+(++rt_j)])
103 {
104 rcount++;
105 lst.push_back(cvPoint(t_i??rt_j));
106 src->imageData[t_i*width+rt_j]=0;//??????
107 }
108 else
109 {
110 break;
111 }
112 }
113 area+=rcount;
114 yRight=t_j+rcount;//???????
115 //???????
116 while (lt_j>0)
117 {
118 //++t_j;
119 if (src->imageData[t_i*width+(--lt_j)])
120 {
121 lcount++;
122 lst.push_back(cvPoint(t_i??lt_j));
123
124 src->imageData[t_i*width+lt_j]=0;//??????
125 }
126 else
127 {
128 break;
129 }
130 }
131 area+=lcount;
132 yLeft=t_j-lcount;//???????
133 //??????????????
134 int up_yLeft=yLeft??up_yRight=yRight;
135 bool up_findNewSeed = false;//?ж????????????
136 while(up_yLeft<=up_yRight)
137 {
138 up_findNewSeed = false;
139 while(src->imageData[(t_i-1)*width+up_yLeft]&&up_yLeft<width)
140 {
141 up_findNewSeed=true;
142 up_yLeft++;
143 }
144
145 if (up_findNewSeed)
146 {
147 if (up_yLeft==up_yRight)
148 {
149 stk.push_back(cvPoint(t_i-1??up_yLeft));
150 lst.push_back(cvPoint(t_i-1??up_yLeft));
151 src->imageData[(t_i-1)*width+up_yLeft]=0;//??????
152 }
153 else
154 {
155 stk.push_back(cvPoint(t_i-1??up_yLeft-1));
156 lst.push_back(cvPoint(t_i-1??up_yLeft-1));
157 src->imageData[(t_i-1)*width+up_yLeft-1]=0;//??????
158 }
159 up_findNewSeed=false;
160 }
161 int itemp=up_yLeft;
162 while (!src->imageData[(t_i-1)*width+up_yLeft]&&up_yLeft<up_yRight)
163 {
164 up_yLeft++;
165 }
166 if (itemp==up_yLeft)
167 {
168 up_yLeft++;
169 }
170 }
171
172 //??????????????
173 int down_yLeft=yLeft??down_yRight=yRight;
174 bool down_findNewSeed = false;//?ж????????????
175 while(down_yLeft<=down_yRight)
176 {
177 down_findNewSeed = false;
178 while(src->imageData[(t_i+1)*width+down_yLeft]&&down_yLeft<width)
179 {
180 down_findNewSeed=true;
181 down_yLeft++;
182 }
183
184 if (down_findNewSeed)
185 {
186 if (down_yLeft==down_yRight)
187 {
188 ++area;
189 stk.push_back(cvPoint(t_i+1??down_yLeft));
190 lst.push_back(cvPoint(t_i+1??down_yLeft));
191 src->imageData[(t_i+1)*width+down_yLeft]=0;//??????
192 }
193 else
194 {
195 ++area;
196 stk.push_back(cvPoint(t_i+1??down_yLeft-1));
197 lst.push_back(cvPoint(t_i+1??down_yLeft-1));
198 src->imageData[(t_i+1)*width+down_yLeft-1]=0;//??????
199 }
200 down_findNewSeed=false;
201 }
202 int itemp=down_yLeft;
203 while (!src->imageData[(t_i+1)*width+down_yLeft]&&down_yLeft<down_yRight)
204 {
205 down_yLeft++;
206 }
207 if (itemp==down_yLeft)
208 {
209 down_yLeft++;
210 }
211
212 }
213
214
215
216
217
218
219
220 }
221 //int e=clock();
222 //std::cout<<e-s;
223 if (area>MinCutNumb)
224 {
225 //cvOr(dst??tempimage??dst);
226 while (!lst.empty())
227 {
228 CvPoint tmpPt=lst.front();
229 lst.pop_front();
230 tempimage->imageData[tmpPt.x*width+tmpPt.y]=255;
231 }
232 }
233 else
234 {
235 //std::list<CvPoint>().swap(lst);
236 //while (!lst.empty()) lst.pop_back();
237 //lst.resize(0);
238 //lst.
239 lst.clear();
240 }
241
242 }//?ж???????
243 //CvPoint
244
245 }
246 }
247 //cvZero(dst);
248 cvCopy(tempimage??dst);
249 cvReleaseImage(&tempimage);
250 return targetSumNumb;
251 }
????Ч?????????
????С?????С???Ч?????????????????????????????????????????????????Ч???????????????ο????????д?????????????????£???????????
???????????????????????漰???????????????????SPASVOС??(021-61079698-8054)?????????????????????????
??????
??C++????????????C++ lvalue??rvalueC++11????????C++???????????????C++?е?????????????????C++?????????C++???Windows????λ??C/C++???????????????????JAVA??C??C++??????????c++??python???????????????????????????????C++???????C++?е????????C++????????????????C++ ???????????????C++?????????????????????C++????????????
???·???
??????????????????
2023/3/23 14:23:39???д?ò??????????
2023/3/22 16:17:39????????????????????Щ??
2022/6/14 16:14:27??????????????????????????
2021/10/18 15:37:44???????????????
2021/9/17 15:19:29???·???????·
2021/9/14 15:42:25?????????????
2021/5/28 17:25:47??????APP??????????
2021/5/8 17:01:11????????
?????????App Bug???????????????????????Jmeter?????????QC??????APP????????????????app?????е????????jenkins+testng+ant+webdriver??????????????JMeter????HTTP???????Selenium 2.0 WebDriver ??????