Display Qbytearray as Image in QT 5.12.9 version

164 views Asked by At

I am reading the QByteArray using QTcpSocket and converting the array into the cvMat image. to display the image using imshow().but i am getting gray image. code is as follows.

//array ->QBytearray (received from socket) 
cv::Mat img,img1;
    img.cols=320;
    img.rows=240;
img = cv::Mat(240,320, CV_8UC1,array.data());
cv::cvtColor(img, img, CV_GRAY2RGB);  // 
      cv::imshow("image display",img);
      cv::waitKey(5000);

after cvtColour() function also its not converting into colour image.

Thanks in advance.

1

There are 1 answers

2
Hihikomori On

This is the way to modify channels separately:

img = cv::Mat(240,320, CV_8UC1,array.data());
cv::Mat img1;
cv::divide(img,cv::Scalar(2),img1);
std::vector<cv::Mat> channels;
   
channels.push_back(img);
channels.push_back(img1);
channels.push_back(img);
cv::merge(channels, img);

cv::imshow("image display",img);
cv::waitKey(5000);