【发布时间】:2020-06-04 16:48:13
【问题描述】:
import cv2
import numpy as np
cap = cv2.VideoCapture(0)
def threshold_slow(image):
h = image.shape[0]
w = image.shape[1]
for x in range(0, w):
for y in range(0, h):
k = np.array(image[x, y])
print(k)
def video():
while True:
ret,frame = cap.read()
frame = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)
threshold_slow(frame)
cv2.imshow('frame',frame)
key = cv2.waitKey(25)
if key == ord('q'):
break
if __name__ == '__main__':
video()
cap.release()
cv2.destroyAllWindows()
我已经做了我能做的几乎所有事情,但我仍然无法重新爱上它。任何有想法的人请帮助一些代码。当我将 print 放在 for 循环之外时,它工作正常。但后来我没有得到图像中每个像素的值。
【问题讨论】:
-
如果
for循环中的逐像素操作太慢,不要这样做!使用cv2.threshold() -
那么,如果我有这样的情况; k = image[y, x] 如果 140
-
我添加了一个答案,展示了如何快速做到这一点。
标签: python image-processing pixel opencv3.0