Sunday, March 04, 2018

cross platform issues

In order to get the OpenCV code using the QHY camera SDK - originally written on Linux - running on Windows by compiling it with Visual Studio, the following items had to be done.

  1. Install the latest Visual Studio Community edition (v. 15, Visual Studio 2017). OpenCV's latest binaries only work with v14 and v15, and if we use some other version of VS, we would have to recompile opencv, which would be a pain.
  2. Install the latest QHY SDK from http://www.qhyccd.com/SWHIST_SDK.html - the latest version of the SDK has the lib files, h files and so on in addition to the dll binaries. Currently the latest version is at the bottom of the page!
  3. Install the latest version of OpenCV for Windows from sourceforge, following the instructions at https://docs.opencv.org/2.4/doc/tutorials/introduction/windows_install/windows_install.html
  4. The instructions on how to build an opencv application, https://docs.opencv.org/2.4/doc/tutorials/introduction/windows_visual_studio_Opencv/windows_visual_studio_Opencv.html#windows-visual-studio-how-to
    is reasonably similar to what we need to do, except for the fact that it would be better if we create a new property sheet called common and save it for future use as mentioned in the next point below - VS15 does not recommend .user property sheets.
  5. In a newly created property sheet (called common, for reuse), add the additional include directories, linker files etc as mentioned in the documentation on point 4 above. Here, we need to add the QHY SDK includes and dlls also. The opencv libraries are now distributed as a single file, opencv_world.lib and not the multiple lib files as in the documentation above. So, in short,
    VC++ directories -> Include
    Linker General -> Additional Library directories
    Linker Input -> names of the lib files in Additional Dependencies 
  6. The .cpp files need to have ifdefs for linux and windows standard headers separately. Code can be seen at https://github.com/hn-88/ASKlive/blob/master/ASKlive.cpp
  7. For the C function sprintf to work, the following pre-processor directive has to be added - C++ -> Preprocessor - > Preprocessor definitions -> add _CRT_SECURE_NO_WARNINGS
  8. In order to copy over the required DLLs, the following post build event has to be added -
    xcopy /y /d "D:\qhy\*.dll" "$(OutDir)"
    xcopy /y /d "$(OPENCV_DIR)\bin\*.dll" "$(OutDir)"

    It is safer to copy to the executable's directory, since there is quite a bit of confusion about copying to system folders - http://www.forceflow.be/2012/04/04/the-3264-bit-dll-confusion-on-windows-64-bit/
  9. Arrays have to be pre-assigned sizes - can't be assigned sizes at runtime as with GNU C compiler. 
Edit 3 June 2018 - 10. Added this line of code to prevent the "exe has stopped working" Windows dialog box on exit - 
SetErrorMode(SEM_FAILCRITICALERRORS | SEM_NOGPFAULTERRORBOX);
via stackoverflow, with additional documentation at msdn

No comments:

Post a Comment