cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Canon EDSDK decoding Evf Memory Stream data C++ (not working) vs Python (working)

adibabu
Apprentice

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. Please note, the actual code I'm compiling has error checking, and I've checked every return value in practice, and there are no explicit error codes which could be handled to resolve this problem. I simply did not include the error checks here because when I posted this before, it was very apparent that their presence (and occasional irrelevant ommision) was distracting anyone who might care to look from the actual, substantive differences in following code segments:

dsStreamRef evfStream;
EdsEvfImageRef evfImage;
uchar * image_data;
QImage qimg;
EdsUInt64 stream_length;
EdsUInt32 evfMode = 1;
EdsUInt32 outDev = 2;

EdsOpenSession(selected_cam);

EdsSetPropertyData(selected_cam, kEdsPropID_Evf_Mode, 0, sizeof(evfMode), &evfMode);
EdsSetPropertyData(selected_cam, kEdsPropID_Evf_OutputDevice, 0, sizeof(outDev), &outDev);

EdsCreateMemoryStream(0, &evfStream);
EdsCreateEvfImageRef(evfStream, &evfImage);

QThread::usleep(1000 * 750);

EdsGetLength(evfStream, &stream_length);
qDebug() << "length" << stream_length;

EdsDownloadEvfImage(selected_cam, evfImage);

EdsGetLength(evfStream, &stream_length);
qDebug() << "length" << stream_length;

image_data = new uchar[stream_length];
EdsGetPointer(evfStream, (EdsVoid**) image_data);
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.

Here's the Python version, which works quite nicely:

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.)

Once again, you can ignore the error checks. No function is returning anything but ERR_OK in the C++ version, and no exceptions are being raised in Python.

I'm fairly certain the problem is in my handling of the memory stream, or the data pointer, or how it's being presented to QImage.loadFromData.

1 ACCEPTED SOLUTION

Accepted Solutions

shadowsports
Legend
Legend

@adibabu Welcome to Canon.  

For development, programming and SDK questions, you should visit the Canon Developers Community.  

Canon Developer Community https://share.google/CW8A1Ji8nphOzf7eq

~Rick
Bay Area - CA


~R5 C (1.1.2.1), ~R50v (1.2.0) ~RF Trinity, ~RF 100 Macro, ~RF 100~400, ~RF 100~500, ~RF 200-800 +RF 1.4x TC, BG-R10, 430EX III-RT ~DxO PhotoLab Elite ~DaVinci Resolve Studio ~ImageClass MF644Cdw/MF656Cdw ~Pixel 10 ~CarePaks Are Worth It

View solution in original post

1 REPLY 1

shadowsports
Legend
Legend

@adibabu Welcome to Canon.  

For development, programming and SDK questions, you should visit the Canon Developers Community.  

Canon Developer Community https://share.google/CW8A1Ji8nphOzf7eq

~Rick
Bay Area - CA


~R5 C (1.1.2.1), ~R50v (1.2.0) ~RF Trinity, ~RF 100 Macro, ~RF 100~400, ~RF 100~500, ~RF 200-800 +RF 1.4x TC, BG-R10, 430EX III-RT ~DxO PhotoLab Elite ~DaVinci Resolve Studio ~ImageClass MF644Cdw/MF656Cdw ~Pixel 10 ~CarePaks Are Worth It

EOS R6 V RF20-50mm F4 L IS USM PZ Lens Kit
Announcements