File tree Expand file tree Collapse file tree 1 file changed +54
-0
lines changed Expand file tree Collapse file tree 1 file changed +54
-0
lines changed Original file line number Diff line number Diff line change
1
+ # -*- coding: utf-8 -*-
2
+ # @Time : 2018/1/19 20:39
3
+ # @Author : play4fun
4
+ # @File : show_image.py
5
+ # @Software: PyCharm
6
+
7
+ """
8
+ show_image.py:
9
+ 制作有用的工具,日常使用
10
+ 在环境变量中设置:
11
+ alias show='/Users/play/.py3/bin/python3.6 /Users/play/github/OpenCV-Python-Tutorial/ch04-图片/show_image.py '
12
+
13
+ """
14
+
15
+ import numpy as np
16
+ import cv2 , sys
17
+
18
+ if len (sys .argv ) < 2 :
19
+ print ('show_image.py image_path' )
20
+ sys .exit (0 )
21
+
22
+ image_path = sys .argv [1 ]
23
+ try :
24
+ f = open (image_path )
25
+ except Exception as e :
26
+ print (e )
27
+ sys .exit (- 1 )
28
+
29
+ img = cv2 .imread (image_path , cv2 .IMREAD_UNCHANGED ) # 包括图像的 alpha 通道
30
+ temp = img .copy ()
31
+
32
+ title = image_path .split ('/' )[- 1 ] + f' { img .shape } '
33
+
34
+ gray = False
35
+ while True :
36
+ cv2 .imshow (title , temp )
37
+
38
+ k = cv2 .waitKey (10 )
39
+ if k == 27 or k == ord ('q' ):
40
+ break
41
+ #TODO 分辨率太大,需要缩放
42
+ if k == ord ('g' ):
43
+ # t = temp == img
44
+ # if t.all():
45
+ # if t.any():
46
+ # if temp == img:
47
+ if gray is False :
48
+ temp = cv2 .cvtColor (img , cv2 .COLOR_BGR2GRAY )
49
+ gray = True
50
+ else :
51
+ temp = img .copy ()
52
+ gray = False
53
+
54
+ cv2 .destroyAllWindows ()
You can’t perform that action at this time.
0 commit comments