他们没有告诉您两个功能:
1)EdsGetPointer
2)EdsGetLength
这将为您分别提供指向 JPEG 流的开头和大小的指针。
一旦你有这个用途LibJPEG Turbo
来解压,Libjpeg
就是不够快。
解压缩后,您可以使用opencv
.
bool CanonCamera::downloadLiveViewImage()
{
EdsError err = EDS_ERR_OK;
EdsEvfImageRef image = NULL;
EdsStreamRef stream = NULL;
unsigned char* data = NULL;
unsigned long size = 0;
err = EdsCreateMemoryStream(0, &stream);
if (err != EDS_ERR_OK) {
cout << "Download Live View Image Error in Function EdsCreateMemoryStream: " << err << "\n";
return false;
}
err = EdsCreateEvfImageRef(stream, &image);
if (err != EDS_ERR_OK) {
cout << "Download Live View Image Error in Function EdsCreateEvfImageRef: " << err << "\n";
return false;
}
err = EdsDownloadEvfImage(cameraRef, image);
if (err != EDS_ERR_OK) {
cout << "Download Live View Image Error in Function EdsDownloadEvfImage: " << err << "\n";
return false;
}
err = EdsGetPointer(stream, (EdsVoid**)& data);
if (err != EDS_ERR_OK) {
cout << "Download Live View Image Error in Function EdsGetPointer: " << err << "\n";
return false;
}
err = EdsGetLength(stream, &size);
if (err != EDS_ERR_OK) {
cout << "Download Live View Image Error in Function EdsGetLength: " << err << "\n";
return false;
}
// libjpegTurbo(data, size);
// display RGB image in opencv
if (stream != NULL) {
EdsRelease(stream);
stream = NULL;
}
if (image != NULL) {
EdsRelease(image);
image = NULL;
}
data = NULL;
return true;
}