第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號(hào)安全,請(qǐng)及時(shí)綁定郵箱和手機(jī)立即綁定
已解決430363個(gè)問(wèn)題,去搜搜看,總會(huì)有你想問(wèn)的

如何從 python 中的 cv2.VideoCapture 獲取每個(gè)幀作為圖像

如何從 python 中的 cv2.VideoCapture 獲取每個(gè)幀作為圖像

冉冉說(shuō) 2022-12-20 14:31:17
我想從視頻中獲取每一幀作為圖像。背景如下。我寫(xiě)了一個(gè)能夠識(shí)別手勢(shì)的神經(jīng)網(wǎng)絡(luò)?,F(xiàn)在我想開(kāi)始一個(gè)視頻流,其中流的每個(gè)圖像/幀都通過(guò)神經(jīng)網(wǎng)絡(luò)。為了使其適合我的神經(jīng)網(wǎng)絡(luò),我想渲染每一幀并將圖像縮小到 28*28 像素。最后它看起來(lái)應(yīng)該類似于:https ://www.youtube.com/watch?v= JfSao30fMxY 我已經(jīng)通過(guò)網(wǎng)絡(luò)搜索并發(fā)現(xiàn)我可以使用 cv2.VideoCapture 來(lái)獲取流。但是我怎樣才能挑選幀的每個(gè)圖像,渲染它并將結(jié)果打印回屏幕上。到目前為止,我的代碼看起來(lái)像這樣:import numpy as npimport cv2cap = cv2.VideoCapture(0)# Todo: each Frame/Image from the video should be saved as a variable and open imageToLabel()# Todo: before the image is handed to the method, it needs to be translated into a 28*28 np Array# Todo: the returned Label should be printed onto the video (otherwise it can be )i = 0while (True):    # Capture frame-by-frame    # Load model once and pass it as an parameter    ret, frame = cap.read()    i += 1    image = cv2.imwrite('database/{index}.png'.format(index=i), frame)    gray = cv2.cvtColor(frame, cv2.COLOR_BGR2BGRAY)    cv2.imshow('frame', frame)    if cv2.waitKey(1) & 0xFF == ord('q'):        break# When everything done, release the capturecap.release()cv2.destroyAllWindows()def imageToLabel(imgArr, checkpointLoad):    new_model = tf.keras.models.load_model(checkpointLoad)    imgArrNew = imgArr.reshape(1, 28, 28, 1) / 255    prediction = new_model.predict(imgArrNew)    label = np.argmax(prediction)    return label
查看完整描述

1 回答

?
神不在的星期二

TA貢獻(xiàn)1963條經(jīng)驗(yàn) 獲得超6個(gè)贊

frame是您從流中獲得的 RGB 圖像。 gray是灰度轉(zhuǎn)換后的圖像。我想您的網(wǎng)絡(luò)因其形狀而采用灰度圖像。因此,您需要先將圖像大小調(diào)整為 (28,28),然后將其傳遞給您的 imageToLabel 函數(shù)


resizedImg = cv2.resize(gray,(28,28))

label = imageToLabel(resizedImg,yourModel)

現(xiàn)在您知道了預(yù)測(cè),您可以frame使用 eg繪制它c(diǎn)v2.putText(),然后繪制它返回的幀而不是frame


編輯:


如果你想為你的網(wǎng)絡(luò)使用部分圖像,你可以像這樣切片圖像:


slicedImg = gray[50:150,50:150]

resizedImg = cv2.resize(slicedImg,(28,28))

label = imageToLabel(resizedImg,yourModel)

如果你不太熟悉 python 中的索引,你可能想看看這個(gè)


此外,如果您希望它看起來(lái)像鏈接視頻中的樣子,您可以繪制一個(gè)從例如 (50,50) 到 (150,150) 的綠色矩形 (0,255,0)


cv2.rectangle(frame,(50,50),(150,150),(0,255,0))


查看完整回答
反對(duì) 回復(fù) 2022-12-20
  • 1 回答
  • 0 關(guān)注
  • 150 瀏覽
慕課專欄
更多

添加回答

舉報(bào)

0/150
提交
取消
微信客服

購(gòu)課補(bǔ)貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動(dòng)學(xué)習(xí)伙伴

公眾號(hào)

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號(hào)