python opencv 视频加快播放_如何使用openCV提高Python中的视频播放速度

这就是问题所在。。。在for x in range(width):

for y in range(height):

if canny[y,x] == 255:

在Numpy.argmax解决方案是。。。在

^{pr2}$

完整代码:import cv2, numpy as np, time

# Get start time

start = time.time()

# Read in the image

img = cv2.imread('/home/stephen/Desktop/rail.jpg')[40:,10:-10]

# Canny filter

canny = cv2.Canny(img, 85, 255)

# Get height and width

height, width = canny.shape

# Create list to store rail points

railPoints = []

# Iterate though each column in the image

for position in range(width-1):

# Slice the relevant column from the image

# The image 'column' is a tall skinny image, only 1px thick

column = np.array(canny[:,position:position+1])

# Use numpy to find the first non-zero value

railPoint = np.argmax(column)

# Add the railPoint to the list of rail points

railPoints.append(railPoint)

# Draw a circle on the image

cv2.circle(img, (position, railPoint), 1, (123,234,123), 2)

cv2.imshow('img', img)

k = cv2.waitKey(1)

cv2.destroyAllWindows()

print(time.time() - start)

我使用Numpy的解决方案需要6毫秒,而您的解决方案需要266毫秒。

你可能感兴趣的:(python,opencv,视频加快播放)