import ffmpeg import numpy import cv2 import sys import jsondef read_frame_by_time(in_file, time):"""指定时间节点读取任意帧"""out, err = (ffmpeg.input(in_file, ss=time).output('pipe:', vframes=1, format='image2', vcodec='mjpeg').run(capture_stdout=True))return outdef get_video_info(in_file):"""获取视频基本信息"""try:probe = ffmpeg.probe(in_file)video_stream = next((stream for stream in probe['streams'] if stream['codec_type'] == 'video'), None)if video_stream is None:print('No video stream found', file=sys.it(1)return video_streamexcept ffmpeg.Error as err:print(str(err.stderr, encoding='utf8'))it(1) def init_mark_result(mark_result):txt = json.load(open(mark_result,encoding= 'utf-8'))['markData']print(len(txt))txt = [item for item in txt if 'currentKey' in item]txts = sorted(txt,key=lambda x:x['currentKey'])return txtsif __name__ == '__main__':result_path = '/Users/xxx/'file_path = '/Users/xxxx/Downloads/xingren20200508_ch0007_00000001056000000_0.mp4'txts = init_mark_result(result_path)print(len(txts))for txt in txts:sss = (int(txt['currentKey']) - 10*25*40) / 1000.0if sss < 0:sss = 0print(sss)print(txt['data'])frame_boxs = txt['data']out = read_frame_by_time(file_path, sss)image_array = numpy.asarray(bytearray(out), dtype="uint8")image = cv2.imdecode(image_array, cv2.IMREAD_COLOR)for box in frame_boxs:x = box['x']y = box['y']w = box['width']h = box['height']print('========')print(box['userSelectedValue']['multiValue'][0]['parentId'])print(box['userSelectedValue']['firstId'])color = (0, 0, angle(image, (int(x), int(y)), (int(x + w), int(y + h)), color, 2)cv2.imshow('frame', image)cv2.waitKey(1000)
本文发布于:2024-02-01 14:30:04,感谢您对本站的认可!
本文链接:https://www.4u4v.net/it/170676900537262.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
留言与评论(共有 0 条评论) |