Friday, November 03, 2017

compiling QHYCCD camera SDK sample application with OpenCV

Steps needed to cleanly compile the LiveFrameSample code from QHY camera SDK, once OpenCV is installed -

Tested the opencv installation, compiling and running webcam capture test code from http://henryhermawan.blogspot.in/2007/09/capturing-frames-from-usb-camera-using.html

Followed the INSTALL file and compiled + installed the QHYCCD SDK.

cmake -DCMAKE_INSTALL_PREFIX=/usr .
make
sudo make install

Tried the sample without modifications -
cd sample
mkdir build
cd build
cmake ..
make

LiveFrameSampletest, SingleFrameSampletest and ControlCFWtest compiled without errors, but for CaptureDarkFrametest errors were reported, like
CaptureDarkFrame.cpp:76:83: error: invalid conversion from ‘int*’ to ‘uint32_t* {aka unsigned int*}’ [-fpermissive]
         ret = GetQHYCCDChipInfo(camhandle,&chipw,&chiph,&w,&h,&pixelw,&pixelh,&bpp);

and so on.

Anyway, I was only interested in the frame capture tests, so I created LiveFrameSampleOCV.cpp from LiveFrameSample.cpp and made the following changes -

  1. Uncommented the #define for opencv support and made that line
    #define OPENCV_SUPPORT 1
  2. Changed the set resolution line to
    ret = SetQHYCCDResolution(camhandle,320,240, 320, 240);
    (first two arguments after camhandle are dimensions, next two are position)
  3. Defined an int key before the display loop, and changed the display loop to an infinite loop -
    //ret = QHYCCD_ERROR;
    //while(ret != QHYCCD_SUCCESS)
    while(1)
  4. Added a break on escape key,
    key=cvWaitKey(30);
    if (key == 27)
    break;
  5. Modified the CMakeLists.txt to uncomment
    find_package(OpenCV REQUIRED) and
    include_directories($(OpenCV_INCLUDE_DIR))

    and also changed the link libraries line to
    target_link_libraries(${FILENAME1} -lqhy ${LIBUSB_1_LIBRARIES} ${OpenCV_LIBS}
    where the OpenCV_LIBS have been added. 
  6. Ran cmake .. from the build directory again, and then
    make LiveFrameSampleOCVtest
So now ./LiveFrameSampleOCVtest shows a live display of the camera at 320x240 resolution, around 20-24 fps. 

While running cmake, it shows
 -- Found libusb-1.0:
--  - Includes: /usr/include/libusb-1.0
--  - Libraries: /usr/lib/x86_64-linux-gnu/libusb-1.0.so

But could not build LiveFrameSample without using cmake - the gcc command needs some more work - this does not work -

gcc -Wall LiveFrameSampleOCV.cpp -o LiveFrameSampleOCV -l/usr/lib/x86_64-linux-gnu/ `pkg-config --cflags --libs opencv usb-1.0`



No comments:

Post a Comment