Ask Your Question
0

Load a text file(pixel values) / Opencv / C++

asked 2014-06-07 06:52:04 -0600

ati gravatar image

updated 2014-06-07 06:57:10 -0600

berak gravatar image

what is opencv equivalent of mat2gray using in Matlab?

I have a text file contains pixel values of an Image. I want to import it to the code and then normalize it...

How do I load it?

Thanks in advance..

edit retag flag offensive close merge delete

1 answer

Sort by ยป oldest newest most voted
4

answered 2014-06-11 03:12:58 -0600

If it's an image:

cv::Mat myMat, myMatGrayScale;
cv::imread( "mypicture.jpg/png/tiff/...", myMat );
cv::cvtColor( myMat, myMatGrayScale, cv::COLOR_BGR2GRAY );

If it's a text file: load it into a char buffer, create a Mat with that buffer:

char* buffer;
// Allocate buffer, read pixel values from the text file (suppose grayscale)
cv::Mat myMat( NbRows, NbCols, CV_8UC1, buffer );
edit flag offensive delete link more

Question Tools

Stats

Asked: 2014-06-07 06:52:04 -0600

Seen: 1,437 times

Last updated: Jun 11 '14