cv2.floodFill(img,mask,seed,newvalue(BGR),(loDiff1,loDiff2,loDiff3),(upDiff1,upDiff2,upDiff3),flag)
#泛洪填充(彩色图像填充) import cv2 import numpy as np def fill_color_demo(image): copyImg = image.copy() h, w = image.shape[:2] mask = np.zeros([h+2, w+2],np.uint8) #mask必须行和列都加2,且必须为uint8单通道阵列 #为什么要加2可以这么理解:当从0行0列开始泛洪填充扫描时,mask多出来的2可以保证扫描的边界上的像素都会被处理 cv.floodFill(copyImg, mask, (220, 250), (0, 255, 255), (100, 100, 100), (50, 50 ,50), cv.FLOODFILL_FIXED_RANGE) cv.imshow("fill_color_demo", copyImg) src = cv.imread('E:/imageload/baboon.jpg') cv.namedWindow('input_image', cv.WINDOW_AUTOSIZE) cv.imshow('input_image', src) fill_color_demo(src) cv.waitKey(0) cv.destroyAllWindows()
cv2.floodFill(initial_car,mask,(seed_x,seed_y),(255,0,0),(loDiff,loDiff,loDiff),(upDiff,upDiff,upDiff),flag) points = [] row,column = mask.shape for i in range(row): for j in range(column): if mask[i][j]==255: points.append((j,i)) #点应该输入点坐标(列,行) points = np.asarray(points) new_rect = cv2.minAreaRect(points)
免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:mmqy2019@163.com进行举报,并提供相关证据,查实之后,将立刻删除涉嫌侵权内容。
长按识别二维码并关注微信
更方便到期提醒、手机管理