Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

socketdata to im

Hi

I've implemented a client server app which receives an image on the c++ server. The data is fetched and has to be saved as an image but the problem the server keeps on throwing segmentation fault 11.

uint32_t len; int lengthbytes = 0; lengthbytes = recv(newsockfd, (char *)&len, sizeof(len), 0); printf("%d",len); int bytes=0; uchar sockData[len]; for (int i = 0; i < len; i += bytes) { if ((bytes = recv(newsockfd, sockData +i, len - i, 0)) == -1) { error("recv failed"); }

}
Mat img(690,250,CV_8UC3,sockData);
imwrite("/Users/koushikv/Desktop/openCVSampleProject/datasent.png", img);

I think the main problem occurs in the Mat img (690,250,CV_8uC3,sockData) since i've given an arbitary rows, cols and type CV_8uc3. I don't know how to create a image from the socketdata without these parameters .Can someone please help me with this issue? To be clear, i need to convert the uchar socketdata to mat and save the image.

Thank you

socketdata to imimage

Hi

I've implemented a client server app which receives an image on the c++ server. The data is fetched and has to be saved as an image but the problem the server keeps on throwing segmentation fault 11.

uint32_t len; int lengthbytes = 0; lengthbytes = recv(newsockfd, (char *)&len, sizeof(len), 0); printf("%d",len); int bytes=0; uchar sockData[len]; for (int i = 0; i < len; i += bytes) { if ((bytes = recv(newsockfd, sockData +i, len - i, 0)) == -1) { error("recv failed"); }

}
Mat img(690,250,CV_8UC3,sockData);
imwrite("/Users/koushikv/Desktop/openCVSampleProject/datasent.png", img);

I think the main problem occurs in the Mat img (690,250,CV_8uC3,sockData) since i've given an arbitary rows, cols and type CV_8uc3. I don't know how to create a image from the socketdata without these parameters .Can someone please help me with this issue? To be clear, i need to convert the uchar socketdata to mat and save the image.

Thank you

socketdata to image

Hi

I've implemented a client server app which receives an image on the c++ server. The data is fetched and has to be saved as an image but the problem the server keeps on throwing segmentation fault 11.

uint32_t len;
 int lengthbytes = 0;
 lengthbytes = recv(newsockfd, (char *)&len, sizeof(len), 0);
 printf("%d",len);
 int bytes=0;
 uchar sockData[len];
 for (int i = 0; i < len; i += bytes)
 {
  if ((bytes = recv(newsockfd, sockData +i, len - i, 0)) == -1)
 {
  error("recv failed");
 }

}
}
Mat img(690,250,CV_8UC3,sockData);
imwrite("/Users/koushikv/Desktop/openCVSampleProject/datasent.png", img);

I think the main problem occurs in the Mat img (690,250,CV_8uC3,sockData) since i've given an arbitary rows, cols and type CV_8uc3. I don't know how to create a image from the socketdata without these parameters .Can someone please help me with this issue? To be clear, i need to convert the uchar socketdata to mat and save the image.

Thank you