初步完成第四题
This commit is contained in:
@@ -1,17 +1,32 @@
|
|||||||
import cv2 as cv
|
import cv2 as cv
|
||||||
|
import numpy as np
|
||||||
|
|
||||||
# 1
|
# 1
|
||||||
img=cv.imread("sample.jpg",cv.IMREAD_GRAYSCALE)
|
img=cv.imread("sample.jpg",cv.IMREAD_GRAYSCALE)
|
||||||
|
img2=cv.imread('sample.jpg',cv.IMREAD_GRAYSCALE)
|
||||||
# 2
|
# 2
|
||||||
def draw_circle(event,x,y,flags,param):
|
def draw_circle(event,x,y,flags,param):
|
||||||
if event==cv.EVENT_LBUTTONDOWN:
|
if event==cv.EVENT_LBUTTONDOWN:
|
||||||
cv.circle(img,(x,y),10,0,-1)
|
cv.circle(img,(x,y),10,0,-1)
|
||||||
#3
|
|
||||||
cv.namedWindow('modify_sample')
|
|
||||||
cv.setMouseCallback('modify_sample',draw_circle)
|
|
||||||
#4
|
#4
|
||||||
alpha=0.3
|
alpha=0.3
|
||||||
beta=80
|
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):
|
while(1):
|
||||||
cv.imshow('modify_sample',img)
|
cv.imshow('modify_sample',img)
|
||||||
pressedKey=cv.waitKey(5)
|
pressedKey=cv.waitKey(5)
|
||||||
|
|||||||
Reference in New Issue
Block a user