1

I'm trying to show LiveView image in real time. I use EDSDK 2.14 + Qt5 + opencv+mingw32 under Windows. I'm not very sophisticated in image processing so now I have the following problem. I use example from Canon EDSDK and all was ok until this part of code:

// // Display image //

I googled a lot of examples but all of them was written on C# or MFC or VB. Also I found advise to use libjpegTurbo for decompressing image and then showing it using opencv. I tried to use libjpegTurbo but failed to undestand what to do :(. Maybe somebody here have code example of the conversion LiveView stream to opencv Mat or QImage (because I use Qt)?

Hermann
  • 247
  • 2
  • 18

4 Answers4

4

Here is what worked for me after following the SAMPLE 10 from the Canon EDSDK Reference. It's a starting point for a more robust solution.

In the downloadEvfData function, I replaced the "Display Image" part by the code bellow:

unsigned char *data = NULL;
EdsUInt32 size = 0;
EdsSize coords ;

// get image coordinates
EdsGetPropertyData(evfImage, kEdsPropsID_Evf_CoordinateSystem, 0, sizeof(coords), &coords);

// get buffer pointer and size
EdsGetPointer(stream, (EdsVoid**)&data);
EdsGetLenth(stream, &size);

//
// release stream and evfImage
//

// create mat object
Mat img(coords.height, coords.width, CV_8U, data);
image = imdecode(img, CV_LOAD_IMAGE_COLOR);

I've also changed the function signature:

EdsError downloadEvfData(EdsCameraRef camera, Mat& image)

And in the main function:

Mat image;
namedWindow("main", WINDOW_NORMAL);
startLiveView(camera);
for(;;) {
    dowloadEvfData(camera, image);
    imshow("main", image);
    if (waitkey(10) >= 0);
        break;
}
William Dias
  • 339
  • 2
  • 6
2

Based on the Canon EDSDKs example, you may append your EdsStreamRef 'stream' data with its correct length into a QByteArray. Then, use for example the following to parse the raw data from the QByteArray as a JPG into a new QImage: QImage my_image = QImage::fromData(limagedata,"JPG"); Once it's in a QImage you can convert it into a OpenCV cv::Mat (see How to convert QImage to opencv Mat)

Community
  • 1
  • 1
gdh
  • 498
  • 3
  • 14
0

Well it depends on the format of the liveview-stream.

There must be some kind of delimiter in it and you need then to convert each image and update your QImage with it.

Check out this tutorial for more information: Canon EDSDK Tutorial in C#

gismo141
  • 884
  • 7
  • 11
0
QImage img = QImage::fromData(data, length, "JPG");

m_image = QImageToMat(img);

// -----------------------------------------
cv::Mat MainWindow::QImageToMat(QImage& src)
{
     cv::Mat tmp(src.height(),src.width(),CV_8UC4,(uchar*)src.bits(),src.bytesPerLine());
     cv::Mat result = tmp.clone(); 
     return result;
}


// -------------------------
void MainWindow::ShowVideo()
{
    namedWindow("yunhu",WINDOW_NORMAL);
    while(1)
    {
        requestLiveViewImage();
        if(m_image.data != NULL)
        {
            imshow("yunhu", m_image);
            cvWaitKey(50);  
        }
    }
}
hpjc
  • 1