iT邦幫忙

0

使用vscode運行影像辨識但無回應

  • 分享至 

  • xImage

大家好,我是剛接觸影像辨識的小白大學生,目前正在嘗試用esp32 cam截取的影像進行影像辨識,有找到一個確定可以跑的程式碼,但是在筆電上的vscode運行時,跳出的視窗都是沒有回應的,想請問該如何解決這個問題?以下是我找到的程式碼:
import cv2
import matplotlib.pyplot as plt
import cvlib as cv
import urllib.request
import numpy as np
from cvlib.object_detection import draw_bbox
import concurrent.futures

url='esp32 cam的ip'

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)

https://ithelp.ithome.com.tw/upload/images/20220804/20151057C68QIh6fEJ.png

GJ iT邦好手 1 級 ‧ 2022-08-08 18:25:22 檢舉
估計是沒有讀取到影像
請先確認筆電程式以外的方式能否讀到CAM影像
圖片
  直播研討會
圖片
{{ item.channelVendor }} {{ item.webinarstarted }} |
{{ formatDate(item.duration) }}
直播中

1 個回答

0
fillano
iT邦超人 1 級 ‧ 2022-08-07 07:31:25

先學著怎麼用程式碼區塊包住你的程式碼,讓大家容易看...像這樣:

import cv2
import matplotlib.pyplot as plt
import cvlib as cv
import urllib.request
import numpy as np
from cvlib.object_detection import draw_bbox
import concurrent.futures

url='esp32 cam的ip'

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)

然後比較容易找到人幫你。

我要發表回答

立即登入回答