Ask Your Question
0

I have problem with changing array data to matrix.

asked 2016-06-29 17:50:43 -0600

davidkim gravatar image

I have a problem with changing array to matrix because array data type is not proper...

could you help me?

#include <iostream>  // for cout, getline
#include <sstream>  // for istringstream
#include <string>   // for string
#include <opencv2\highgui\highgui.hpp>
#include <fstream>
#include <stdio.h>

using namespace std; using namespace cv;

int main() { std::ifstream file("cell2.txt"); // assume the file opens correctly

double matrix[256][256];

int row = 0, col = 0;
Mat abs_val;
Mat dst(256, 256, CV_32F);

//double dst[256][256];

std::string line;


while (std::getline(file, line)) {  // read each line from the file

    std::istringstream stream(line);

    double x;
    col = 0;  // reset column counter
    while (stream >> x) {  // keep trying to read ints until there are no more
        matrix[row][col] = x;
        col++;
        }

    row++;
}

Mat matrix1(Size(256, 256), CV_32F, matrix);// = Mat(256, 256, CV_32FC1, matrix);
cout << matrix1 << endl;

system("pause >nul");
return 0;

}

in here when I change the array to the matrix, message data is not read properly...

0.0448286 0.0437008 0.0430881 0.0448606 0.0383793 0.044633 0.0411747 0.0460828 0.0449244 0.042626 0.0447564 0.0404438 0.0397293 0.0428335 0.0440014 0.0427125 0.039638 0.0450739 0.0387029 0.0405195

data type is like this.

Could you tell me problem or change type instead CV_32F?

edit retag flag offensive close merge delete

Comments

hi, due to a lot of spam lately, this site has to go moderated. patience required, and please don't post duplicates ;)

berak gravatar imageberak ( 2016-06-29 20:47:02 -0600 )edit

1 answer

Sort by ยป oldest newest most voted
0

answered 2016-06-29 21:04:01 -0600

berak gravatar image

updated 2016-06-29 21:06:47 -0600

your matrix is of doubletype, thus your Matneeds to be CV_64F, not CV_32F (which would be 'float')

also, be very careful when constructing a Mat like this, see here

edit flag offensive delete link more

Question Tools

1 follower

Stats

Asked: 2016-06-29 17:50:43 -0600

Seen: 98 times

Last updated: Jun 29 '16