opencv roi
import cv2
import numpy as np
def grayscale(img): # 흑백이미지로 변환
return cv2.cvtColor(img, cv2.COLOR_RGB2GRAY)
def roi(img, vertices):
mask = np.zeros_like(img)
cv2.fillPoly(mask,vertices,255)
masked = cv2.bitwise_and(img,mask)
return masked
img = cv2.imread('test.jpg')
px = img.shape[0]
px1 = img.shape[1]
print(px, px1)
r= 600.0/img.shape[1]
dim = (800,int(img.shape[0]*r))
resized = cv2.resize(img, dim, interpolation = cv2.INTER_AREA)
cv2.imshow('scaling', resized)
cuttingImg = resized[100:400, 100:400]
#cv2.imshow('cuttingImg',cuttingImg)
vertices = np.array([[10,500], [10,300], [300,200], [500,200], [800,300], [800,500],],np.int32)
gray_img = grayscale(resized)
output_img = roi(gray_img, [vertices])
#ROI_image = cv2.bitwise_and(resized, cuttingImg)
#cv2.imshow('ROI', ROI_image)
cv2.imshow('roi', output_img)
cv2.waitKey(0)
cv2.destroyAllWindows()