亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

為什么我會收到此錯誤?'NoneType'對象在opencv中沒有屬性'shape'

為什么我會收到此錯誤?'NoneType'對象在opencv中沒有屬性'shape'

天涯盡頭無女友 2023-09-02 16:22:31
我正在研究實時服裝檢測。所以我從 GitHub 借用了這樣的代碼: https: //github.com/rajkbharali/Real-time-clothes-detection 但是(H, W) = frame.shape[:2]:最后一行出現以下錯誤。我應該在哪里修復它?from time import sleepimport cv2 as cvimport argparseimport sysimport numpy as npimport os.pathfrom glob import globimport imutilsfrom imutils.video import WebcamVideoStreamfrom imutils.video import FPSfrom google.colab import drivedrive.mount('/content/drive')%cd /content/drive/My Drive/experiment/Yolo_mark-master/x64/Release/Labels = []classesFile1 = "data/obj.names";with open(classesFile1, 'rt') as f:    Labels = f.read().rstrip('\n').split('\n')np.random.seed(42)COLORS = np.random.randint(0, 255, size=(len(Labels), 3), dtype="uint8")weightsPath = "obj_4000.weights"configPath = "obj.cfg"net1 = cv.dnn.readNetFromDarknet(configPath, weightsPath)net1.setPreferableBackend(cv.dnn.DNN_BACKEND_OPENCV)net1.setPreferableTarget(cv.dnn.DNN_TARGET_CPU)image = WebcamVideoStream(src=0).start()fps = FPS().start()#'/home/raj/Documents/yolov3-Helmet-Detection-master/safety.mp4'#while fps._numFrames<100:while True:#for fn in glob('images/*.jpg'):    frame = image.read()    #frame = imutils.resize(frame,width=500)    (H, W) = frame.shape[:2]
查看完整描述

1 回答

?
蕭十郎

TA貢獻1815條經驗 獲得超13個贊

您的錯誤背后的原因是框架是None(Null). 有時,從網絡攝像頭捕獲的第一幀是“無”,主要是因為 (1)網絡攝像頭尚未準備好(并且需要一些額外的時間才能準備好)或者(2)操作系統不允許您的代碼訪問網絡攝像頭。


在第一種情況下,在對框架執行任何操作之前,您需要檢查框架是否有效:


while True:

?

? ? frame = image.read()

? ? if frame is not None:? # add this line

? ? ? ?

? ? ? (H, W) = frame.shape[:2]

在其他情況下,您需要檢查操作系統中的相機設置。


此外,為了捕獲網絡攝像頭幀,還有另一種基于Opencv 中的VideoCapure類的方法,該方法可能更容易調試。



查看完整回答
反對 回復 2023-09-02
  • 1 回答
  • 0 關注
  • 161 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號