else: cv2.rectangle(image, (x - 5, y - 15), (x + w, y + h + 10), (255, 255, 255), 20) elif k == 3: if w < bounding_list[3][2]: w = bounding_list[3][2] cv2.rectangle(image, (x - 5, y - 5), (x + w, y + h + 10), (255, 255, 255), 25) else: cv2.rectangle(image, (x - 5, y - 5), (x + w, y + h + 10), (255, 255, 255), 25) elif k == 4: if w < bounding_list[3][2]: w = bounding_list[3][2] if x > bounding_list[3][0]: x = bounding_list[3][0] cv2.rectangle(image, (x - 5, y - 15), (x + w, y + h + 14), (255, 255, 255), 25) else: cv2.rectangle(image, (x - 5, y - 15), (x + w, y + h + 14), (255, 255, 255), 25) cv2.line(image, (x, y + h - 10), (x + w, y + h - 10), (255, 255, 255), 25) return image if __name__ == '__main__': images = ['C:/Users/Administrator/Desktop/1_ELwangkang/ASIC_PD_05_03_21_022646.jpg','C:/Users/Administrator/Desktop/1_ELwangkang/ASIC_PD_05_03_21_022450.jpg'] original = cv2.imread(images[1]) image_show('测试', original) image = original add_rectangle_image = draw_rectangle(image, original) image_show('add_rectangle_image', add_rectangle_image)
:param standard_light_coef: 目标亮度系数. :param standard_contrast_coef: 目标对比度系数. :return: over_picture, """ needed_image = cv2.imread(picture) needed_image_light_coef = light_contrast_coef(needed_image)[0] needed_image_contrast_coef = light_contrast_coef(needed_image)[ 1] # 待调图片的亮度信息 needed_image_contrast = needed_image - needed_image_light_coef # 待调图片的对比度信息 数组(广播) m = standard_light_coef / needed_image_light_coef # 亮度系数 n = standard_contrast_coef / needed_image_contrast_coef # 对比度系数 over_picture = needed_image_light_coef * m + needed_image_contrast * n # 修改亮度和对比度 # new_array_picture = new_array_picture/255 # 保存到本地注释掉,在batch_deal_el.py中保存到本地,便于批处理 #cv2.imwrite('D://Documents//Desktop//over_picture.jpg', over_picture) return over_picture if __name__ == '__main__': from tools import image_show # 图片img的亮度系数、对比度系数 img = cv2.imread('D://Documents//Desktop//sxdhd.jpg') standard_light_coef = light_contrast_coef(img)[0] standard_contrast_coef = light_contrast_coef(img)[1] over_picture = adjust_image_info('D://Documents//Desktop//szy2.jpg', standard_light_coef, standard_contrast_coef) image_show('over picture', over_picture)
db="ak_zuul", charset="utf8") cur = conn.cursor() sql = "INSERT INTO aiko_elprint (original_el_path, constract_el_path,rectangle_el_path,tzqt_el_path,dytzqt_el_path,dytz_el_path) VALUES ( '%s', '%s','%s', '%s', '%s','%s')" data = (original_need_deal_el_path, constract_el_path, rectangle_el_path, tzqt_el_path, dytzqt_el_path, dytz_el_path) cur.execute(sql % data) conn.commit() # print('边缘矩形图像已保存到本地') if __name__ == '__main__': from tools import image_show over_picture_path = 'F://2017//12//ELTD//Renamepath2//101985314740.jpg' # original_image = cv2.imread('D://Documents//Desktop//over_picture.jpg') # 改变亮度、对比度后的图片image1 image = cv2.imread('F://2017//test//Rectangle//Rectangle_101985314740.jpg' ) # 在image1的基础上增加矩形边缘、白色格栅线的图片image2 # 图片img的二值图和轮廓等。 thresh = Contours_feature(image)[0] transformed_image = transform_form(thresh, 'closing') image_show('transformed_image', transformed_image) # 展示形态学转换后的二值图 new_image, new_contours, new_hierarchy = cv2.findContours( transformed_image, cv2.RETR_EXTERNAL, cv2.CHAIN_APPROX_SIMPLE) # image2的二值图经过形态学转化后的轮廓等提取 bounding_show(new_contours, over_picture_path, number_id=None) # 在image1 中展示故障特征 # save_bounding_picture(new_contours, over_picture_path) # 根据轮廓,提取故障特征保存在本地
""" imgray = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY) ret, thresh = cv2.threshold(imgray, 10, 255, cv2.THRESH_BINARY) # 反色,即对二值图每个像素取反 result = cv2.bitwise_not(thresh) dilation_kernel = np.ones((10, 10), np.uint8) dilation = cv2.dilate(result, dilation_kernel, iterations=2) erode_kernel = np.ones((5, 5), np.uint8) closing_image = cv2.erode(dilation, erode_kernel, iterations=1) new_image, new_contours, new_hierarchy = cv2.findContours( closing_image, cv2.RETR_TREE, cv2.CHAIN_APPROX_SIMPLE) # image2的二值图经过形态学转化后的轮廓等 for i in range(len(new_contours)): j = new_contours[i] x, y, w, h = cv2.boundingRect(j) cv2.rectangle(image, (x - 10, y - 10), (x + w + 8, y + h + 5), (255, 255, 255), 17) # 不注释的话会使之后的img变量表示的图片上都是绿色的线框存在,影响图片原有信息。 # 保存到本地注释掉,在batch_deal_el.py中保存到本地,便于批处理 # cv2.imwrite('D://Documents//Desktop//add_rectangle_image.jpg', ee) return image if __name__ == '__main__': from tools import image_show image = cv2.imread('F:/2017/12/ELTD/Constract/Constract_101910111517.jpg') add_rectangle_image = draw_rectangle(image) image_show('add_rectangle_image', add_rectangle_image)