python OpenCV – add alpha channel to RGB image

With opencv3, this should work: Python # First create the image with alpha channel rgba = cv2.cvtColor(rgb_data, cv2.COLOR_RGB2RGBA) # Then assign the mask to the last channel of the image rgba[:, :, 3] = alpha_data C++ # First create the image with alpha channel cv::cvtColor(rgb_data, rgba , cv::COLOR_RGB2RGBA); # Split the image for access to … Read more

Compiling a static executable with CMake

As global CMake settings, add these lines before add_executable, valid for gcc/clang: set(CMAKE_FIND_LIBRARY_SUFFIXES “.a”) set(BUILD_SHARED_LIBS OFF) set(CMAKE_EXE_LINKER_FLAGS “-static”) On Modern CMake (3.x+ – target_link_libraries doc), you can apply the flag to specific targets, in this way: target_link_libraries(your_target_name -static) If you’re using MSVC, you have to set the compiler and linker flags: set(CMAKE_FIND_LIBRARY_SUFFIXES “.lib”) target_compile_options(your_target_name [PUBLIC|PRIVATE] … Read more

sift = cv2.xfeatures2d.SIFT_create() not working even though have contrib installed

I had the same problem. It seems that SIRF and SURF are no longer available in opencv > 3.4.2.16. I chose an older opencv-python and opencv-contrib-python versions and solved this problem. Here is the history version about opencv-python, and I use the following code : pip install opencv-python==3.4.2.16 pip install opencv-contrib-python==3.4.2.16 Edit For Anaconda User … Read more

Can’t use SURF, SIFT in OpenCV

There is a pip source that makes this very easy. If you have another version of opencv-python installed use this command to remove it to avoid conflicts: pip uninstall opencv-python Then install the contrib version with this: pip install opencv-contrib-python SIFT usage: import cv2 sift = cv2.xfeatures2d.SIFT_create()

Access IP Camera in Python OpenCV

An IP camera can be accessed in opencv by providing the streaming URL of the camera in the constructor of cv2.VideoCapture. Usually, RTSP or HTTP protocol is used by the camera to stream video. An example of IP camera streaming URL is as follows: rtsp://192.168.1.64/1 It can be opened with OpenCV like this: capture = … Read more