大佬教程收集整理的这篇文章主要介绍了有没有一种从多个帧中提取单个像素的有效方法?,大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
我对使用 Python 和 OpenCV 非常陌生,并且真的很难找到解决这个问题的方法。
我有一个长度为 2500 的视频/图像序列,即视频的持续时间为 5 秒,采样频率为 500 Hz。我正在尝试提取尺寸为 150x400 的感兴趣区域的像素值,因此我应该有 60'000 个长度为 2500 的单个像素。
我已经加载了我的视频,我正在尝试遍历帧以沿时域提取每个像素实例并存储它,以便我以后可以处理它。
有人知道如何执行此操作吗?
我可以为我所做的事情提供代码,但到目前为止我还没有取得任何成功。
非常欢迎所有帮助和建议!
谢谢!
这是一些读取视频的代码,从每一帧中获取 ROI,并将其存储在一个大数组中。
import numpy as np
import cv2 as cv
cap = cv.VideoCapture("somevideo.mkv")
assert cap.isOpened(),"video can't be opened... is the path correct?"
nframes = int(cap.get(cv.CAP_PROP_FRAME_COUNT))
assert nframes == 2500,f"you said 2500 frames but it's {nframes} frames"
roi_x,roi_y = 12,34 # top left
roi_width,roi_height = 400,150
cube = np.empty((nframes,roi_height,roi_width,3),dtype=np.uint8)
# 3-chAnnel: assuming it's RGB/BGR data,not gray
for i in range(nframes):
rv,frame = cap.read()
assert rv,"video ended before it said it would!"
cube[i] = frame[roi_y:roi_y+roi_height,roi_x:roi_x+roi_width]
cap.release()
,
谢谢大家的回复。我今天对此进行了研究,并认为我对我的解决方案感到满意。我显然没有导入视频文件,而是从笔记本电脑上的文件夹中取出保存的帧,然后在时域中提取单个像素。虽然,接下来我将实现您的视频代码 @Christopher 并清理我的。谢谢!
import numpy as np
import cv2
import glob
### Reading in all of the chessboard files ###
cv_img = []
for img in glob.glob("/Python/OpenCv/Images/chessboard/*.jpg"):
n = cv.imread(img)
cv_img.append(n)
list1 = np.empty((len(cv_img),100,100),dtype=np.uint8)
i = 0
for img in cv_img:
img = img[100:200,100:200]
new_img = cv2.cvtColor(img,cv2.COLOR_BGR2GRAY)
list1[i] = new_img
i = i+1
img = img + 1
column = 0;
pixels_clear = np.ones((1,13)) #no_of_frames,one column 5,1
pixels = np.ones((1,13))
for rows in range(0,100):
column=0
while column < 100:
n_frame = 0
for n_frame in range(0,13):
pixels_clear[0,n_frame] =list1[n_frame,rows,column]
n_frames = n_frames + 1
column = column + 1
pixels = np.vstack([pixels,pixels_clear])
"""
以上是大佬教程为你收集整理的有没有一种从多个帧中提取单个像素的有效方法?全部内容,希望文章能够帮你解决有没有一种从多个帧中提取单个像素的有效方法?所遇到的程序开发问题。
如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。