def preallocate(self, img):
if self.size is None or self.size[0] != img.shape[0] or self.size[1] != img.shape[1]:
h, w = img.shape[:2]
self.size = (h, w)
self.img = np.empty((h, w, 3), dtype=np.uint8)
self.hsv = np.empty((h, w, 3), dtype=np.uint8)
self.bin = np.empty((h, w, 1), dtype=np.uint8)
self.bin2 = np.empty((h, w, 1), dtype=np.uint8)
self.out = np.empty((h, w, 3), dtype=np.uint8)
# for overlays
self.zeros = np.zeros((h, w, 1), dtype=np.bool)
self.black = np.zeros((h, w, 3), dtype=np.uint8)
self.morphKernel = cv2.getStructuringElement(cv2.MORPH_RECT, (2,2), anchor=(0,0))
cv2.copyMakeBorder(img, 0, 0, 0, 0, cv2.BORDER_CONSTANT, value=self.RED, dst=self.out)
评论列表
文章目录