【问题标题】:How to find value of each pixel in all the frames of a video using python如何使用python查找视频所有帧中每个像素的值
【发布时间】:2021-09-17 06:16:30
【问题描述】:

我有一个尺寸为 1280、720 和 166 帧的视频。现在我想跟踪给定位置的每个像素的值。就像在位置 (100, 100) 一样,我想在所有 166 帧中获取该位置的像素值。这会给我 166 的价值。

同样,我想找到帧中所有位置的像素值。然后为每个像素的所有值逐一拟合曲线。

这是我写的代码,但是只能获取指定位置的像素值。

cap= cv2.VideoCapture('video.mp4')
success, image = cap.read()
count = 0
while success:
  count += 1
  v = image[500, 700]
  s = sum(v)/len(v)
  print(" Count {}  Pixel at (500, 700) - Value {} ".format(count,v))
  success, image = cap.read()
cap.release()
cv2.destroyAllWindows()

我也尝试使用框架的宽度和高度,但它随机读取位置,我希望它们按顺序存储,因为我想为它们中的每一个绘制一个图表:

while success:
  count += 1
  for x in range(0,width):
    for y in range(0,height):
      print(image[x,y,z])

那么我必须在这段代码中进行哪些更改才能获取所有值。

【问题讨论】:

  • 我见过你问过这样的问题。 numpy 的教程可能会对您有很大帮助。
  • 我是新手,这就是我问这些问题的原因。感谢您的建议。

标签: python opencv video-processing


【解决方案1】:
cap= cv2.VideoCapture('video.mp4')
success, image = cap.read()
count = 0
while success:
  count += 1
  print("{}th image from the movie ".format(count))
  for x in range(0,1280-1):
      for y in range(0,720-1):
          v = image[y, x]
          print("Pixel at ({}, {}) - Value {} ".format(x,y,v))
  success, image = cap.read()
cap.release()
cv2.destroyAllWindows()

【讨论】:

  • 谢谢!但是这段代码再次给了我 500、700 处的像素值。我想找到所有位置的值,而不仅仅是一个。
  • 你想得到平均图像吗?
  • 是的,并且对于每个像素单独的所有帧
  • 非常感谢您的回答我理解我的错误!
  • 我收到此错误:IndexError: index 720 is out of the bounds for axis 0 with size 720 in line v = image[x, y] afterreaching (719, 718) for the first frame
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2017-05-11
  • 2023-04-02
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多