相关疑难解决方法(0)

在python中保存openCV视频

我正在尝试保存视频,但它无法正常工作.我按照openCV文档中的说明进行操作.

import numpy as np
import cv2

cap = cv2.VideoCapture(0)

fourcc = cv2.VideoWriter_fourcc(*'XVID')
out = cv2.VideoWriter('output.avi', fourcc, 20.0, (640,480))

while(cap.isOpened()):
    ret, frame = cap.read()
    if ret==True:
        frame = cv2.flip(frame,0)


        out.write(frame)

        cv2.imshow('frame',frame)
        if cv2.waitKey(1) & 0xFF == ord('q'):
            break
    else:
        break
cap.release()

out.release()

cv2.destroyAllWindows()
Run Code Online (Sandbox Code Playgroud)

怎么了?

python opencv

33
推荐指数
8
解决办法
7万
查看次数

如何使用 OpenCV 捕获多个摄像头流?

我必须拼接从许多 (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)

python performance multithreading opencv video-streaming

12
推荐指数
1
解决办法
2万
查看次数

来自相机的 Python OpenCV 流 - 多线程,时间戳

我在 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)

python performance multithreading opencv raspberry-pi

8
推荐指数
1
解决办法
1万
查看次数

使用 OpenCV cv2.VideoCapture 在 Python 中从 IP 摄像头流式传输视频

我正在尝试从 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)

python ip opencv rtsp video-streaming

5
推荐指数
1
解决办法
2万
查看次数