如何填充 ROI,使影像位于 ROI 的中心?
找到 ROI并(x, y, w, h) = cv2.boundingRect(contour)插入輸入影像
image = cv2.resize(input_image, (w, h)) img2gray = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY) _, image_mask = cv2.threshold(img2gray, 1, 255, cv2.THRESH_BINARY) roi = frame[y:y h, x:x w] roi[np.where(image_mask)] = 0 roi = image
h和w是我輸入影像的尺寸。
如何添加偏移量以使ROI = image結果如圖所示?

uj5u.com熱心網友回復:
根據我的理解,您希望將調整大小的影像放置在 ROI 的中心。
您已經獲得了投資回報率roi = frame[y:y h, x:x w]。
# using this as background, hence making it white
roi[:] = (255, 255, 255)
# Obtain the spatial dimensions of ROI and image
roi_h, roi_w = roi.shape[:2]
image_h, image_w = image.shape[:2]
# Calculate height and width offsets
height_off = int((roi_h - image_h)/2)
width_off = int((roi_w - image_w)/2)
# With Numpy slicing, place the image in the center of the ROI
roi[height_off:height_off image_h, width_off:width_off image_w] = image
我希望這能讓您了解如何進一步進行
轉載請註明出處,本文鏈接:https://www.uj5u.com/yidong/466811.html
上一篇:int位域的大小和對齊方式
下一篇:從影像中裁剪和提取圖章
