Monday, 15 February 2010

c - Reading CVPoint from File -



c - Reading CVPoint from File -

i interested in reading points of type cvpoint* file, have tried standard notation (x,y). gives wrong values when seek verify output. format reading cvpoint in file.

point.txt

(1,1)

main.cpp

points = (cvpoint*)malloc(length*sizeof(cvpoint*)); points1 = (cvpoint*)malloc(length*sizeof(cvpoint*)); points2 = (cvpoint*)malloc(length*sizeof(cvpoint*)); fp = fopen(points.txt, "r"); fscanf(fp, "%d", &(length)); printf("%d \n", length); = 1; while(i <= length) { fscanf(fp, "%d", &(points[i].x)); fscanf(fp, "%d", &(points[i].y)); printf("%d %d \n",points[i].x, points[i].y); i++; }

it prints:

1 12 0

here different approach using same format text file:

#include <iostream> #include <fstream> #include <opencv2/core/core.hpp> using namespace std; using namespace cv; int main(int argc, char* argv[]) { ifstream file("points.txt"); string line; size_t start, end; point2f point; while (getline(file, line)) { start = line.find_first_of("("); end = line.find_first_of(","); point.x = atoi(line.substr(start + 1, end).c_str()); start = end; end = line.find_first_of(")"); point.y = atoi(line.substr(start + 1, end - 1).c_str()); cout << "x, y: " << point.x << ", " << point.y << endl; } homecoming 0; }

c opencv

No comments:

Post a Comment