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

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

如何在 Python 中調整一個小的 OpenCV 視頻捕獲窗口的大???

我正在使用 tensorflow 制作剪刀石頭布游戲,用戶可以通過網絡攝像頭玩電腦,但網絡攝像頭圖像太小,如下所示:屏幕截圖這是我使用 OpenCV 的片段:cap = cv2.VideoCapture(0)prev_move = Nonewhile True:    ret, frame = cap.read()    if not ret:        continue    # rectangle for user to play    cv2.rectangle(frame, (100, 100), (500, 500), (255, 255, 255), 2)    # rectangle for computer to play    cv2.rectangle(frame, (800, 100), (1200, 500), (255, 255, 255), 2)    # extract the region of image within the user rectangle    roi = frame[100:500, 100:500]    img = cv2.cvtColor(roi, cv2.COLOR_BGR2RGB)    img = cv2.resize(img, (227, 227))    # predict the move made    pred = model.predict(np.array([img]))    move_code = np.argmax(pred[0])    user_move_name = mapper(move_code)    # predict the winner (human vs computer)    if prev_move != user_move_name:        if user_move_name != "none":            computer_move_name = choice(['rock', 'paper', 'scissors'])            winner = calculate_winner(user_move_name, computer_move_name)        else:            computer_move_name = "none"            winner = "Waiting..."    prev_move = user_move_name    # display the information    font = cv2.FONT_HERSHEY_SIMPLEX    cv2.putText(frame, "Your Move: " + user_move_name,                (50, 50), font, 1.2, (255, 255, 255), 2, cv2.LINE_AA)    cv2.putText(frame, "Computer's Move: " + computer_move_name,                (750, 50), font, 1.2, (255, 255, 255), 2, cv2.LINE_AA)    cv2.putText(frame, "Winner: " + winner,                (400, 600), font, 2, (0, 0, 255), 4, cv2.LINE_AA)    if computer_move_name != "none":        icon = cv2.imread(            "{}.png".format(computer_move_name))        icon = cv2.resize(icon, (400, 400))        frame[100:500, 800:1200] = icon    cv2.imshow("Rock Paper Scissors", frame)    k = cv2.waitKey(10)    if k == ord('q'):        breakcap.release()cv2.destroyAllWindows()我的網絡攝像頭有問題嗎?我嘗試調整框架大小,但它不起作用。
查看完整描述

1 回答

?
Cats萌萌

TA貢獻1805條經驗 獲得超9個贊

您可以使用以下方法調整大?。?/p>


width = 1500

height = 1080

dim = (width, height)


frame = cv2.resize(frame, dim, interpolation=cv2.INTER_AREA)


查看完整回答
反對 回復 2022-12-20
  • 1 回答
  • 0 關注
  • 329 瀏覽
慕課專欄
更多

添加回答

了解更多

舉報

0/150
提交
取消
微信客服

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

幫助反饋 APP下載

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

公眾號

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