import threading import cv2 as cv import time import numpy as np class ROI9527(): def __init__(self): pass def draw_Contours(self, contours, img): ''' # 绘制自动识别的轮廓 automation 自动识别区域 :param contours: :param img: :return: ''' cnt = contours[1:] # contours 二值图片轮廓 获取全部轮廓 Contours_image = cv.drawContours(img, cnt, -1, (0, 0, 255), 1) # 其中参数2就是得到的contours,参数3表示要绘制哪一条轮廓,-1表示绘制所有轮廓,参数4是颜色(B/G/R通道,所以(0,0,255)表示红色),参数5是线宽 cv.namedWindow('show Fail', 0) # O表示显示窗口可以随意手动调节,1 cv.imshow("show Fail", Contours_image) # 显示图片 c = cv.waitKey(0) # 50豪标 显示时间 显示时间越长 卡顿越严重 cv.destroyWindow("show Fail") # 显示ROI 有效区域 def show_obj_area(self, ROI_list, img): ''' 自动识别ROI区域显示 :param img: :return: ''' print('ROSlIST: ', ROI_list) print('自动识别ROI区域个数: ', len(ROI_list)) new_image = img for OBJ_ROI in ROI_list: x_min = OBJ_ROI["x_min"] - 10 y_min = OBJ_ROI["y_min"] - 10 x_max = OBJ_ROI["x_max"] + 10 y_max = OBJ_ROI["y_max"] + 10 cv.rectangle(new_image, (x_min, y_min), (x_max, y_max), (4, 211, 41), 2) # 白色區域 [x列:y列, x列:y行] # 行差100 cv.namedWindow('show_obj_area', 0) # O表示显示窗口可以随意手动调节,1 cv.imshow("show_obj_area", new_image) # 显示图片 c = cv.waitKey(0) # 50豪标 显示时间 显示时间越长 卡顿越严重 cv.destroyAllWindows() def showIMG(self, img, index=9527):
openCV ROI
最新推荐文章于 2023-07-14 10:19:20 发布