首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >GStreamer警告:无法查询视频位置: status=0,值=-1,时长=-1

GStreamer警告:无法查询视频位置: status=0,值=-1,时长=-1
EN

Stack Overflow用户
提问于 2020-07-26 01:43:01
回答 1查看 8.8K关注 0票数 6

我正在使用带有face_recognition包的OpenCV包来检测我笔记本电脑网络摄像头上的人脸。

每当我运行它时,代码都运行得很好,但是我遇到了相同的GStreamer错误。

代码语言:javascript
运行
复制
from imutils.video import VideoStream
import face_recognition
import pickle
import argparse
import time
import cv2
import imutils

ap = argparse.ArgumentParser()
ap.add_argument("-o", "--output", type=str, help="path to output video")
ap.add_argument("-y", "--display", type=int, default=1,
                help="0 to prevent display of frames to screen")
ap.add_argument("-d", "--detection", default="hog",
                type=str, help="Detection method (hog/cnn")
args = vars(ap.parse_args())


print("[INFO] loading encodings...")

data = pickle.load(open("encodings.p", "rb"))

print("[INFO] starting video stream...")
vs = VideoStream().start()
writer = None
time.sleep(3)

while True:

    frame = vs.read()

    rgb = cv2.cvtColor(frame, cv2.COLOR_BGR2RGB)
    rgb = imutils.resize(frame, width=750)
    r = frame.shape[1] / float(rgb.shape[1])

    boxes = face_recognition.face_locations(rgb, model=args["detection"])
    encodings = face_recognition.face_encodings(rgb, boxes)

    for encoding, locations in zip(encodings, boxes):
        matches = face_recognition.compare_faces(data["encodings"], encoding)
        name = "Unknown"
        names = {}

        if True in matches:
            ids = [i for (i, b) in enumerate(matches) if b]
            for i in ids:
                name = data["names"][i]
                names[name] = names.get(name, 0) + 1

            name = max(names, key=names.get)

        for (top, right, bottom, left) in boxes:

            top = int(top * r)
            right = int(right * r)
            bottom = int(bottom * r)
            left = int(left * r)

            cv2.rectangle(frame, (left, top), (right, bottom), (255, 0, 0), 3)
            y = top - 15 if top - 15 > 15 else top + 15
            cv2.putText(frame, name, (left, y),
                        cv2.FONT_HERSHEY_SIMPLEX, 0.75, (255, 0, 0), 2)

    if writer is None and args["output"] is not None:
        fourcc = cv2.VideoWriter_fourcc(*"MJPG")
        writer = cv2.VideoWriter(
            args["output"], fourcc, 20, (frame.shape[1], frame.shape[2]), True)

    if writer is not None:
        writer.write(frame)

    if args["display"] == 1:
        cv2.imshow("frame", frame)
        key = cv2.waitKey(1)

        if key == ord("q"):
            break

cv2.destroyAllWindows()
vs.stop()

if writer is not None:
    writer.release()

我找不到任何问题,但我总是得到这样的错误:

[ WARN:0] global /home/azazel/opencv/modules/videoio/src/cap_gstreamer.cpp (935) open OpenCV | GStreamer warning: Cannot query video position: status=0, value=-1, duration=-1

摄像头仍然显示,面部识别工作正常,但错误意味着什么,我如何修复它?

EN

回答 1

Stack Overflow用户

发布于 2020-11-13 15:47:32

这是一个尝试在OpenCV中使用Gstreamer的bug。在https://github.com/opencv/opencv/issues/10324https://github.com/opencv/opencv/pull/14834中提到了它(在第二个链接中修复)

本质上,这是一个由于Gstreamer读取帧的方式和OpenCV跟踪视频帧的方式而出现的问题。我认为值得尝试添加这行代码并重新构建OpenCV,看看它是否解决了这个问题。

票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/63091548

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档