我在开发一些三线性插值代码时收到了这个opencv错误1820: error: (-215:Assertion failed)
我想弄清楚这是什么意思
我现在也在想我的编码方法是否适合三线性
还有,有没有办法让flow算法在彩色中工作 而不是灰度?我试了一下颜色,但也收到了类似的错误
在这里下载三帧
代码:
import numpy as np
import cv2
import scipy as sp
Image1_Fp = ".\\3325_71.png" to
Image2_Fp = ".\\3325_72.png" to
Image3_Fp = ".\\3325_73.png" to
Write_Image_Location_Tri_Sampled = ".\\3325_syn_Tri.png"
def imread(filename):
im = cv2.imread(filename)
return im
if __name__ == '__main__':
im1 = imread(Image1_Fp)
im2 = imread(Image2_Fp)
im3 = imread(Image3_Fp)
im3gray = cv2.cvtColor(im3, cv2.COLOR_BGR2GRAY)
im1gray = cv2.cvtColor(im1, cv2.COLOR_BGR2GRAY)
flow = cv2.calcOpticalFlowFarneback(im1gray, im3gray, flow=1, pyr_scale=0.5, levels=2, winsize=10, iterations=5, poly_n=7, poly_sigma=1.2, flags=0)
# Trilinear Interpolation using meshgrid and remap
half_flow = 0.5 * flow # reduce the flow lines all by half.
h, w = flow.shape[:2]
grid_x, grid_y = np.meshgrid(h, w) # Identifies the coordinates of the grid with x, and y value,
coor_x_1 = grid_x + half_flow[:, :, 0] # So the flow is a displacement, and you need to add the pixel location to it to get where that displacement came from on the grid
coor_y_1 = grid_y + half_flow[:, :, 1]
# Finds the interpolated intensity from the pixels closest to the flow line from RGB Image 1
output_1 = cv2.remap(im1, coor_x_1, coor_y_1, cv2.INTER_CUBIC, borderMode =cv2.BORDER_REPLICATE)
coor_x_2 = grid_x - half_flow[:, :, 0]
coor_y_2 = grid_y - half_flow[:, :, 1]
# Finds the interpolated intensity from the pixels closest to the flow line from RGB Image 2
output_2 = cv2.remap(im2, coor_x_2, coor_y_2, cv2.INTER_CUBIC, borderMode =cv2.BORDER_REPLICATE)
# combined half of each
Combined_Output = (output_1 / 2) + (output_2 / 2) # Applies Trilinear part for a synthesized batch
cv2.imwrite(Write_Image_Location_Tri_Sampled, Combined_Output)
我希望看到一个合成的图像,看起来像在两个图像之间的一个,但我收到这个错误
Exception has occurred: error
OpenCV(4.1.0) C:\projects\opencv-python\opencv\modules\imgproc\src\imgwarp.cpp:1820: error: (-215:Assertion failed) ((map1.type() == CV_32FC2 || map1.type() == CV_16SC2) && map2.empty()) || (map1.type() == CV_32FC1 && map2.type() == CV_32FC1) in function 'cv::remap'
File "..\OpenCVOpticalFLowAndTrilinearInterp.py", line 90, in <module>
output_1 = cv2.remap(im1, coor_x_1, coor_y_1, cv2.INTER_CUBIC, borderMode =cv2.BORDER_REPLICATE)
目前没有回答
相关问题 更多 >
编程相关推荐