[x]
Posted via EE Mobile

Search, ask, and monitor your questions on the go with EE Mobile. Visit Experts Exchange from your mobile device and never be out of touch again.

08/11/2009 at 10:53PM PDT, ID: 24645516
[x]
Attachment Details
[x]
The Solution Rating System

With so many solutions, how can you tell which solutions are most likely to help you and which ones are not? To provide you with a tool to use, we rate our solutions based on various elements that most accurately determine if a solution is a quality solution. To explain what factors affect the solution rating, here are the elements we take into consideration when formulating our solution rating.

  • The Grade of the Solution
  • The Zone Rank of the Expert Providing the Solution
  • The Number of Author and Expert Comments
  • The Number of Experts Contributing
  • The Feedback of the Community

Your Input Matters
Because of the way the system is set up, the most important variable in this equation is you. As a member of Experts Exchange, you are able to cast your vote on the quality of the solutions in regard to how complete, accurate, helpful and easy to understand each solution is. When you provide your feedback, each rating is adjusted accordingly. So, if you see a solution that has a poor rating that you think is a good solution, let us know by rating it. As you do, the rating will be adjusted and will become more accurate for other members of our site.

If you have any suggestions that you would like to make for our rating system, please ask a question in the Suggestions Zone of Community Support.

Thank you!

6.8

why is it so slow for my background subtraction

Asked by gen12324 in Algorithms, Microsoft Visual C++.Net, Windows Programming

can someone tell me why my code run so slow for the background subtraction? Is there any ways to make it faster?
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:
126:
127:
128:
129:
130:
131:
132:
133:
134:
135:
136:
137:
138:
139:
140:
141:
142:
143:
144:
145:
146:
147:
148:
149:
150:
151:
152:
153:
154:
155:
156:
157:
158:
159:
160:
161:
162:
163:
164:
165:
166:
167:
168:
169:
170:
171:
172:
173:
174:
175:
176:
177:
178:
179:
180:
181:
182:
183:
// Background subtraction with edge detection.cpp : Defines the entry point for the console application.
//
#include "stdafx.h"
#include <cv.h>
#include <cvaux.h> 
#include <highgui.h> 
#include <ctype.h> 
#include <stdio.h> 
 
IplImage *frame1 = NULL, *frame2 = NULL, *frame3 = NULL; 
IplImage *diff1 = NULL, *diff2 = NULL, *result = NULL; 
//IplImage* cannyImg; 
IplImage *grayImg = 0; // gray image 
 
