title: Canon EDSDK How can I get width and height of live view images?
body: <p>I written C++ code to display live view image on monitor. I referred to some code on stackoverflow. Finally, I complete my code, but there are some problem. </p>
  
  <p>I want display live view image using opencv, but I don't know to get the width &amp; height of live view image. (maybe it is retrieved by EDSDK function..)</p>
  
  <p>please answer for me.</p>
  
  <p>(I attached my code, I want suitable answer for my code)</p>
  
  <p>(look at "//libjpegTurbo...//, there are manual _width &amp; height. I want to retrieve using function)</p>
  
  <hr>
  
  <pre><code>// Functions_body
  bool LiveViewStart() 
  {
      EdsError err = EDS_ERR_OK;
      EdsCameraListRef cameraList = NULL;
      EdsCameraRef camera = NULL;
      EdsUInt32    count = 0; 
      bool         isSDKLoaded = false;
  
      // Initialize SDK
      err = EdsInitializeSDK(); 
  
      if(err == EDS_ERR_OK) 
      { 
          isSDKLoaded = true; 
      }
  
      // Acquisition of camera list
      if(err == EDS_ERR_OK)
      {
          err = EdsGetCameraList(&amp;cameraList);
      }
  
      // Acquisition of number of Cameras
      if(err == EDS_ERR_OK)
      {
          err = EdsGetChildCount(cameraList, &amp;count);
          if(count == 0)
          {
              err = EDS_ERR_DEVICE_NOT_FOUND;
          }
      }
  
      // Acquisition of camera at the head of the list
      if(err == EDS_ERR_OK)
      {   
          err = EdsGetChildAtIndex(cameraList , 0 , &amp;camera); 
      }
  
      // Acquisition of camera information
      EdsDeviceInfo deviceInfo;
      if(err == EDS_ERR_OK)
      {   
          err = EdsGetDeviceInfo(camera , &amp;deviceInfo);   
          if(err == EDS_ERR_OK &amp;&amp; camera == NULL)
          {
              err = EDS_ERR_DEVICE_NOT_FOUND;
          }
      }
  
      // Release camera list
      if(cameraList != NULL)
      {
          EdsRelease(cameraList);
      }
  
      if(err != EDS_ERR_OK)
      {
          ::MessageBox(NULL,"Cannot detect camera",NULL,MB_OK);
          exit(1);
      }
  
      // Open session with camera 
      if(err == EDS_ERR_OK) 
      { 
          err = EdsOpenSession(camera); 
      } 
  
      // Start Live view  
      // Get the output device for the live view image
      EdsUInt32 device;
      err = EdsGetPropertyData(camera, kEdsPropID_Evf_OutputDevice, 0, sizeof(device), &amp;device);
  
      // PC live view starts by setting the PC as the output device for the live view image. 
      if(err == EDS_ERR_OK) 
      { 
          device |= kEdsEvfOutputDevice_PC; 
          err = EdsSetPropertyData(camera, kEdsPropID_Evf_OutputDevice, 0 , sizeof(device), &amp;device);
      } 
  
      Sleep(2000);
  
      // Download EvfData
      EdsEvfImageRef evfImage = NULL;
      EdsStreamRef stream = NULL;
      unsigned char* data = NULL;
      unsigned long size = 0;
  
      // Create memory stream
      err = EdsCreateMemoryStream(0, &amp;stream);
  
      if (err != EDS_ERR_OK) {
          cout &lt;&lt; "Download Live View Image Error in Function EdsCreateMemoryStream: " &lt;&lt; err &lt;&lt; "\n";
          return false;
      }
  
      // Create EvfImageRef.
      err = EdsCreateEvfImageRef(stream, &amp;evfImage);
  
      if (err != EDS_ERR_OK) {
          cout &lt;&lt; "Download Live View Image Error in Function EdsCreateEvfImageRef: " &lt;&lt; err &lt;&lt; "\n";
          return false;
  
      }
  
      // Download live view image data.
      err = EdsDownloadEvfImage(camera, evfImage);
  
      if (err != EDS_ERR_OK) {
          cout &lt;&lt; "Download Live View Image Error in Function EdsDownloadEvfImage: " &lt;&lt; err &lt;&lt; "\n";
          return false;
      }
  
      //Sleep(1000);
  
      // Get Pointer of evfStream
      err = EdsGetPointer(stream, (EdsVoid**)&amp; data);
  
      if (err != EDS_ERR_OK) {
          cout &lt;&lt; "Download Live View Image Error in Function EdsGetPointer: " &lt;&lt; err &lt;&lt; "\n";
          return false;
      }
  
      // Get Length of evfStream
      err = EdsGetLength(stream, &amp;size);
  
      if (err != EDS_ERR_OK) {
          cout &lt;&lt; "Download Live View Image Error in Function EdsGetLength: " &lt;&lt; err &lt;&lt; "\n";
          return false;
      }
  
  
  
      // libjpegTurbo(data, size);
      int JPEG_QUALITY = 75;
      int COLOR_COMPONENTS = 3;
      int _width = 1920;
      int _height = 1080;
      long unsigned int _jpegSize = 0;
      unsigned char *_compressedImage = NULL;
      unsigned char *buffer = new unsigned char [_width * _height * COLOR_COMPONENTS];
  
      tjhandle _jpegCompressor = tjInitCompress();
  
      tjCompress2(_jpegCompressor, buffer, _width, 0, _height, TJPF_RGB, &amp;_compressedImage, &amp;_jpegSize, TJSAMP_444, JPEG_QUALITY, TJFLAG_FASTDCT);
  
      tjDestroy(_jpegCompressor);
  
      // display RGB image in opencv
  
      // Release stream
      if (stream != NULL) {
          EdsRelease(stream);
          stream = NULL;
      }
  
      // Release evfImage
      if (evfImage != NULL) {            
          EdsRelease(evfImage);
          evfImage = NULL;
      }
  
      data = NULL;
  
      // End Live view.
      // Get the output device for the live view image
      err = EdsGetPropertyData(camera, kEdsPropID_Evf_OutputDevice, 0, sizeof(device), &amp;device);
  
      // PC live view ends if the PC is disconneccted from the live view output device.
      if(err == EDS_ERR_OK)
      {
          device &amp;= ~kEdsEvfOutputDevice_PC;
          err = EdsSetPropertyData(camera, kEdsPropID_Evf_OutputDevice, 0, sizeof(device), &amp;device);
      }
  
      // Close session with camera 
      if(err == EDS_ERR_OK) 
      {
          err = EdsCloseSession(camera); 
      } 
  
      // Release camera 
      if(camera != NULL) 
      { 
          EdsRelease(camera); 
      } 
      // Terminate SDK 
      if(isSDKLoaded) 
      { 
          EdsTerminateSDK(); 
      } 
      return true;
  } 
  </code></pre>