I’m having trouble with import cv
in my python code.
My issue is I need to draw a rectangle around regions of interest in an image. How can this be done in python? I’m doing object detection and would like to draw a rectangle around the objects I believe I’ve found in the image.
Advertisement
Answer
please don’t try with the old cv module, use cv2:
JavaScript
x
11
11
1
import cv2
2
3
cv2.rectangle(img, (x1, y1), (x2, y2), (255,0,0), 2)
4
5
6
x1,y1 ------
7
| |
8
| |
9
| |
10
--------x2,y2
11
[edit] to append the follow-up questions below:
JavaScript
1
5
1
cv2.imwrite("my.png",img)
2
3
cv2.imshow("lalala", img)
4
k = cv2.waitKey(0) # 0==wait forever
5