OpenCV-python通过滑条调节两张图片的融合度,通过修改像素对目标区域画上矩形,获取图像的像素

    科技2022-07-14  115

    import cv2 import numpy as py # 获取图像的信息 def get_img_info(src): height = src.shape[0] width = src.shape[1] channels = src.shape[2] print('长度:%d 宽度:%d 通道:%d' % (height, width, channels)) # 滑条的回调函数 def nothing(x): pass img = cv2.imread('football.png') cv2.rectangle(img, (100, 300), (188, 368), (0, 0, 255), 1) width1 = 601 height1 = 375 dim = (width1, height1) # 修改图像的大小,使两幅图的大小相同 img2 = cv2.imread('tree.jpg') img2 = cv2.resize(img2, dim, interpolation=cv2.INTER_AREA) # 修改图像大小 cv2.namedWindow('input img', cv2.WINDOW_AUTOSIZE) cv2.createTrackbar('bar', 'input img', 0, 10, nothing) # 创建滑条来修改图像融合度 cv2.imshow('input img', img) get_img_info(img) get_img_info(img2) while(1): tmp = cv2.getTrackbarPos('bar', 'input img') dst = cv2.addWeighted(img2, float(tmp/10), img, float(1-(tmp/10)), 0) # 图像混合 cv2.imshow('input img', dst) c = cv2.waitKey(1) # 不能为0,为0的话会等待一个输入直到有内容输入 if c == 27: break # cv2.destroyAllWindows()
    Processed: 0.018, SQL: 8