Ask Your Question
0

Output tracked variables into a Text File

asked 2016-01-27 18:14:29 -0500

Hello! I'm new to this whole software so if my question has been asked before or has a super obvious answer I'm sorry.

I'm using the Open Source Tracking software to track the movement of a zebrafish for my senior project in college, but my one issue is that I cannot figure out how to output my tracked variables into a text file. I've seen the video that open source tracking put up that shows how to accomplish this but I'm not getting a text file.

Some help would be great!

Thank you!

edit retag flag offensive close merge delete

1 answer

Sort by ยป oldest newest most voted
1

answered 2016-01-28 08:51:38 -0500

updated 2016-01-28 09:06:27 -0500

you could use std::ofstream for saving variables into text file ( needs #include <fstream> )

take a look at the test code below

#include <opencv2/highgui.hpp>
#include <opencv2/imgproc.hpp>
#include <fstream>

int main( int argc, const char** argv )
{
    // Create the outputfilestream
    std::ofstream output("output_test.txt");

    cv::String s = "OpenCV is a great library for creating Computer Vision software";
    cv::Rect r(10,30,20,20);
    int i = 123;
    float f = (float) 3 / 7;
    cv::Mat m( 5,5,CV_8UC3,cv::Scalar( 0,255,0));

    output << s << std::endl;
    output << r << std::endl;
    output << i << std::endl;
    output << f << std::endl;
    output << m << std::endl;
    output << "this is a Rect : " << r << std::endl;
    output.close(); 
    return 0;
}

result : output_test.txt

OpenCV is a great library for creating Computer Vision software
[20 x 20 from (10, 30)]
123
0.428571
[0, 255, 0, 0, 255, 0, 0, 255, 0, 0, 255, 0, 0, 255, 0;
  0, 255, 0, 0, 255, 0, 0, 255, 0, 0, 255, 0, 0, 255, 0;
  0, 255, 0, 0, 255, 0, 0, 255, 0, 0, 255, 0, 0, 255, 0;
  0, 255, 0, 0, 255, 0, 0, 255, 0, 0, 255, 0, 0, 255, 0;
  0, 255, 0, 0, 255, 0, 0, 255, 0, 0, 255, 0, 0, 255, 0]
this is a Rect :[20 x 20 from (10, 30)]

note : You can store and then restore various OpenCV data structures to/from XML or YAML formats see documentation

edit flag offensive delete link more
Login/Signup to Answer

Question Tools

1 follower

Stats

Asked: 2016-01-27 18:14:29 -0500

Seen: 1,182 times

Last updated: Jan 28 '16