0

I am trying to select a Region of Interest using cv2.selectROI() by using a namedWindow("name",WINDOW_AUTOSIZE)

But when I select the ROI I cannot visualize the box.

With namedWindow("name",WINDOW_NORMAL) the box is visible, it works.

if __name__ == '__main__' :

    # Read image
    im = cv2.imread("386368.jpg")

    showCrosshair = False
    fromCenter = False
    cv2.namedWindow("Image",2)
    r = cv2.selectROI("Image", im, fromCenter, showCrosshair)
    cv2.waitKey(30)

Same problem when I use cv2.resize() too. Should I increase the waitKey value? or How can I solve this issue.

This is the auto resized window though I am actually dragging I cannot visualize the ROI This is the normal window I can see the blue box

1 Answer 1

2

Your code is not enough. This is my result and code.


enter image description here

#!/usr/bin/python3
# 2017.11.28 14:32:33 CST

import cv2
import numpy as np

if __name__ == '__main__' :
    # Read image
    img = cv2.imread("test.png")
    cv2.namedWindow("Image",2)
    roi = cv2.selectROI("Image", img, False, False)

    ## Display the roi
    if roi is not None:
        x,y,w,h = roi
        mask = np.zeros_like(img, np.uint8)
        cv2.rectangle(mask, (x,y), (x+w, y+h), (255,255,255), -1)
        masked = cv2.bitwise_and(img, mask )
        cv2.imshow("mask", mask)
        cv2.imshow("ROI", masked)

    cv2.waitKey()
4
  • Thank you for your anwser but cv2.selectROI lets you draw a blue box I don't get that box if I resized the window.
    – janu777
    Nov 28, 2017 at 6:54
  • @janu777 I try to resize the Image window on my PC, it's OK.
    – Kinght 金
    Nov 28, 2017 at 6:56
  • Yeah for some images the resizing works but for some images it doesn't.
    – janu777
    Nov 28, 2017 at 7:03
  • 1
    ... I just tested the one. Then I have no idea why.
    – Kinght 金
    Nov 28, 2017 at 7:09

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.