Panel użytkownika
Nazwa użytkownika:
Hasło:
Nie masz jeszcze konta?

[C++, OpenCV] Wczytanie std::string do klasy cv::Mat

Ostatnio zmodyfikowano 2013-12-23 00:40
Autor Wiadomość
roserek
Temat założony przez niniejszego użytkownika
[C++, OpenCV] Wczytanie std::string do klasy cv::Mat
» 2013-12-13 15:12:54
Witam. Mam histogram w stringu i chcę go przekazać do zmiennej Mat. Jak to można zrobić ??
P-99100
MrPoxipol
» 2013-12-17 19:22:48
P-99485
DejaVu
» 2013-12-23 00:40:04
Podsumowując, z powyższego linka chodzi o posta:
OpenCV Mat has a constructor from vector<byte>, but this is not so intuitive. You need to convert from string to vector this way first:[
C/C++
std::vector < byte > vectordata( data.begin(), data.end() );
Then you can create a cv::Mat from the vector:

C/C++
cv::Mat data_mat( vectordata, true );
You also need to decode the image (check documentation for which types are allowed, png, jpg, depending on the OpenCV version)

C/C++
cv::Mat image( cv::imdecode( data_mat, 1 ) ); //put 0 if you want greyscale
Now you can check if the resulting size of the image is the same as the one you sent:
C/C++
cout << "Height: " << image.rows << " Width: " << image.cols << endl;
P-99893
« 1 »
  Strona 1 z 1