opencv using python - kopiere roi auf ein neues, kleineres Bild
In OpenCV mit Python - Wie kann ich ein neues Image erstellen, das einfach eine Kopie eines Roi von einem anderen Image ist? Sicher gibt es etwas im Sinne von
Mat roi = img( Rect(x,y,w,h) );
für Python oder irgendetwas Eleganteres als die Brute Force
rect=[x,y,w,h]
img = cv2.imread(subst)
roi= np.zeros((rect[3],rect[2],3),np.uint8) #is this really reversed? who ordered that?
cv2.rectangle(img,(x,y),(w+x,h+y),[255,0,0],thickness=1)
cv2.imshow('img',img)
cv2.waitKey()
#cv.Copy(cv.fromarray(img),cv.fromarray(roi),cv.fromarray(mask)) #can't make it work...
for x in range(rect[2]):
for y in range(rect[3]):
roi[y,x,:]=img[y+rect[1],x+rect[0],:]
und übrigens, wie ordnen sich die x, y-Koordinaten - ist es [x, y, c] oder [y, x, c], einen Punkt bei x (horizontal) und y (vertikal) anzugeben? Es scheint wie sein [y, x, c], iiuc, während das cv2.rectangle (x, y) und die img.shape (y, x) ist, was noch ärgerlicher wäre als (g, r, b) von (r, g, b) ....