int main(int argc, char** argv) 
{ 
int height,width,step,channels; 
uchar *data1, *data2, *data3, *diffData1, *diffData2, *resultData; 
 
int i, j; 
int threshold = 30; 
int diff; 
 
/* Start capturing */ 
 
 
CvCapture* capture = cvCaptureFromCAM( CV_CAP_ANY );
	if( !capture ) 
	{
    fprintf( stderr, "ERROR: capture is NULL \n" );
    getchar();
    return -1;
	}
	
 
//capture = cvCaptureFromAVI("C:\Documents and Settings\biob202\Desktop\ax fyp\optical_flow_input.avi"); 
 
 
int //mode = CV_RETR_EXTERNAL; 
  
    mode = CV_RETR_EXTERNAL; //detect both outside and inside contour 
  
 
if( !capture ) 
 
{ 
        
fprintf(stderr,"Could not initialize...\n"); 
//return -1; 
 
} 
 
/* Capture 1 video frame for initialization */ 
 
frame2 = cvQueryFrame(capture);    // retrive from the video 
frame3 = cvQueryFrame(capture); 
 
/* Create windows */ 
 
cvNamedWindow("Actual Video", 1);    // creating window 
 
cvNamedWindow("With Differencing", 1); 
cvMoveWindow("With Differencing", 500,0); 
cvNamedWindow("BackGround", 1); 
cvMoveWindow("BackGround", 100,350); 
 
//cvNamedWindow("canny Edge",1); 
//cvMoveWindow("canny Edge", 750, 350); 
 
CvBGStatModel* bg_model; 
 
bg_model =cvCreateGaussianBGModel( frame2 ); 
 
 
/* Get properties of frame */ 
width = frame2->width; 
height = frame2->height; 
step = frame2->widthStep; 
channels = frame2->nChannels; 
 
int key=-1; 
while(key != 'q') 
{ 
        
 
/* Get consecutive frames */ 
frame1 = cvCloneImage(frame2); 
 
// cvReleaseData(frame2); 
// cvReleaseImage(&frame2); 
frame2 = cvCloneImage(frame3); 
 
// cvReleaseData(frame3); 
// cvReleaseImage(&frame3);  
frame3 = cvQueryFrame(capture); 
 
/* Initialize difference and result frames */ 
diff1 = cvCloneImage(frame3); 
diff2 = cvCloneImage(frame3); 
result = cvCloneImage(frame3); 
 
 
/* Image is treated as at unsigned char data hence we use an 
unsigned char pointer to point to the same to access pixels */ 
 
data1 = (uchar *)frame1->imageData; 
data2 = (uchar *)frame2->imageData; 
data3 = (uchar *)frame2->imageData; 
diffData1 = (uchar *)diff1->imageData; 
diffData2 = (uchar *)diff2->imageData; 
resultData = (uchar *)result->imageData; 
 
 
/* Get difference of frames */ 
cvAbsDiff(frame2,frame1,diff1); 
cvAbsDiff(frame3,frame2,diff2); 
cvUpdateBGStatModel( frame2, bg_model ); 
 
 
 
// Check for threshold 
 
for(i=0;i<=height-1;i++) 
{ 
for(j=0;j<=width-1;j++) 
{ 
//Difference depends on sum of pixels on each channel 
 
if(((diffData1[i*step+j*channels+0] + 
diffData1[i*step+j*channels+1] + diffData1[i*step+j*channels+2]) > 
threshold) && ((diffData2[i*step+j*channels+0] + 
diffData2[i*step+j*channels+1] + diffData2[i*step+j*channels+2]) > 
threshold)) 
{ 
resultData[i*step+j*channels+0] = 255; 
resultData[i*step+j*channels+1] = 255; 
resultData[i*step+j*channels+2] = 255; 
} 
else 
{ 
resultData[i*step+j*channels+0] = 0; 
resultData[i*step+j*channels+1] = 0; 
resultData[i*step+j*channels+2] = 0; 
} 
} 
}
 
//end of frame differencing with binarization 
 
grayImg = cvCreateImage( cvSize(result->width, result->height), 
IPL_DEPTH_8U, 1 ); 
    
    //convert original color image (3 channel rgb color image) to gray-level image 
    cvCvtColor( result, grayImg, CV_BGR2GRAY ); 
   // cannyImg = cvCreateImage(cvGetSize(result), IPL_DEPTH_8U, 1); 
 
// cvCanny(grayImg, cannyImg, 50, 150, 3); 
 
 
cvShowImage("Actual Video",frame2); 
cvShowImage("With Differencing",result); 
cvShowImage("BackGround", bg_model->background); 
//cvShowImage("canny Edge", cannyImg); 
 
  
 
cvReleaseImage(&frame1); 
cvReleaseImage(&diff1);  
cvReleaseImage(&diff2); 
cvReleaseImage(&result); 
 
key = cvWaitKey(10); 
}//end of while 
 
 
cvDestroyWindow("Actual Video"); 
cvDestroyWindow("With Differencing"); 
cvDestroyWindow("BackGround"); 
//cvDestroyWindow("canny"); 
cvReleaseCapture(&capture); 
 
return 0; 
}
[+][-]08/11/09 11:10 PM, ID: 25076064

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 30-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]08/12/09 12:40 AM, ID: 25076422

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 30-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]08/12/09 01:57 AM, ID: 25076809

View this solution now by starting your 30-day free trial. Setting up your free trial is quick, easy, and secure. We will return you to this solution, unlocked, when you're done.

 

About this solution

Zones: Algorithms, Microsoft Visual C++.Net, Windows Programming
Sign Up Now!
Solution Provided By: AndyAinscow
Participating Experts: 2
Solution Grade: A
 
 
[+][-]08/12/09 03:26 AM, ID: 25077256

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 30-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]08/12/09 03:59 AM, ID: 25077397

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 30-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]08/12/09 04:18 AM, ID: 25077484

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 30-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]08/12/09 04:31 AM, ID: 25077567

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 30-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]08/12/09 05:51 AM, ID: 25078143

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 30-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]08/12/09 08:08 PM, ID: 25085209

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 30-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]08/12/09 08:11 PM, ID: 25085215

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 30-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]08/12/09 08:56 PM, ID: 25085347

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 30-day free trial to view this Author Comment or ask the Experts your question.

 
 
Loading Advertisement...
20091111-EE-VQP-91 - Hierarchy / EE_QW_3_20080625