[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.

Question
[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!

7.7

error!

Asked by gen12324 in C++ Programming Language, Open Source Programming, C++ Builder

Hi, right now i'm testing motion tracker with optical flow. When i run it, it appears to have error.
How should i solve it? I'm new to c++

First-chance exception at 0x00411b98 in Motion Tracker with Optical Flow.exe: 0xC0000005: Access violation writing location 0x02ba9000.
Unhandled exception at 0x00411b98 in Motion Tracker with Optical Flow.exe: 0xC0000005: Access violation writing location 0x02ba9000.
The program '[1540] Motion Tracker with Optical Flow.exe: Native' has exited with code 0 (0x0).
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:
184:
185:
186:
187:
188:
189:
190:
191:
192:
193:
194:
195:
196:
197:
198:
199:
200:
201:
202:
203:
204:
205:
206:
207:
208:
209:
210:
211:
212:
213:
214:
215:
216:
217:
218:
219:
220:
221:
222:
223:
224:
225:
226:
227:
228:
229:
230:
231:
232:
233:
234:
235:
236:
237:
238:
239:
240:
241:
242:
243:
244:
245:
246:
247:
248:
249:
250:
251:
252:
// Motion Tracker with Optical Flow.cpp : Defines the entry point for the console application.
//
 
#include <stdafx.h>
#include <cv.h>
#include <highgui.h>
#include <math.h>
#include <stdio.h>
 
 
const int MAX_COUNT = 2000;
int count = 0, startOfTrackPoints = 0;
 
CvPoint2D32f* points[2] = {0,0};
 
IplImage *color_img=0;
 
/* Listener for mouse clicks */
void OnMouseClick(int event, int x, int y, int flags, void* param)
{
	    
	if(color_img->origin)
	y = color_img->height - y;
	if(event == CV_EVENT_LBUTTONDOWN && count < MAX_COUNT) 
	{
		// Add point
		points[1][count] = points[0][count] = cvPoint2D32f(x, y); 
		count++;
	}
	
}
int main(int argc,char *argv[])
{
	
	int c, i, j, step, win_size, flags, color;
	char* status = 0;
 
	CvCapture* capture = cvCaptureFromCAM( CV_CAP_ANY );
	if( !capture ) 
	{
    fprintf( stderr, "ERROR: capture is NULL \n" );
    getchar();
    return -1;
	}
printf("Debug 1\n");
	IplImage *gray_img, *prev_img, *curr_img;
	IplImage *pyramid, *prev_pyramid, *optical_flow_field;
	CvPoint p1, p2, p3, p4, p5;
	printf("Welcome to Ax demo! ^_^\n");
	printf("Click on the 'This is my webcam!' window to add trackballs.\n");
	printf("The 'Field' window shows the optical flow with larger \n");
	printf("arrows corresponding to larger displacements.\n\n");
	printf("Keyboard commands:\n");
	printf(" ESC to quit\n");
	printf(" c to clear all the trackballs\n");
	printf(" n to cycle through the different trackball colors\n");
 
/* Initialization and space allocation */
color_img = cvQueryFrame(capture);
if(!color_img)
return 0;
 
gray_img = cvCreateImage(cvSize(color_img->width,color_img->height), IPL_DEPTH_8U, 1);
optical_flow_field = cvCreateImage( cvSize(color_img->width,color_img->height), IPL_DEPTH_8U, 1);
prev_img = cvCreateImage(cvSize(color_img->width,color_img->height), IPL_DEPTH_8U, 1);
curr_img = cvCreateImage(cvSize(color_img->width,color_img->height), IPL_DEPTH_8U, 1);
pyramid = cvCreateImage(cvSize(color_img->width,color_img->height), IPL_DEPTH_8U, 1);
prev_pyramid = cvCreateImage(cvSize(color_img->width,color_img->height), IPL_DEPTH_8U, 1);
 
gray_img->origin = color_img->origin;
optical_flow_field->origin = color_img->origin;
prev_img->origin = color_img->origin;
curr_img->origin = color_img->origin;
pyramid->origin = color_img->origin;
prev_pyramid->origin = color_img->origin;
 
	points[0] = (CvPoint2D32f*)cvAlloc(MAX_COUNT*sizeof(points[0][0]));
	points[1] = (CvPoint2D32f*)cvAlloc(MAX_COUNT*sizeof(points[0][0]));
	status = (char*)cvAlloc(MAX_COUNT);
	flags = 0;
	step = 10;
	win_size = 10;
	color = 0;
	
 
/* Create windows */
cvNamedWindow("This is my webcam!", CV_WINDOW_AUTOSIZE);
cvNamedWindow("Field", CV_WINDOW_AUTOSIZE);
 
/* Set up mouse event listener */
int mouseParam=5;
cvSetMouseCallback("This is my webcam!", OnMouseClick, &mouseParam);
 
/* Initialize the points to the points on the image separated
by distances of 10 pixels */
printf("Debug 2\n");
for(i = 0; i < color_img->height; i+=step) 
{
	for(j = 0; j < color_img->width; j+=step) 
	{
		points[0][count] = cvPoint2D32f(j, i);
		points[1][count] = cvPoint2D32f(j, i);
		count++; // count the number of points
		
	}
 
 
}
 
/* Where track points begin */
startOfTrackPoints = count;
 
/* Use the "first" frame */
color_img = cvQueryFrame(capture);
if(!color_img)
return 0;
 
cvCvtColor( color_img, gray_img, CV_BGR2GRAY );
 
/* Smooth to improve accuracy */
cvSmooth(gray_img, gray_img, CV_GAUSSIAN, 3, 0, 0);
cvSmooth(gray_img, gray_img, CV_GAUSSIAN, 3, 0, 0);
cvSmooth(gray_img, gray_img, CV_GAUSSIAN, 3, 0, 0);
cvCopy(curr_img, prev_img, 0);
cvCopy(gray_img, curr_img, 0);
 
/* Begin the main infinite loop until break */
for(;;) 
{
	color_img = cvQueryFrame(capture);
	if(!color_img)
	break;
	cvCvtColor( color_img, gray_img, CV_BGR2GRAY );
 
	/* Smooth to improve accuracy */
	cvSmooth(gray_img, gray_img, CV_GAUSSIAN, 3, 0, 0);
	cvSmooth(gray_img, gray_img, CV_GAUSSIAN, 3, 0, 0);
	cvSmooth(gray_img, gray_img, CV_GAUSSIAN, 3, 0, 0);
	cvCopy(curr_img, prev_img, 0);
	cvCopy(gray_img, curr_img, 0);
	cvCopy(pyramid, prev_pyramid, 0);
 
	for(i = startOfTrackPoints; i < count; i++)
	points[0][i] = points[1][i];
 
	/* Calculate the optical flow using pyramidal iterative LK */
	cvCalcOpticalFlowPyrLK(prev_img, curr_img, prev_pyramid, pyramid,
	points[0], points[1], count, cvSize(win_size, win_size), 3, status, 0,
	cvTermCriteria(CV_TERMCRIT_ITER|CV_TERMCRIT_EPS,20,0.03), flags);
 
	/* Threshold to ignore noise */
	for(i = startOfTrackPoints; i < count; i++)
	if(abs((int)(points[0][i].x - points[1][i].x)) > 50 ||
	abs((int)(points[0][i].y - points[1][i].y)) > 50)
	points[1][i] = points[0][i];
 
	/* Set flags */
	flags |= CV_LKFLOW_PYR_A_READY;
 
	/* Refresh the optical flow field */
	for (i = 0; i < optical_flow_field->height; i++)
	for (j = 0; j < optical_flow_field->width; j++)
	(optical_flow_field->imageData + optical_flow_field->widthStep*i)[j] = (char)255;
 
	/* Draw the optical flow field; the greater the velocity, the bigger the
	respective arrow and arrowhead will be for better visualization */
 
for (i = 0; i < startOfTrackPoints; i++) 
{
	/* Threshold velocities: not drawing very small or very large velocities */
	if((abs((int)(points[0][i].x - points[1][i].x)) >= 1 ||
	abs((int)(points[0][i].y - points[1][i].y)) >= 1) &&
	(abs((int)(points[0][i].x - points[1][i].x)) <= 20 &&
	abs((int)(points[0][i].y - points[1][i].y)) <= 20)) 
	{
 
		/* Arrow */
		cvLine(optical_flow_field, cvPointFrom32f(points[0][i]),
		cvPointFrom32f(points[1][i]), cvScalar(0, 0, 0,0), 1, 8, 0);
		/* Arrowhead */
 
		p1 = cvPoint((int)(cvPointFrom32f(points[0][i]).x + 0.7*(cvPointFrom32f(points[1][i]).x - cvPointFrom32f(points[0][i]).x)),
		(int)(cvPointFrom32f(points[0][i]).y + 0.7*(cvPointFrom32f(points[1][i]).y -
		cvPointFrom32f(points[0][i]).y)));
 
		p2 = cvPoint((int)(cvPointFrom32f(points[0][i]).x + 0.7*(cvPointFrom32f(points[1][i]).x -
		cvPointFrom32f(points[0][i]).x)),
		(int)cvPointFrom32f(points[1][i]).y);
 
		p3 = cvPoint((int)cvPointFrom32f(points[1][i]).x,(int)(cvPointFrom32f(points[0][i]).y +
		0.7*(cvPointFrom32f(points[1][i]).y - cvPointFrom32f(points[0][i]).y)));
 
		p4 = cvPoint((int)(p1.x + 0.5*(p2.x-p1.x)),
		(int)(p1.y + 0.5*(p2.y-p1.y)));
 
		p5 = cvPoint((int)(p1.x + 0.5*(p3.x-p1.x)),
		(int)(p1.y + 0.5*(p3.y-p1.y)));
 
		cvLine(optical_flow_field, cvPointFrom32f(points[1][i]),
		p4, cvScalar(0, 0, 0,0), 1, 8, 0);
 
		cvLine(optical_flow_field, cvPointFrom32f(points[1][i]),
		p5, cvScalar(0, 0, 0,0), 1, 8, 0);
	}
 
	else 
	{
		/* Draws a dot */
		cvLine(optical_flow_field, cvPointFrom32f(points[0][i]),
		cvPointFrom32f(points[0][i]), cvScalar(0, 0, 0,0), 1, 8, 0);
	}
 
}
 
for(i = startOfTrackPoints; i < count; i++) 
{
	/* Draw trackballs */
	if(color == 0)
	cvCircle(color_img, cvPoint((int)points[1][i].x, (int)points[1][i].y),
	5, cvScalar(0,255,0,0), 3, 8, 0);
 
	else if(color == 1)
	cvCircle(color_img, cvPoint((int)points[1][i].x, (int)points[1][i].y),
	5, cvScalar(255,0,0,0), 3, 8, 0);
 
	else
	cvCircle(color_img, cvPoint((int)points[1][i].x, (int)points[1][i].y), 5, cvScalar(0,255,255,0), 3, 8, 0);
}
 
	/* Show images */
	cvShowImage("This is my webcam!", color_img);
	cvShowImage("Field", optical_flow_field);
	/* Wait */
	c = cvWaitKey(10);
	/* Check for ESC */
if(c == 27)
break;
 
else if(c == 'c')
startOfTrackPoints = count;
 
else if(c == 'n') 
{
	color++;
	color = color % 3;
	}
}
	/* Release windows */
	cvReleaseCapture(&capture);
	cvDestroyWindow("This is my webcam!");
	cvDestroyWindow("Field");
}
[+][-]08/07/09 03:04 AM, ID: 25041236Accepted Solution

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: C++ Programming Language, Open Source Programming, C++ Builder
Sign Up Now!
Solution Provided By: pepr
Participating Experts: 2
Solution Grade: A
 
[+][-]08/07/09 12:40 AM, ID: 25040559Expert Comment

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/07/09 12:50 AM, ID: 25040588Author Comment

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/07/09 12:59 AM, ID: 25040622Author Comment

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/07/09 01:19 AM, ID: 25040701Expert Comment

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/07/09 01:51 AM, ID: 25040861Author Comment

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/07/09 02:01 AM, ID: 25040922Author Comment

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/07/09 03:06 AM, ID: 25041244Expert Comment

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/07/09 11:08 AM, ID: 25045432Author Comment

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/07/09 03:45 PM, ID: 25047453Expert Comment

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/08/09 03:19 AM, ID: 25049104Assisted Solution

Assisted solutions are selected by the member who asked the question as a comment that contributed to their question's solution.

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

 
[+][-]08/09/09 07:41 PM, ID: 25056864Author Comment

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/10/09 02:52 AM, ID: 25058365Author Comment

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/11/09 07:07 PM, ID: 25075183Author Comment

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 09:09 PM, ID: 25085380Author Comment

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 09:12 PM, ID: 25085386Author Comment

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/13/09 02:22 AM, ID: 25086518Expert Comment

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/13/09 03:29 AM, ID: 25086803Author Comment

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/13/09 03:36 AM, ID: 25086834Expert Comment

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/13/09 03:42 AM, ID: 25086857Author Comment

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/13/09 04:20 AM, ID: 25087046Author Comment

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/13/09 06:15 AM, ID: 25087809Expert Comment

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/13/09 06:25 PM, ID: 25094621Author Comment

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/13/09 06:36 PM, ID: 25094661Author Comment

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/13/09 11:40 PM, ID: 25095666Expert Comment

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.

 
 
Loading Advertisement...
20091118-EE-VQP-93 - Hierarchy / EE_QW_3_20080625