开发者

Writing point coordinate to txt file in C

开发者 https://www.devze.com 2023-03-26 17:09 出处:网络
I have a set of eye coordinates and I want to save them into a text file in C (For OpenCV) like this:

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)

0

精彩评论

暂无评论...
验证码 换一张
取 消