我正在尝试从文件夹中读取图像并获取cv2.DualTVL1OpticalFlow
。
当我在计算光学偏移量后尝试进行着色时,显示此错误,可能是什么原因?为什么在为当前图像和下一幅图像提供路径而对文件夹路径不起作用时,着色flow2bgr_middlebury
是否起作用?
import flow_process
import flow_io
import flow_eval
import os
import pandas as pd
import numpy as np
import random
import cv2
import glob
import sys
packpath = 'C:/Users/Documents/deep_L_projects/optical_flow/'
if not(packpath in sys.path):
sys.path.append(packpath)
from utils.flow_process import flow2bgr_middlebury
from utils.flow_io import read_flo, read_flow_kitti, write_flo
from utils.flow_eval import epe_rate, epe_average
input_path = 'C:/Users/Documents/dev/dev_02/in'
output_path = 'C:/Users/Documents/dev/dev_02/out/'
video_dir = os.listdir(input_path)
for ind in video_dir:
vid_dir = os.path.join(input_path, ind)
save_dir = os.path.join(output_path, ind)
print(vid_dir)
images = glob.glob(os.path.join(vid_dir,'*'))
print ("Processing {}: {} files... ".format(vid_dir, len(images))),
sys.stdout.flush()
img_curr = cv2.cvtColor(cv2.imread(images[0]),cv2.COLOR_BGR2GRAY)
for ret, frames2 in enumerate(images):
img_next = cv2.cvtColor(cv2.imread(frames2),cv2.COLOR_BGR2GRAY)
if len(img_curr.shape) != 2:
img_curr = cv2.cvtColor(img_curr, cv2.COLOR_BGR2GRAY)
img_next = cv2.cvtColor(img_next, cv2.COLOR_BGR2GRAY)
optical_flow = cv2.DualTVL1OpticalFlow_create()
flow = optical_flow.calc(img_curr, img_next, None)
bgr = flow2bgr_middlebury(flow)
cv2.imshow('flow', bgr)
cv2.waitKey(0)
这是错误:
ValueError Traceback (most recent call last)
<ipython-input-9-e5bad81ceb8b> in <module>
52 optical_flow = cv2.DualTVL1OpticalFlow_create()
53 flow = optical_flow.calc(img_curr, img_next, None)
---> 54 bgr = flow2bgr_middlebury(flow)
55 cv2.imshow('flow', bgr)
56
~\Documents\deep_L_projects\optical_flow\utils\flow_process.py in flow2bgr_middlebury(flow)
103 a = np.arctan2(-v[y, x], -u[y, x]) / np.pi
104 fk = (a + 1) / 2 * (ncols - 1)
--> 105 k0 = int(fk)
106 k1 = (k0 + 1) % ncols
107 f = fk - k0
ValueError: cannot convert float NaN to integer