forked from makelove/OpenCV-Python-Tutorial
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
172 additions
and
42 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
# -*- coding: utf-8 -*- | ||
# @Time : 2017/7/18 下午11:14 | ||
# @Author : play4fun | ||
# @File : __init__.py | ||
# @Software: PyCharm | ||
|
||
""" | ||
__init__.py: | ||
""" | ||
|
66 changes: 66 additions & 0 deletions
66
Tools工具包/OpenCV_Window_Management/opencv_windows_management.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
# -*- coding: utf-8 -*- | ||
# @Time : 2017/7/18 下午10:34 | ||
# @Author : play4fun | ||
# @File : opencv_windows_management.py | ||
# @Software: PyCharm | ||
|
||
""" | ||
opencv_windows_management.py: | ||
""" | ||
|
||
import cv2, math | ||
import tkinter as tk | ||
|
||
|
||
class Window: | ||
def __init__(self, name, image, weight=1): | ||
self.name = name | ||
self.image = image.copy() | ||
self.weight = weight | ||
self.shape = self.image.shape | ||
self.hight_x = self.shape[0] | ||
self.lenght_y = self.shape[1] | ||
|
||
|
||
class opencv_windows_management: | ||
def __init__(self): | ||
self.windows = dict() | ||
|
||
root = tk.Tk() | ||
screen_width = root.winfo_screenwidth() | ||
screen_height = root.winfo_screenheight() | ||
self.screen_size = (screen_width, screen_height) # (1280, 800) | ||
root.quit() | ||
|
||
def add(self, name, image, weight=1): | ||
''' | ||
权重,越高,图片显示越大 | ||
:return: | ||
''' | ||
cv2.namedWindow(name, flags=cv2.WINDOW_AUTOSIZE) | ||
window = Window(name, image, weight) | ||
self.windows[name] = window | ||
# self.windows[name] = image | ||
|
||
def show(self): | ||
lenw = len(self.windows) | ||
w_l = int(self.screen_size[0] / lenw) | ||
|
||
max_num_line = math.ceil(math.sqrt(lenw)) # 取平方根 | ||
# TODO 权重 | ||
|
||
for i, name in enumerate(self.windows): | ||
# if (i+1) >max_num_line: | ||
# #TODO 换行 | ||
# cv2.moveWindow(name, w_l * i, h_x*j) | ||
# pass | ||
|
||
win = self.windows[name] | ||
image = win.image | ||
# image = self.windows[name] | ||
# h_x = int(image.shape[1] / w_l * image.shape[0]) #保持比例 | ||
h_x = int(w_l / win.lenght_y * win.hight_x) # 保持比例 | ||
# print((w_l,h_x)) | ||
img2 = cv2.resize(image, (w_l, h_x)) | ||
cv2.moveWindow(name, w_l * i, 0) | ||
cv2.imshow(name, img2) |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
# -*- coding: utf-8 -*- | ||
# @Time : 2017/7/19 上午10:52 | ||
# @Author : play4fun | ||
# @File : cv2_imread_path_not_found.py | ||
# @Software: PyCharm | ||
|
||
""" | ||
cv2_imread_path_not_found.py: | ||
""" | ||
|
||
import cv2 | ||
import numpy as np | ||
import os | ||
import errno | ||
|
||
path = 'messi6.jpg'#不正确的路径,文件不存在 | ||
# path = '../data/messi5.jpg' | ||
if not os.path.exists(path): | ||
raise FileNotFoundError(errno.ENOENT, os.strerror(errno.ENOENT), path) | ||
|
||
img = cv2.imread(path, cv2.IMREAD_UNCHANGED) | ||
|
||
cv2.imshow('src', img) | ||
cv2.waitKey(0) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters