[英]How to I efficiently transform a numpy image of shape (w, h, 3) to (w,h,5) which has r,g,b,x,y in third axis?
[英]How to get each value of x,y,w,h in this crop image?
我想問一些事情。 在 opencv 中有 cv2.rectangle 來構建一個 object 感興趣的矩形。 在我得到用矩形表示的 object 興趣后,我想得到興趣區域框。 為此,我使用了crop = frame[y:y+h, x:x+w]
。
現在我想得到那個裁剪框的x,y,w,h
的值。 怎么做?
這是我的代碼
while bol:
capture = cv2.VideoCapture(0)
ret, frame = capture.read()
#load object detector
path = os.getcwd()+'\haarcascade_frontalface_default.xml'
face_cascade = cv2.CascadeClassifier(path)
#convert image to grayscale
imgGray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)
for (x, y, w, h) in face_cascade.CascadeClassifier(imgGray):
cv2.rectangle(frame, (x,y), (x+w, y+h), (255,255,255), 3)
_croppedImage = frame[y:y+h, x:x+w]
ROI = _croppedImage
如何獲得_croppedImage
的x,y,w,h
的值?
_croppedImage 的x & y
的值沒有意義和意義。 這是因為 _croppedImage 只是從另一個圖像中裁剪出來的圖像。
要獲取 _croppedImage 的w & h
,您可以使用 .shape() 方法。 圖像的w & h
分別是圖像的寬度和高度。
h, w = _croppedImage[:2]
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.