好的。這有點奇怪。長話短說。我從相機開始拍攝原始BGR圖像,使用OpenCV將它們壓縮爲JPG並使用UDP協議發送到PC。這是我如何壓縮圖片:JPG壓縮後的原始BGR圖像的長度是否相同?
// memblock contains raw image
IplImage* fIplImageHeader;
fIplImageHeader = cvCreateImageHeader(cvSize(160, 120), 8, 3);
fIplImageHeader->imageData = (char*) memblock;
// compress to JPG
vector<int> p;
p.push_back(CV_IMWRITE_JPEG_QUALITY);
p.push_back(75);
vector<unsigned char> buf;
cv::imencode(".jpg", fIplImageHeader, buf, p);
這是我送他們用UDP:
n_sent = sendto(sk,&*buf.begin(),(int)size,0,(struct sockaddr*) &server,sizeof(server));
這是我收到他們的PC:
int iRcvdBytes=recvfrom(iSockFd,buff,bufferSize,0,
(struct sockaddr*)&cliAddr,(socklen_t*)&cliAddrLen);
// print how many bytes we have received
cout<<"Received "<<iRcvdBytes<<" bytes from the client"<<endl;
我得到此輸出:
Received 57600 bytes from the client
Received 57600 bytes from the client
...
如果我刪除JP在程序獲取從相機圖像G壓縮,則輸出是相同的:
Received 57600 bytes from the client
Received 57600 bytes from the client
...
然而,當我保存在磁盤上所接收到的圖像,它的大小約爲7.8KB而保存到磁盤未壓縮的原始圖像約需57KB的空間。
這是怎麼回事?
哦,沒錯。大小包含原始圖像的大小。順便說一句,如何找到vector buf的大小? –
2010-11-23 10:21:46