print AVG Depth and Motion
1
.gitignore
vendored
@ -330,3 +330,4 @@ ASALocalRun/
|
||||
.mfractor/
|
||||
/1.png
|
||||
/vid
|
||||
/pic
|
||||
|
6
MV.py
@ -8,7 +8,7 @@ prvs = cv.cvtColor(frame1, cv.COLOR_BGR2GRAY)
|
||||
hsv = np.zeros_like(frame1)
|
||||
hsv[..., 1] = 255
|
||||
print("jump ahead")
|
||||
cap.set(cv.CAP_PROP_POS_FRAMES, 59760)
|
||||
cap.set(cv.CAP_PROP_POS_FRAMES, 12000)
|
||||
print("jump done")
|
||||
|
||||
while(1):
|
||||
@ -22,9 +22,9 @@ while(1):
|
||||
hsv[..., 0] = ang*180/np.pi/2
|
||||
hsv[..., 2] = cv.normalize(mag, None, 0, 255, cv.NORM_MINMAX)
|
||||
bgr = cv.cvtColor(hsv, cv.COLOR_HSV2BGR)
|
||||
cv.namedWindow("frame2", cv.WINDOW_NORMAL)
|
||||
cv.namedWindow("MotionVector", cv.WINDOW_NORMAL)
|
||||
cv.namedWindow("frame", cv.WINDOW_NORMAL)
|
||||
cv.imshow('frame2', bgr)
|
||||
cv.imshow('MotionVector', bgr)
|
||||
cv.imshow("frame", frame2)
|
||||
cv.waitKey(1)
|
||||
#k = cv.waitKey(0.1) & 0xff
|
||||
|
@ -6,10 +6,18 @@ import os
|
||||
import sys
|
||||
from matplotlib import pyplot as plt
|
||||
|
||||
'''
|
||||
TODO:
|
||||
0:读取视频 √
|
||||
1:获取视差 √
|
||||
2:获取运动矢量 √
|
||||
3:确定舒适度
|
||||
4:加舒适度水印
|
||||
...
|
||||
'''
|
||||
|
||||
def openVid():
|
||||
fileName = "./vid/zootopia.mkv"
|
||||
#fileName = input("video path:")
|
||||
fileName = input("video path:")
|
||||
while not os.path.isfile(fileName):
|
||||
print("file doesn't exist!")
|
||||
fileName = input("video path:")
|
||||
@ -41,16 +49,26 @@ if __name__ == "__main__":
|
||||
cap = openVid()
|
||||
frameRate = getFrameRate(cap)
|
||||
frameCount = getFrameCount(cap)
|
||||
ret, img = cap.read()
|
||||
|
||||
isSuccess, img = cap.read()
|
||||
if not isSuccess:
|
||||
print("video read error.")
|
||||
sys.exit()
|
||||
|
||||
imgL = np.split(img, 2, 1)[0]
|
||||
imgR = np.split(img, 2, 1)[1]
|
||||
prvs = cv2.cvtColor(imgR, cv2.COLOR_BGR2GRAY)
|
||||
hsv = np.zeros_like(imgR)
|
||||
hsv[..., 1] = 255
|
||||
cap.set(cv2.CAP_PROP_POS_FRAMES,12000)
|
||||
for frameID in range(int(cap.get(cv2.CAP_PROP_POS_FRAMES)), int(frameCount), int(frameRate/2)):
|
||||
|
||||
cap.set(cv2.CAP_PROP_POS_FRAMES,52000)
|
||||
|
||||
for frameID in range(int(cap.get(cv2.CAP_PROP_POS_FRAMES)), int(frameCount), int(frameRate/4)):
|
||||
cap.set(cv2.CAP_PROP_POS_FRAMES, frameID)
|
||||
isSuccess, img = cap.read()
|
||||
if isSuccess:
|
||||
if not isSuccess:
|
||||
print("video read error.")
|
||||
sys.exit()
|
||||
|
||||
imgL = np.split(img, 2, 1)[0]
|
||||
imgR = np.split(img, 2, 1)[1]
|
||||
@ -61,20 +79,26 @@ if __name__ == "__main__":
|
||||
hsv[..., 2] = cv2.normalize(mag, None, 0, 255, cv2.NORM_MINMAX)
|
||||
bgr = cv2.cvtColor(hsv, cv2.COLOR_HSV2BGR)
|
||||
|
||||
cv2.namedWindow("imgR", cv2.WINDOW_NORMAL)
|
||||
cv2.imshow('imgR', imgR)
|
||||
cv2.namedWindow("img", cv2.WINDOW_NORMAL)
|
||||
cv2.imshow('img', img)
|
||||
cv2.namedWindow("MotionVector",cv2.WINDOW_NORMAL)
|
||||
cv2.imshow("MotionVector",bgr)
|
||||
prvs = next
|
||||
|
||||
|
||||
stereo = cv2.StereoSGBM_create(numDisparities=96, blockSize=11)
|
||||
disparity = stereo.compute(imgL, imgR)
|
||||
print("time: ", frameID/frameRate)
|
||||
print("AVG depth: ",np.mean(disparity))
|
||||
print("AVG motion: ",np.mean(hsv[...,2]))
|
||||
print()
|
||||
cv2.waitKey(1)
|
||||
#cv2.waitKey(1)
|
||||
plt.title("DepthMap")
|
||||
plt.imshow(disparity)
|
||||
plt.pause(0.5)
|
||||
else:
|
||||
print("video read error")
|
||||
#plt.title("DepthMap")
|
||||
#plt.imshow(disparity)
|
||||
#plt.pause(0.5)
|
||||
|
||||
|
||||
print("success")
|
||||
|
||||
|
||||
|
22
picMV.py
Normal file
@ -0,0 +1,22 @@
|
||||
import cv2 as cv
|
||||
import numpy as np
|
||||
|
||||
img = cv.imread("./pic/2.jpg")
|
||||
imgL = np.split(img, 2, 1)[0]
|
||||
imgR = np.split(img, 2, 1)[1]
|
||||
|
||||
prvs = cv.cvtColor(imgL, cv.COLOR_BGR2GRAY)
|
||||
hsv = np.zeros_like(imgL)
|
||||
hsv[..., 1] = 255
|
||||
|
||||
next = cv.cvtColor(imgR, cv.COLOR_BGR2GRAY)
|
||||
flow = cv.calcOpticalFlowFarneback(prvs, next, None, 0.5, 3, 15, 3, 5, 1.2, 0)
|
||||
mag, ang = cv.cartToPolar(flow[..., 0], flow[..., 1])
|
||||
hsv[..., 0] = ang*180/np.pi/2
|
||||
hsv[..., 2] = cv.normalize(mag, None, 0, 255, cv.NORM_MINMAX)
|
||||
bgr = cv.cvtColor(hsv, cv.COLOR_HSV2BGR)
|
||||
cv.namedWindow("MotionVector", cv.WINDOW_NORMAL)
|
||||
cv.namedWindow("frame", cv.WINDOW_NORMAL)
|
||||
cv.imshow('MotionVector', bgr)
|
||||
cv.imshow("frame", img)
|
||||
cv.waitKey(100)
|
BIN
pic_en/1.jpg
Before Width: | Height: | Size: 395 KiB |
BIN
pic_en/10.jpg
Before Width: | Height: | Size: 527 KiB |
BIN
pic_en/2.jpg
Before Width: | Height: | Size: 594 KiB |
BIN
pic_en/3.jpg
Before Width: | Height: | Size: 165 KiB |
BIN
pic_en/4.jpg
Before Width: | Height: | Size: 922 KiB |
BIN
pic_en/5.jpg
Before Width: | Height: | Size: 924 KiB |
BIN
pic_en/6.jpg
Before Width: | Height: | Size: 1.0 MiB |
BIN
pic_en/7.jpg
Before Width: | Height: | Size: 417 KiB |
BIN
pic_en/8.jpg
Before Width: | Height: | Size: 653 KiB |
BIN
pic_en/9.jpg
Before Width: | Height: | Size: 238 KiB |