我正在通过网络摄像头捕获视频,该网络摄像头提供了一个mjpeg流.我在工作线程中进行了视频捕获.我像这样开始捕获:
const std::string videoStreamAddress = "http://192.168.1.173:80/live/0/mjpeg.jpg?x.mjpeg";
qDebug() << "start";
cap.open(videoStreamAddress);
qDebug() << "really started";
cap.set(CV_CAP_PROP_FRAME_WIDTH, 720);
cap.set(CV_CAP_PROP_FRAME_HEIGHT, 576);
Run Code Online (Sandbox Code Playgroud)
摄像机以20fps的速度输入流.但是,如果我像这样以20fps读取:
if (!cap.isOpened()) return;
Mat frame;
cap >> frame; // get a new frame from camera
mutex.lock();
m_imageFrame = frame;
mutex.unlock();
Run Code Online (Sandbox Code Playgroud)
然后有3秒多的延迟.原因是捕获的视频首先存储在缓冲区中.当我第一次启动摄像机时,缓冲区被累积但我没有读出帧.所以如果我从缓冲区读取它总是给我旧帧.我现在唯一的解决方案是以30fps的速度读取缓冲区,这样它就可以快速清理缓冲区并且没有更严重的延迟.
有没有其他可能的解决方案,以便每次启动相机时我都可以手动清理/刷新缓冲区?
我必须拼接从许多 (9) 台相机捕获的图像。最初,我尝试从 2 个相机以 15 FPS 的速率捕获帧。然后,我连接了 4 个摄像头(我还使用了外部供电的 USB 集线器来提供足够的电力)但我只能看到一个流。
为了测试,我使用了以下脚本:
import numpy as np
import cv2
import imutils
index = 0
arr = []
while True:
cap = cv2.VideoCapture(index)
if not cap.read()[0]:
break
else:
arr.append(index)
cap.release()
index += 1
video_captures = [cv2.VideoCapture(idx) for idx in arr]
while True:
# Capture frame-by-frame
frames = []
frames_preview = []
for i in arr:
# skip webcam capture
if i == 1: continue
ret, frame = video_captures[i].read()
if ret:
frames.append(frame) …Run Code Online (Sandbox Code Playgroud) 我在 RasbpberryPI 3 上运行了简单的 python 脚本。这个脚本负责使用 MJPEG 打开视频设备和流数据 (800x600) 到 HTTP 端点。当我收到这个流时,我的一个 rasbpberrypi 核心 100% 工作。可以使用多线程运行 OpenCV 吗?
这是我的代码
import cv2
from BaseHTTPServer import BaseHTTPRequestHandler, HTTPServer
import time
import argparse
import socket as Socket
camera = None
def setUpCameraCV():
global camera
camera = cv2.VideoCapture(0)
class mjpgServer(BaseHTTPRequestHandler):
ip = None
hostname = None
def do_GET(self):
print('connection from:', self.address_string())
if self.ip is None or self.hostname is None:
self.ip, _ = 0.0.0.0
self.hostname = Socket.gethostname()
if self.path == '/mjpg':
self.send_response(200)
self.send_header('Cache-Control', 'no-cache')
self.send_header('Pragma', …Run Code Online (Sandbox Code Playgroud) 我正在使用 cv2.VideoCapture 在 python 脚本中读取 RTSP 视频链接的帧。.read() 函数处于 while 循环中,每秒运行一次,但是,我没有从流中获取最新的帧。我得到了较旧的帧,这样我的滞后就会增加。无论如何,我可以获得最新的帧而不是已通过管道传输到 VideoCapture 对象的旧帧吗?
我正在尝试从 IP 摄像头获取 python 中的视频流,但出现错误。我正在使用 Pycharm IDE。
import cv2
scheme = '192.168.100.23'
host = scheme
cap = cv2.VideoCapture('http://admin:Ebmacs8485867@'+host+':81/web/admin.html')
while True:
ret, frame = cap.read()
# Place options to overlay on the video here.
# I'll go over that later.
cv2.imshow('Camera', frame)
k = cv2.waitKey(0) & 0xFF
if k == 27: # esc key ends process
cap.release()
break
cv2.destroyAllWindows()
Run Code Online (Sandbox Code Playgroud)
import cv2
scheme = '192.168.100.23'
host = scheme
cap = cv2.VideoCapture('http://admin:Ebmacs8485867@'+host+':81/web/admin.html')
while True:
ret, frame = cap.read()
# Place options to overlay …Run Code Online (Sandbox Code Playgroud) 我们正在学校里做一个需要进行基本图像处理的项目。我们的目标是为Raspberry Pi使用每个视频帧并进行实时图像处理。
我们试图将raspistill包含在我们的python程序中,但到目前为止没有任何效果。我们项目的目标是在图像处理的帮助下设计一辆遵循蓝色/红色/任何彩色线条的RC汽车。
我们认为制作一个进行所有图像处理必要的python程序是一个好主意,但是目前我们正努力将记录的图像引入python程序中。有没有办法用picamera做到这一点,还是我们应该尝试其他方式?
对于任何好奇的人,这就是我们程序当前的外观
while True:
#camera = picamera.PiCamera()
#camera.capture('image1.jpg')
img = cv2.imread('image1.jpg')
width = img.shape[1]
height = img.shape[0]
height=height-1
for x in range (0,width):
if x>=0 and x<(width//2):
blue = img.item(height,x,0)
green = img.item(height,x,1)
red = img.item(height,x,2)
if red>green and red>blue:
Run Code Online (Sandbox Code Playgroud)
预先感谢炭疽。