没有项目描述
CVPubSubs的Python项目详细描述
cvpubsubs
支持连接到多个窗口的pubsub opencv interface ereadme.md.网络摄像头和视频源。
安装
cvpubsub作为一个通用的 wheel和在linux/macos和windows上可用,并支持 python 2.7/3.5+和pypy。
$ pip install CVPubSubs
用法
视频编辑和发布
显示网络摄像头
import cvpubsubs.webcam_pub as w
w.VideoHandlerThread().display()
更改显示参数
import cvpubsubs.webcam_pub as w
video_thread = w.VideoHandlerThread(video_source=0,
callbacks = w.display_callbacks,
request_size=(800, 600),
high_speed = False,
fps_limit = 8
)
处理鼠标输入
import cvpubsubs.webcam_pub as w
from cvpubsubs.input import mouse_loop
@mouse_loop
def print_mouse(mouse_event):
print(mouse_event)
w.VideoHandlerThread().display()
接收按键输入
import cvpubsubs.webcam_pub as w
from cvpubsubs.input import key_loop
@key_loop
def print_key_thread(key_chr):
print("key pressed: " + str(key_chr))
w.VideoHandlerThread().display()
在帧上运行自己的函数
import cvpubsubs.webcam_pub as w
def redden_frame_print_spam(frame, cam_id):
frame[:, :, 0] = 0
frame[:, :, 1] = 0
print("Spam!")
w.VideoHandlerThread(callbacks=[redden_frame_print_spam] + w.display_callbacks).display()
显示张量
def tensor_from_image(frame, cam_id):
ten = tensor_from_pytorch_or_tensorflow(frame)
return ten
t = wp.VideoHandlerThread(video_source=cam, callbacks=[tensor_from_image] + wp.display_callbacks)
t.display()
从一个源显示多个窗口
import cvpubsubs.webcam_pub as w
from cvpubsubs.window_sub import SubscriberWindows
def cam_handler(frame, cam_id):
SubscriberWindows.set_global_frame_dict(cam_id, frame, frame)
t = w.VideoHandlerThread(0, [cam_handler],
request_size=(1280, 720),
high_speed=True,
fps_limit=240
)
t.start()
SubscriberWindows(window_names=['cammy', 'cammy2'],
video_sources=[str(0)]
).loop()
t.join()
显示来自多个来源的多个窗口
iport cvpubsubs.webcam_pub as w
from cvpubsubs.window_sub import SubscriberWindows
t1 = w.VideoHandlerThread(0)
t2 = w.VideoHandlerThread(1)
t1.start()
t2.start()
SubscriberWindows(window_names=['cammy', 'cammy2'],
video_sources=[0,1]
).loop()
t1.join()
t1.join()
对每个像素运行函数
from cvpubsubs.webcam_pub import VideoHandlerThread
from cvpubsubs.webcam_pub.callbacks import function_display_callback
img = np.zeros((50, 50, 1))
img[0:5, 0:5, :] = 1
def conway_game_of_life(array, coords, finished):
neighbors = np.sum(array[max(coords[0] - 1, 0):min(coords[0] + 2, 50),
max(coords[1] - 1, 0):min(coords[1] + 2, 50)])
neighbors = max(neighbors - np.sum(array[coords[0:2]]), 0.0)
if array[coords] == 1.0:
if neighbors < 2 or neighbors > 3:
array[coords] = 0.0
elif 2 <= neighbors <= 3:
array[coords] = 1.0
else:
if neighbors == 3:
array[coords] = 1.0
VideoHandlerThread(video_source=img, callbacks=function_display_callback(conway_game_of_life)).display()
许可证
import cvpubsubs.webcam_pub as w
w.VideoHandlerThread().display()
import cvpubsubs.webcam_pub as w
video_thread = w.VideoHandlerThread(video_source=0,
callbacks = w.display_callbacks,
request_size=(800, 600),
high_speed = False,
fps_limit = 8
)
处理鼠标输入
import cvpubsubs.webcam_pub as w
from cvpubsubs.input import mouse_loop
@mouse_loop
def print_mouse(mouse_event):
print(mouse_event)
w.VideoHandlerThread().display()
接收按键输入
import cvpubsubs.webcam_pub as w
from cvpubsubs.input import key_loop
@key_loop
def print_key_thread(key_chr):
print("key pressed: " + str(key_chr))
w.VideoHandlerThread().display()
在帧上运行自己的函数
import cvpubsubs.webcam_pub as w
def redden_frame_print_spam(frame, cam_id):
frame[:, :, 0] = 0
frame[:, :, 1] = 0
print("Spam!")
w.VideoHandlerThread(callbacks=[redden_frame_print_spam] + w.display_callbacks).display()
显示张量
def tensor_from_image(frame, cam_id):
ten = tensor_from_pytorch_or_tensorflow(frame)
return ten
t = wp.VideoHandlerThread(video_source=cam, callbacks=[tensor_from_image] + wp.display_callbacks)
t.display()
从一个源显示多个窗口
import cvpubsubs.webcam_pub as w
from cvpubsubs.window_sub import SubscriberWindows
def cam_handler(frame, cam_id):
SubscriberWindows.set_global_frame_dict(cam_id, frame, frame)
t = w.VideoHandlerThread(0, [cam_handler],
request_size=(1280, 720),
high_speed=True,
fps_limit=240
)
t.start()
SubscriberWindows(window_names=['cammy', 'cammy2'],
video_sources=[str(0)]
).loop()
t.join()
显示来自多个来源的多个窗口
iport cvpubsubs.webcam_pub as w
from cvpubsubs.window_sub import SubscriberWindows
t1 = w.VideoHandlerThread(0)
t2 = w.VideoHandlerThread(1)
t1.start()
t2.start()
SubscriberWindows(window_names=['cammy', 'cammy2'],
video_sources=[0,1]
).loop()
t1.join()
t1.join()
对每个像素运行函数
from cvpubsubs.webcam_pub import VideoHandlerThread
from cvpubsubs.webcam_pub.callbacks import function_display_callback
img = np.zeros((50, 50, 1))
img[0:5, 0:5, :] = 1
def conway_game_of_life(array, coords, finished):
neighbors = np.sum(array[max(coords[0] - 1, 0):min(coords[0] + 2, 50),
max(coords[1] - 1, 0):min(coords[1] + 2, 50)])
neighbors = max(neighbors - np.sum(array[coords[0:2]]), 0.0)
if array[coords] == 1.0:
if neighbors < 2 or neighbors > 3:
array[coords] = 0.0
elif 2 <= neighbors <= 3:
array[coords] = 1.0
else:
if neighbors == 3:
array[coords] = 1.0
VideoHandlerThread(video_source=img, callbacks=function_display_callback(conway_game_of_life)).display()
许可证
import cvpubsubs.webcam_pub as w
from cvpubsubs.input import mouse_loop
@mouse_loop
def print_mouse(mouse_event):
print(mouse_event)
w.VideoHandlerThread().display()
import cvpubsubs.webcam_pub as w
from cvpubsubs.input import key_loop
@key_loop
def print_key_thread(key_chr):
print("key pressed: " + str(key_chr))
w.VideoHandlerThread().display()
在帧上运行自己的函数
import cvpubsubs.webcam_pub as w
def redden_frame_print_spam(frame, cam_id):
frame[:, :, 0] = 0
frame[:, :, 1] = 0
print("Spam!")
w.VideoHandlerThread(callbacks=[redden_frame_print_spam] + w.display_callbacks).display()
显示张量
def tensor_from_image(frame, cam_id):
ten = tensor_from_pytorch_or_tensorflow(frame)
return ten
t = wp.VideoHandlerThread(video_source=cam, callbacks=[tensor_from_image] + wp.display_callbacks)
t.display()
从一个源显示多个窗口
import cvpubsubs.webcam_pub as w
from cvpubsubs.window_sub import SubscriberWindows
def cam_handler(frame, cam_id):
SubscriberWindows.set_global_frame_dict(cam_id, frame, frame)
t = w.VideoHandlerThread(0, [cam_handler],
request_size=(1280, 720),
high_speed=True,
fps_limit=240
)
t.start()
SubscriberWindows(window_names=['cammy', 'cammy2'],
video_sources=[str(0)]
).loop()
t.join()
显示来自多个来源的多个窗口
iport cvpubsubs.webcam_pub as w
from cvpubsubs.window_sub import SubscriberWindows
t1 = w.VideoHandlerThread(0)
t2 = w.VideoHandlerThread(1)
t1.start()
t2.start()
SubscriberWindows(window_names=['cammy', 'cammy2'],
video_sources=[0,1]
).loop()
t1.join()
t1.join()
对每个像素运行函数
from cvpubsubs.webcam_pub import VideoHandlerThread
from cvpubsubs.webcam_pub.callbacks import function_display_callback
img = np.zeros((50, 50, 1))
img[0:5, 0:5, :] = 1
def conway_game_of_life(array, coords, finished):
neighbors = np.sum(array[max(coords[0] - 1, 0):min(coords[0] + 2, 50),
max(coords[1] - 1, 0):min(coords[1] + 2, 50)])
neighbors = max(neighbors - np.sum(array[coords[0:2]]), 0.0)
if array[coords] == 1.0:
if neighbors < 2 or neighbors > 3:
array[coords] = 0.0
elif 2 <= neighbors <= 3:
array[coords] = 1.0
else:
if neighbors == 3:
array[coords] = 1.0
VideoHandlerThread(video_source=img, callbacks=function_display_callback(conway_game_of_life)).display()
许可证
def tensor_from_image(frame, cam_id):
ten = tensor_from_pytorch_or_tensorflow(frame)
return ten
t = wp.VideoHandlerThread(video_source=cam, callbacks=[tensor_from_image] + wp.display_callbacks)
t.display()
import cvpubsubs.webcam_pub as w
from cvpubsubs.window_sub import SubscriberWindows
def cam_handler(frame, cam_id):
SubscriberWindows.set_global_frame_dict(cam_id, frame, frame)
t = w.VideoHandlerThread(0, [cam_handler],
request_size=(1280, 720),
high_speed=True,
fps_limit=240
)
t.start()
SubscriberWindows(window_names=['cammy', 'cammy2'],
video_sources=[str(0)]
).loop()
t.join()
iport cvpubsubs.webcam_pub as w
from cvpubsubs.window_sub import SubscriberWindows
t1 = w.VideoHandlerThread(0)
t2 = w.VideoHandlerThread(1)
t1.start()
t2.start()
SubscriberWindows(window_names=['cammy', 'cammy2'],
video_sources=[0,1]
).loop()
t1.join()
t1.join()
from cvpubsubs.webcam_pub import VideoHandlerThread
from cvpubsubs.webcam_pub.callbacks import function_display_callback
img = np.zeros((50, 50, 1))
img[0:5, 0:5, :] = 1
def conway_game_of_life(array, coords, finished):
neighbors = np.sum(array[max(coords[0] - 1, 0):min(coords[0] + 2, 50),
max(coords[1] - 1, 0):min(coords[1] + 2, 50)])
neighbors = max(neighbors - np.sum(array[coords[0:2]]), 0.0)
if array[coords] == 1.0:
if neighbors < 2 or neighbors > 3:
array[coords] = 0.0
elif 2 <= neighbors <= 3:
array[coords] = 1.0
else:
if neighbors == 3:
array[coords] = 1.0
VideoHandlerThread(video_source=img, callbacks=function_display_callback(conway_game_of_life)).display()
CVpubSubs根据这两个条款进行分配
MIT License <https://choosealicense.com/licenses/mit>
Apache License, Version 2.0 <https://choosealicense.com/licenses/apache-2.0>
由你选择。