Question

I've program, in which I calcul the mean value of multiples frames, when I save this mean value wich is a frame I got a 965KB file, but I do the same thing with SCILAB which based on OpenCV I get a 5.93MB which sound more logical. anyway I decid to write my frame using fwrite and here what did:

 cv::Mat meanFrame= cv::Mat::zeros(height,width,CV_32FC3);
cv::Mat frameR;
FILE* inpR = NULL;
...... //after calculating the meanFrame
inpR = fopen("d:\\red.txt","wb+");
for(int row = 0; row < meanFrame.rows; ++row) {
    for (int col = 0; col < meanFrame.cols; ++col) {
        std::cout << meanFrame.at<cv::Vec3f>(row, col)[1] <<std::endl;
        std::cout << meanFrame.at<cv::Vec3f>(row, col)[2] <<std::endl;
        fwrite(&resultframe.at<cv::Vec3f>(row,col )[0],sizeof(float),1,inpR);
    }
}
fcloseall();

I can see the pf channel 1 and 2 but when I opencv the file red.txt I get :

  €€<€€<€€<€€<€€<€€<€€<€€<€€<€€<€€<€€<€€.......

any idea what I'm missing here, after that I want to load those file in SCILAB and than save the frame as file. thanks for your help!

Was it helpful?

Solution

You are writing the binary data - how a float is stored in memory.

When you view the file (in the editor or on the commandline) it thinks this is text data and is trying to interpret it as characters.

If you need to read this values into another program then you can use fwrite and fread (although you might have an issue with byte ordering if you have different CPUs)

If you just want to see the results, or want slightly more work to read them into another program, you can just print the values with

printf("%f", resultframe.at<cv::Vec3f>(row,col )[0]);
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top