Open the file and add new data at any time.
File *fp;if((fp=fopen("data.txt","a"))==NULL){printf("Create File failure"); exit(1);}fprintf(fp,"[%d, %d]\n", x, y);fclose(fp);
Cyclic operations store a lot of data as follows:
[29, 35]
[29, 33]
[30, 34]
[29, 33]
[29, 34]
[29, 34]
[29, 34]
[28, 33]
[30, 34]
[30, 34]
[29, 33]
[28, 33]
[29, 33]
[29, 33]
[29, 34]
[29, 33]
The program uses files to save data for easy access and use elsewhere.
(Blog quality is getting lower and lower. Use it at any time ~~~~)
Open the file and read data.
Read the above data:
[Amount .... The above data is not read :]
29 35
29 33
30 34
29 33
29 34
29 34
29 34
28 33
30 34
30 34
29 33
28 33
FILE *fp = fopen("data.txt", "r");while( !feof(fp) ){v++;int x, y;fscanf(fp,"%d",&x);fscanf(fp,"%d",&y);·········
Read int-type data without stopping, knowing the end of the file.
OK to do this, mainly for testing.
-----
Roar
Anyway, I read my data and added it to the line fitting tested last week, as shown below:
# Include "stdafx. H "# include" stdio. H "# include" CV. H "# include" highgui. H "Void put_data_into_array (cvpoint dataarray [], cvpoint data, int N) {for (INT I = 0; I <n-1; I ++) dataarray [I] = dataarray [I + 1]; dataarray [n-1] = data;} int _ tmain (INT argc, _ tchar * argv []) {iplimage * IMG = cvcreateimage (cvsize (500,500), 8, 3); cvnamedwindow ("fitline", 1); cvpoint pt1, pt2; // cvpoint * points = (cvpoin T *) malloc (6 * sizeof (points [0]); // stores randomly generated points. The number is countcvmat pointmat = cvmat (1, 6, cv_32sc2, points ); // point set, which stores count random points pointsfloat line [4]; // output line parameters. In 2D fitting, it is an array containing four floating point numbers (VX, Vy, x0, y0) // Where (VX, Vy) is the unit vector of the line and (x0, y0) is an online point float t; file * fp = fopen ("data.txt", "R"); int V = 0; while (! Feof (FP) {v ++; int X, Y; fscanf (FP, "% d", & X); fscanf (FP, "% d ", & Y); put_data_into_array (points, cvpoint (x, y), 6); printf ("[% d, % d] \ n", x, y ); if (V> 6) {// find the optimal line curve to fit cvfitline (& pointmat, cv_dist_l1, 1, 0.001, 0.001, line ); // draw the two endpoints of a line segment (avoid line being too short and extend line [0] * t to both ends at a random point on the line) t = (float) (IMG-> width + IMG-> height); pt1.x = cvround (line [2]-line [0] * t ); pt1.y = cvround (line [3]-line [1] * t); pt2.x = cvround (line [2] + line [0] * t ); pt2.y = cvround (line [3] + line [1] * t); cvzero (IMG); cvline (IMG, pt1, pt2, cv_rgb (0,255, 0), 3, cv_aa, 0); cvcircle (IMG, cvpoint (x, y), 2, cv_rgb (255, 0, 0), cv_filled, cv_aa, 0 ); char key = cvwaitkey (20); cvshowimage ("fitline", IMG) ;}} fclose (FP); free (points); cvwaitkey (-1 ); cvdestroywindow ("fitline"); Return 0 ;}
PS:
I encountered a very tangled problem. I didn't add it at the beginning.
char key = cvWaitKey(20)
This statement can only display the last frame of the image.
At the beginning, I thought it was too fast to display it.
So also
# Include <windows. h>
Sleep (100 );
A moment later, o_o
Ah, it seems like someone who has learned opencv... This is the first thing that comes to mind ....
But let's talk about it again. We only know this.
cvWaitKey(20)
It is waiting for 20 ms, so why not with sleep (20? Why is sleep gray and the image cannot be seen ....
Hey, I checked to find out if I can't underestimate the cvwaitkey ··
Cvwaitkey http://blog.csdn.net/zm_nong/article/details/7519238
;