Writing point coordinate to txt file in C
I have a set of eye coordinates and I want to save them into a text file in C (For OpenCV) like this:
开发者_运维技巧254 234 344 434 this is first set, including left and right eye co-ordinate 455 345 344 345 next one and so on..
Use fprintf and a loop. Something like
file = fopen("myfile.txt", "w");
for (i = 0; i < num_coords; ++i)
{
fprintf(file, "%d %d %d %d\n", coords[i].left_x, coords[i].left_y, coords[i].right_x, coords[i].right_y);
}
fclose(file);
Details will vary depending on exactly how you have the data, of course.
Try:
man fopen
and
man fprintf
OpenCV has own interface (both C and C++ versions) for writing files in xml/yaml formats: XML/YAML Persistence (C API)
精彩评论