简体   繁体   English

有没有一种从多个帧中提取单个像素的有效方法?

[英]Is there an efficient way of extracting individual pixels from a number of frames?

I am very new to using Python and OpenCV and really struggling to come up with a solution to this problem.我对使用 Python 和 OpenCV 非常陌生,并且真的很难想出解决这个问题的方法。

I have a video/image sequences of length 2500 ie the duration of the video is 5 seconds with a sampling frequency of 500 Hz.我有一个长度为 2500 的视频/图像序列,即视频的持续时间为 5 秒,采样频率为 500 Hz。 I am trying to extract the pixel values of a region of interest that has dimensions of 150x400, therefore I should have 60'000 individual pixels of length 2500.我试图提取尺寸为 150x400 的感兴趣区域的像素值,因此我应该有 60'000 个长度为 2500 的单个像素。

I have loaded in my video and I am trying to loop through the frames to extract each pixel instance along the time domain and store this so I can process it later.我已经加载了我的视频,我正在尝试遍历帧以沿时域提取每个像素实例并存储它,以便我以后可以处理它。

Does anyone have any idea on how to execute this?有没有人知道如何执行这个?

I can provide code for what I have done, but I havent had any success with it so far.我可以为我所做的事情提供代码,但到目前为止我还没有取得任何成功。

All help and suggestions are very much welcome!非常欢迎所有帮助和建议!

Thank you!谢谢!

here's some code that reads a video, takes a ROI from each frame, and stores that in one big array.这是一些读取视频的代码,从每一帧中获取 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()

Thank you all for replying.谢谢大家的回复。 I worked on this today and think I am happy with my solution.我今天对此进行了研究,并认为我对我的解决方案感到满意。 I obviously didnt import a video file but just took the saved frames from a folder on my laptop and then extracted the individual pixels in the time domain.我显然没有导入视频文件,而是从笔记本电脑上的文件夹中取出保存的帧,然后在时域中提取单个像素。 Although, next I will implement your video code @Christopher and clean mine up.虽然,接下来我将实现您的视频代码 @Christopher 并清理我的。 Thank you!谢谢!

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])

""" """

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 从图像中提取单个帧 - Extracting individual frames from an image 从对象数组中提取的有效方法 - Efficient way of extracting from an array of objects 从python中的大量xml文件中提取信息的最有效方法是什么? - What is the most efficient way of extracting information from a large number of xml files in python? 有没有更有效的方法从给定数量的字典值中提取部分和? - Is there a more efficient way of extracting a partial sum from a given number of dictionary values? 如何在pygame中有效地绘制单个像素? - How to make drawing individual pixels efficient in pygame? 从视频中提取帧 - extracting frames from video 从六进制字符串中提取单个位值的有效方法 - Efficient way to extract individual bit values from a hexa string 如何从帧的 ndarray 访问单个像素阵列,或者是否有更好的方法来存储帧并访问它们? - How can I access the individual pixel arrays from an ndarray of frames or is there a better way to store the frames and access them? stream 帧序列的有效方法 - Efficient way to stream a sequence of frames 从 json 文件中提取数据的有效方法。 并将其转化为 dataframe - Efficient way of extracting data, from json file. And transforming it into dataframe
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM