title: uEye Camera and OpenCV Memory Access
body: <p>I am using a 35MM EO Megapixel Fixed FL Lens Edmund Optics camera, OpenCV 2.4.6, and Ubuntu 12.04 LTS as my development environment.  I am also using C to develop, not C++. The camera has an API that I am following, and I believe I have set everything up correctly.  I initialize the camera, set memory locations, and freeze the video.  I then use OpenCV to get the image from memory, but my image is nothing like what it should be (may be seen below).  Is my image data pulling data from a junk memory location?  How can I access the image saved by "is_FreezeVideo" for image processing done by OpenCV?  The image that is printed out can be seen here <a href="http://i.imgur.com/kW6aqB3.png" rel="nofollow">http://i.imgur.com/kW6aqB3.png</a></p>
  
  <p>The code I am using is below. </p>
  
  <pre><code>#include "../Include/Camera.h"
  #include &lt;wchar.h&gt;
  #include &lt;locale.h&gt;
  #include &lt;stdlib.h&gt;
  #include &lt;stdio.h&gt;
  #include &lt;cv.h&gt;
  #include &lt;highgui.h&gt;
  //#include &lt;opencv2/opencv.hpp&gt;
  #include &lt;ueye.h&gt;
  
  // uEye variables
  HIDS m_hCam;                                    // handle to room
  HWND m_hWndDisplay;                             // handle to diplay window
  int m_Ret;                                      // return value of uEye  SDK functions
  int m_nColorMode = 0;                               // Y8/RGB16/RGB24/REG32
  int m_nBitsPerPixel=8;                          // number of bits needed store one pixel
  int m_nSizeX = 1280;                             // width of video
  int m_nSizeY = 1024;                             // height of video
  int m_lMemoryId;                                // grabber memory - buffer   ID
  char* m_pcImageMemory;                          // grabber memory - pointer to buffer
  int m_nRenderMode = IS_RENDER_FIT_TO_WINDOW;    //render  mode
  
  void getAzimuth(){
  
  }
  void getElevation(){
  
  }
  void initializeCamera(){
  
      if (m_hCam !=0 ) {
          //free old image mem.
          is_FreeImageMem (m_hCam, m_pcImageMemory, m_lMemoryId);
          is_ExitCamera (m_hCam);
      }
  
      // init room
      m_hCam = (HIDS) 0;    // open next room
      m_Ret = is_InitCamera (&amp;m_hCam, NULL);    // init room
  
      if (m_Ret == IS_SUCCESS) {
          // retrieve original image size
          SENSORINFO sInfo;
          is_GetSensorInfo (m_hCam, &amp;sInfo);
          m_nSizeX = sInfo.nMaxWidth;
          m_nSizeY = sInfo.nMaxHeight;
  
          printf("Width: %d Height: ", m_nSizeX, m_nSizeY);
  
          // setup the color depth to the current windows setting
          is_GetColorDepth (m_hCam, &amp;m_nBitsPerPixel, &amp;m_nColorMode);
          is_SetColorMode (m_hCam, m_nColorMode);
  
          //printf ("m_nBitsPerPixel=%i  m_nColorMode=%i \n", m_nBitsPerPixel, IS_CM_BAYER_RG8);
  
          // memory initialization
          is_AllocImageMem (m_hCam, m_nSizeX, m_nSizeY, m_nBitsPerPixel, &amp;m_pcImageMemory, &amp;m_lMemoryId);
          //set memory active
          is_SetImageMem (m_hCam, m_pcImageMemory, m_lMemoryId);
          // display initialization
          is_SetImageSize (m_hCam, m_nSizeX, m_nSizeY);
          is_SetImagePos(m_hCam, 0, 0);
          is_SetDisplayMode (m_hCam, IS_SET_DM_DIB);
      } else {
          printf("No Camera Initialized! %c", 10);
  
      }
  if (m_hCam !=0) {
      INT dummy;
      char *pMem, *pLast;
      double fps = 0.0;
  
      if (is_FreezeVideo (m_hCam, IS_WAIT) == IS_SUCCESS) {
          m_Ret = is_GetActiveImageMem(m_hCam, &amp;pLast, &amp;dummy);
          m_Ret = is_GetImageMem(m_hCam, (void**)&amp;pLast);
  
      }
  
      IplImage* tmpImg = cvCreateImageHeader (cvSize (m_nSizeX, m_nSizeY), IPL_DEPTH_8U, 1);
      tmpImg-&gt;imageData = &amp;m_pcImageMemory;
  
      cvNamedWindow("src",1);
      cvShowImage("src",tmpImg);
  
      cvWaitKey(0);
  
  }
  </code></pre>
  
  <p>}</p>
  
  <p>Thanks</p>