Created
June 24, 2022 13:41
-
-
Save temminks/b452924bbac62003bb8c38092aaa0730 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
import cv2 | |
import cvlib as cv | |
import urllib.request | |
import numpy as np | |
from cvlib.object_detection import draw_bbox | |
import concurrent.futures | |
url = 'http://192.168.178.54/capture' | |
im = None | |
def run1(): | |
cv2.namedWindow("live transmission", cv2.WINDOW_AUTOSIZE) | |
while True: | |
img_resp = urllib.request.urlopen(url) | |
imgnp = np.array(bytearray(img_resp.read()), dtype=np.uint8) | |
im = cv2.imdecode(imgnp, -1) | |
cv2.imshow('live transmission', im) | |
key = cv2.waitKey(5) | |
if key == ord('q'): | |
break | |
cv2.destroyAllWindows() | |
def run2(): | |
cv2.namedWindow("detection", cv2.WINDOW_AUTOSIZE) | |
while True: | |
img_resp = urllib.request.urlopen(url) | |
imgnp = np.array(bytearray(img_resp.read()), dtype=np.uint8) | |
im = cv2.imdecode(imgnp, -1) | |
bbox, label, conf = cv.detect_common_objects(im) | |
im = draw_bbox(im, bbox, label, conf) | |
cv2.imshow('detection', im) | |
key = cv2.waitKey(5) | |
if key == ord('q'): | |
break | |
cv2.destroyAllWindows() | |
if __name__ == '__main__': | |
print("started") | |
with concurrent.futures.ProcessPoolExecutor() as executer: | |
f1 = executer.submit(run1) | |
f2 = executer.submit(run2) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment