This is part of my program:
// let's get jpg image from socket
int iRcvdBytes=recvfrom(iSockFd, buff, bufferSize, 0,
(struct sockaddr*)&cliAddr, (socklen_t*)&cliAddrLen);
// buff now contains 30KB jpg image
// let's load the jpg image to IplImage
IplImage* fIplImageHeader;
fIplImageHeader = cvCreateImageHeader(cvSize(640, 480), 8, 1);
fIplImageHeader->imageData = (char *)buff;
// now let's check the size difference
cout << "Received " << iRcvdBytes << " bytes from the client" << endl;
cout << fIplImageHeader->imageSize << endl;
And the output is:
Received 31860 bytes from the client
307200
Now why is that? Is cvCreateImageHeader() converting the jpg image to RGB or something like that internally? I want it to stay JPG and show it with cvShowImage().
Please, any help would be welcome.
You are comparing the lenght of the compressed jpeg image data to the uncompressed pixel data.
In particular, given:
It will always be the case that
fIplImageHeader->imageSize==width * height * (depth/8) * channelsAssigning the bytes recieved by the
recvfrom()call to theimageDataarea doesn’t work in the first place.