Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 557778e

Browse files
committed
日常使用
1 parent 80c7a03 commit 557778e

File tree

1 file changed

+54
-0
lines changed

1 file changed

+54
-0
lines changed

‎ch04-图片/show_image.py‎

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
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()

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /