From 91062a3282d56f0ad258ee7a84f0e0a15aa58f78 Mon Sep 17 00:00:00 2001 From: lantianhaian <90693546+lantianhaian@users.noreply.github.com> Date: Mon, 7 Mar 2022 19:54:22 +0800 Subject: [PATCH] Add files via upload --- .../picture.py" | 12 ++++++++++ .../viedo.py" | 23 +++++++++++++++++++ 2 files changed, 35 insertions(+) create mode 100644 "\350\276\271\347\274\230\346\243\200\346\265\213/picture.py" create mode 100644 "\350\276\271\347\274\230\346\243\200\346\265\213/viedo.py" diff --git "a/\350\276\271\347\274\230\346\243\200\346\265\213/picture.py" "b/\350\276\271\347\274\230\346\243\200\346\265\213/picture.py" new file mode 100644 index 0000000..155a67a --- /dev/null +++ "b/\350\276\271\347\274\230\346\243\200\346\265\213/picture.py" @@ -0,0 +1,12 @@ +import cv2 +def pic_canny(image): + img=cv2.imread(image) + blurred=cv2.GaussianBlur(img,(3,3),0) + gray=cv2.cvtColor(blurred,cv2.COLOR_BGR2GRAY) + xgrad=cv2.Sobel(gray.cv2_16SC1,1,0) + ygrad = cv2.Sobel(gray.cv2_16SC1, 0, 1) + output=cv2.Canny(xgrad,ygrad,50,150) + cv2.imshow("canny",output) + cv2.waitKey(0) + +pic_canny() \ No newline at end of file diff --git "a/\350\276\271\347\274\230\346\243\200\346\265\213/viedo.py" "b/\350\276\271\347\274\230\346\243\200\346\265\213/viedo.py" new file mode 100644 index 0000000..54e4594 --- /dev/null +++ "b/\350\276\271\347\274\230\346\243\200\346\265\213/viedo.py" @@ -0,0 +1,23 @@ +import cv2 + +def viedo_canny(video): + cap=cv2.VideoCapture(video) + while 1: + ret,frame=cap.read() + img=frame + if ret : + img_resize=cv2.resize(img,(1080,608)) + blurred = cv2.GaussianBlur(img_resize, (3, 3), 0) + gray = cv2.cvtColor(blurred, cv2.COLOR_BGR2GRAY) + xgrad = cv2.Sobel(gray,cv2.CV_16SC1, 1, 0) + ygrad = cv2.Sobel(gray,cv2.CV_16SC1, 0, 1) + output = cv2.Canny(xgrad, ygrad, 50, 150) + cv2.imshow("video", output) + if cv2.waitKey(24) & 0xff==27: + break + else: + break + cap.release() + cv2.destroyAllWindows() + +viedo_canny("《原神》剧情PV-「神女劈观」.《原神》剧情PV-「神女劈观」.mp4")#把MP4格式视频放在根目录下, 然后复制路径到这里,即可运行