版权声明:我是南七小僧,微信: to_my_love ,寻找人工智能相关工作,欢迎交流思想碰撞。 https://blog.csdn.net/qq_25439417/article/details/83832142
# -*- coding: utf-8 -*-
"""
Created on Tue Nov 6 09:49:57 2018
@author: Lenovo
"""
from PIL import Image as Im
import numpy as np
import time
def process_img(img_array):
img = img_array.astype('int')
gimg = np.zeros(img.shape,dtype='int')
# s = time.clock()
for i in range(5,img.shape[0]-5,2):
for j in range(5,img.shape[1]-5,2):
s = np.sum(img[i-5:i,j])
x = np.sum(img[i:i+5,j])
gimg[i,j]= s - x
# e = time.clock()
# print(time.clock()-s)
gimg[gimg<gimg.max()*0.5] = 0
gimg[gimg>=gimg.max()*0.5] = 255
return gimg
#def get_y_point(img_array):
#
# a = np.where(img_array==255)
import cv2 as cv
import matplotlib.pyplot as plt
cap = cv.VideoCapture('WIN_20180831_13_49_39_Pro.mp4')
y_p_list = []
iss,frame = cap.read()
while iss:
iss,frame = cap.read()
if iss:
frame = cv.cvtColor(frame,cv.COLOR_BGR2GRAY)
frame = cv.resize(frame,(120,60))
s = time.clock()
frame_process = process_img(frame)
# a =
e = time.clock()
y_p_list.append(np.where(frame_process==255)[0].mean())
plt.plot(range(len(y_p_list)),y_p_list)
plt.pause(0.0001)
print(e-s)
frame_process = frame_process.astype('uint8')
cv.imshow('22',frame_process)
if cv.waitKey(1) & 0xFF ==ord('q'):
break
cv.destroyAllWindows()