python-opencv:cv2.selectROIの使用法、パラメーター、および戻り値の解釈



Python Opencv Interpretation Cv2



画像で、より多くの操作を実行するために、どのように関心のある領域を選択し、関心のある領域をインターセプトしますか?

image=cv2.imread('example.png') cv2.namedWindow('img') r = cv2.selectROI('roi', image, False, False ) cv2.waitKey(0)

画像



パラメータの解釈:

selectROI(windowName, img, showCrosshair=None, fromCenter=None): . Parameter windowName: the name of the window where the selected area is displayed . Parameter img: what picture to choose ROI on . Parameter showCrosshair: whether to draw a crosshair in a rectangular box. . Parameter fromCenter: whether to start drawing from the center of the rectangular box

戻り値:

image=cv2.imread('example.png') cv2.namedWindow('img') r = cv2.selectROI('roi', image, False, False ) print(r) cv2.waitKey(0)

返されるのはリスト[min_x、min_y、w、h]です。
画像
最初の値は、長方形の最小のx値です
2番目の値は、長方形のボックス内の最小のy値です。
3番目の値は、この長方形のボックスの幅です。
4番目の値は長方形のボックスの高さです

インターセプトROI:

image=cv2.imread('example.png') cv2.namedWindow('img') r = cv2.selectROI('roi', image, False, False ) print(r) img_roi = image[int(r[1]):int(r[1]+r[3]),int(r[0]):int(r[0]+r[2])] cv2.imshow('imageHSV',img_roi) cv2.waitKey(0)

[注:ここimage[int(r[1]):int(r[1]+r[3]),int(r[0]):int(r[0]+r[2])]水平座標と垂直座標を変更する必要があります]
画像



画像