簡體   English   中英

將網絡攝像頭與 rasperry pi 4 一起使用

[英]Using webcam with rasperry pi 4

我們已將普通網絡攝像頭連接到樹莓派 4。我編寫了下面的代碼來顯示攝像頭。 相機燈已打開,但沒有顯示。 只是打開了一個空白屏幕。 這是我寫的代碼。 如何顯示相機?

import cv2 as cv

cap = cv.VideoCapture(0)

while True:
   isTrue, frame = cap.read()
   cv.imshow('Video',frame)
   if cv.waitKey(1) & 0xFF == ord('q'): break

cap.release()
cv.destroyAllWindows()

break 的標識不正確:

這個:

while True:
   isTrue, frame = cap.read()
   cv.imshow('Video',frame)
   if cv.waitKey(1) & 0xFF == ord('q'): break

為了:

while True:
   isTrue, frame = cap.read()
   cv.imshow('Video',frame)
   if cv.waitKey(1) & 0xFF == ord('q'): 
      break

所有代碼:

import cv2
import numpy as np

# Create a VideoCapture object and read from input file
# If the input is the camera, pass 0 instead of the video file name
cap = cv2.VideoCapture('chaplin.mp4')

# Check if camera opened successfully
if (cap.isOpened()== False): 
  print("Error opening video stream or file")

# Read until video is completed
while(cap.isOpened()):
  # Capture frame-by-frame
  ret, frame = cap.read()
  if ret == True:

    # Display the resulting frame
    cv2.imshow('Frame',frame)

    # Press Q on keyboard to  exit
    if cv2.waitKey(25) & 0xFF == ord('q'):
      break

  # Break the loop
  else: 
    break

# When everything done, release the video capture object
cap.release()

# Closes all the frames
cv2.destroyAllWindows()

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM