From 663ed66e2fc1fc0dd33dfbfd20f190b76aeb5aa8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=BE=A1=E5=9D=82=E6=98=B4?= Date: Mon, 23 Sep 2024 22:41:54 +0800 Subject: [PATCH] =?UTF-8?q?=E5=88=9D=E6=AD=A5=E5=AE=8C=E6=88=90=E7=AC=AC?= =?UTF-8?q?=E5=9B=9B=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- test/2024,9,23/homework.py | 21 ++++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) diff --git a/test/2024,9,23/homework.py b/test/2024,9,23/homework.py index 3978220..73eb236 100644 --- a/test/2024,9,23/homework.py +++ b/test/2024,9,23/homework.py @@ -1,17 +1,32 @@ import cv2 as cv +import numpy as np # 1 img=cv.imread("sample.jpg",cv.IMREAD_GRAYSCALE) +img2=cv.imread('sample.jpg',cv.IMREAD_GRAYSCALE) # 2 def draw_circle(event,x,y,flags,param): if event==cv.EVENT_LBUTTONDOWN: cv.circle(img,(x,y),10,0,-1) -#3 -cv.namedWindow('modify_sample') -cv.setMouseCallback('modify_sample',draw_circle) #4 alpha=0.3 beta=80 +def updateAlpha(x): + global alpha,img,img2 + alpha=cv.getTrackbarPos('Alpha','image') + alpha=alpha*0.01 + img=np.uint8(np.clip((alpha*img2+beta),0,255)) +def updateBeta(x): + global beta,img,img2 + beta=cv.getTrackbarPos('Beta','image') + img=np.uint8(np.clip((alpha*img2+beta),0,255)) +#3 +cv.namedWindow('modify_sample') +cv.createTrackbar('Alpha','image',0,300,updateAlpha) +cv.createTrackbar('Beta','image',0,255,updateBeta) +cv.setTrackbarPos('Alpha','image',100) +cv.setTrackbarPos('Beta','image',10) +cv.setMouseCallback('modify_sample',draw_circle) while(1): cv.imshow('modify_sample',img) pressedKey=cv.waitKey(5)