opencv / opencv-python

Automated CI toolchain to produce precompiled opencv-python, opencv-python-headless, opencv-contrib-python and opencv-contrib-python-headless packages.
https://pypi.org/project/opencv-python/
MIT License
4.44k stars 835 forks source link

New opencv-contrib-python pip package has unexpected behavior than the one I had installed previously for cv2.selectROI #1021

Closed monajalal closed 3 weeks ago

monajalal commented 3 weeks ago

Expected behaviour

After selecting an ROI, and pressing Enter key, I wanted to expand it full screen (same size as my namedWindow)

Actual behaviour

I needed to install cv2 super resolution and apparently I needed to uninstall and then install --upgrade the opencv-contrib-python package. After doing so, now when I select the ROI, it doesn't zoom it out to the size of namedWindow (in this case my sized window is full screen) and it just shows the exact amount that is selected.

Dimension of the second display where I am showing my image

display_size The old version (don't know what the version was)

after_select_roi_old

The new version of opencv-contrib-python, after roi select, it doesn't set the size of image to be displayed to be size of the named window (here RealSense) after_select_roi_new

Write here what went wrong. My assumption is the new version of opencv-contrib-python has caused it. Problem is, I didn't keep track of the working version.

Steps to reproduce

sr.readModel(path)

sr.setModel("edsr",4)

config.enable_stream(rs.stream.color, 1920, 1080, rs.format.bgr8, 30) cv2.namedWindow("RealSense", cv2.WND_PROP_FULLSCREEN) cv2.moveWindow("RealSense", second_display_x-1, second_display_y-1) #working resized window cv2.resizeWindow("RealSense", second_display_width, second_display_height) # Resize to screen dimensions cv2.setWindowProperty("RealSense", cv2.WND_PROP_FULLSCREEN, cv2.WINDOW_FULLSCREEN)#working resized window

   new = cv2.rotate(color_img, cv2.ROTATE_90_CLOCKWISE)
   if not roi_selected:
        roi = cv2.selectROI('RealSense', new)
        roi_selected = True
        print('roi is: ', roi)
        if roi != (0, 0, 0, 0):
            x, y, w, h = roi

    # sr_roi_img = sr.upsample(roi_image) # commenting super resolution post cropping since it is very slow
    cv2.imshow('RealSense', roi_image)
    # cv2.imshow('RealSense', sr_roi_img)

- operating system
Ubuntu 22.04
- architecture (e.g. x86)
X86
- opencv-python version

$ /usr/bin/pip3 show opencv-python Name: opencv-python Version: 4.9.0.80 Summary: Wrapper package for OpenCV python bindings. Home-page: https://github.com/opencv/opencv-python Author: Author-email: License: Apache 2.0 Location: /home/mona/.local/lib/python3.10/site-packages Requires: numpy Required-by: FaceAnalyzer, MegEngine, mmcv, mmengine, nvdu, raytracing, ultralytics

$ /usr/bin/pip3 show opencv-contrib-python Name: opencv-contrib-python Version: 4.10.0.84 Summary: Wrapper package for OpenCV python bindings. Home-page: https://github.com/opencv/opencv-python Author: Author-email: License: Apache 2.0 Location: /home/mona/.local/lib/python3.10/site-packages Requires: numpy Required-by: mediapipe


##### Issue submission checklist

 - [ ] This is not a generic OpenCV usage question (looking for help for coding, other usage questions, homework etc.)
   <!--

   Use Q&A forums such as https://answers.opencv.org/questions/ and https://stackoverflow.com/ and other communities
   to discuss problems. Tickets without real issue statements related to this build toolchain will be closed.

   -->
 - [ ] I have read the README of this repository and understand that this repository provides only an automated build toolchain for OpenCV Python packages (there is no actual OpenCV code here)
   <!--

   If you have some OpenCV bug report which needs to fixed in the C++ code, 
   please report issue to the OpenCV repository: 

   https://github.com/opencv/opencv/issues

   See also:

   * OpenCV documentation: https://docs.opencv.org
   * OpenCV FAQ page: https://github.com/opencv/opencv/wiki/FAQ
   * OpenCV forum: https://answers.opencv.org
   * Stack Overflow branch: https://stackoverflow.com/questions/tagged/opencv

   -->
 - [ ] The issue is related to the build scripts in this repository, to the pre-built binaries or is a feature request (such as "please enable this additional dependency")
 - [ ] I'm using the latest version of ``opencv-python``

https://github.com/IntelRealSense/librealsense/issues/13278#issuecomment-2307135755
monajalal commented 3 weeks ago

I don't know what the discrepancy between the two versions was but the following resolved it for me:


        roi_image_fullscreen = cv2.resize(roi_image, (second_display_width, second_display_height))
        cv2.imshow('RealSense', roi_image_fullscreen)

I didn't have this piece of code before and it was automatically doing it for me.

image