Canon EDSDK decoding Evf Memory Stream data

8 hours ago 3
ARTICLE AD BOX

I actually have what I want working in Python with PySide and edsdk-python, however I am trying to get this working in C++ and stumbling on the decoding of the memory stream data.

Here is the relevant code from my C++ project:

EdsStreamRef evfStream; EdsEvfImageRef evfImage; uchar * image_data; QImage qimg; EdsUInt64 stream_length; err = EdsOpenSession(selected_cam); if (err == EDS_ERR_OK) { EdsUInt32 evfMode = 1; EdsUInt32 outDev = 2; err = EdsSetPropertyData(selected_cam, kEdsPropID_Evf_Mode, 0, sizeof(evfMode), &evfMode); err = EdsSetPropertyData(selected_cam, kEdsPropID_Evf_OutputDevice, 0, sizeof(outDev), &outDev); } if (err == EDS_ERR_OK) { err = EdsCreateMemoryStream(0, &evfStream); } if (err == EDS_ERR_OK) { err = EdsCreateEvfImageRef(evfStream, &evfImage); } if (err == EDS_ERR_OK) { QObject().thread()->usleep(1000*750); err = EdsGetLength(evfStream, &stream_length); qDebug() << "length" << stream_length; err = EdsDownloadEvfImage(selected_cam, evfImage); } if (err == EDS_ERR_OK) { err = EdsGetLength(evfStream, &stream_length); image_data = new uchar[stream_length]; err = EdsGetPointer(evfStream, (EdsVoid**) image_data); qDebug() << "length" << stream_length; qimg.loadFromData(image_data, stream_length, "JPG"); qDebug() << "download ok" << qimg.format(); }

So, the first print of stream_length is 0, and the second is ~280000, suggesting that the download worked. However, the decode did not, because the last debug statement prints download ok QImage::Format_Invalid.

But I'm doing almost the same thing in Python and it works fine:

qimg = QImage() edsdk.OpenSession(selected_cam) edsdk.SetPropertyData(selected_cam, PropID.Evf_Mode, 0, 1) edsdk.SetPropertyData(selected_cam, PropID.Evf_OutputDevice, 0, 2) image_data = bytes(960*640*3) mem_stream = edsdk.CreateMemoryStreamFromPointer(image_data) evfImage = edsdk.CreateEvfImageRef(mem_stream) time.sleep(.75) edsdk.DownloadEvfImage(selected_cam, image) qimg.loadFromData(image_data, "JPEG") pixmap = QPixmap.fromImage(qimg) mainWindow.imageLabel.setPixmap(pixmap)

(If I do the C++ version using CreateMemoryStreamFromPointer as in the Python version, I get a bunch of "bogus DQT" messages from loadFromData.)

Does anybody have any idea what I'm doing wrong here?

Read Entire Article