1. 程式人生 > >python+opencv影象長寬xy和螢幕的對應

python+opencv影象長寬xy和螢幕的對應

左上角是原點,往下是x/height。往右是y/width。

 

import cv2
import numpy as np

img = cv2.imread('Parthenon.jpg')

h,w,l = np.shape(img)

(h1, w1) = img.shape[:2] #tuple

print(h,w,l)
print(h1,w1)

cv2.imshow('Parthenon',img)


img1 = np.copy(img)

for x in range(200):
    img1[x,:] = 0
    
cv2.imshow('Parthenon1',img1)

img2 = np.copy(img)

for y in range(200):
    img2[:,y] = 0
    
cv2.imshow('Parthenon2',img2)

輸出:

(498, 800, 3)
(498, 800)