wangzhifengharrison / HTNet

54 stars 8 forks source link

optical photo #14

Open Maskljh opened 7 months ago

Maskljh commented 7 months ago

The features of the photos I got using the TVL1 method are not obvious.Below is an optical flow feature that I got using casmeii's EP02-01f.How to change to get obvious optical photo? optical_flow_process

ZAMI900384 commented 7 months ago

可能和你的图片预处理有关

Maskljh commented 7 months ago

可能和你的图片预处理有关

我就是读取Cropped文件夹中EP02-01f的第一张和最后一张照片,然后cv2.resized将这两张照片变成224*224,然后使用cv2.optflow.createOptFlow_DualTVL1()获取光流特征图,但是获得的特征图不明显

Maskljh commented 7 months ago

def tvl1_ofcalc(path1, path2,epsilon): origin_photo1=cv2.imread(path1) resized_photo1=cv2.resize(origin_photo1,(224,224)) origin_photo2=cv2.imread(path2) resized_photo2=cv2.resize(origin_photo2,(224,224)) img1 = cv2.cvtColor(resized_photo1, cv2.COLOR_BGR2GRAY) img2 = cv2.cvtColor(resized_photo2, cv2.COLOR_BGR2GRAY)

flow = cv2.optflow.createOptFlow_DualTVL1()
flow.setEpsilon(epsilon)  # 设置epsilon参数的值
of = flow.calc(img1, img2, None)

# flow = cv2.optflow.createOptFlow_DeepFlow()
# of = flow.calc(img1, img2, None)

# of = cv2.optflow.calcOpticalFlowSparseToDense(img1,img2)

# flow = cv2.DISOpticalFlow_create(2)
# of = flow.calc(img1, img2, None)
return of

def minmax_norm(x): x_flat = x.reshape(-1) x_max = np.max(x) x_min = np.min(x) if x_max == x_min: x_flat *= 0 else: x_flat = (x_flat - x_min) / (x_max - x_min) return x_flat.reshape(x.shape)

def calc_os_flow(path1, path2):

调整epsilon参数的值

epsilon = 0.15
flow = tvl1_ofcalc(path1, path2,epsilon)
u_flow = minmax_norm(flow[:, :, 0]) * 255
v_flow = minmax_norm(flow[:, :, 1]) * 255

ux, uy = np.gradient(flow[:, :, 0])
vx, vy = np.gradient(flow[:, :, 1])

os_flow = np.sqrt(ux ** 2 + vy ** 2 + 0.25 * (uy + vx) ** 2)
os_flow = minmax_norm(os_flow) * 255

return np.concatenate(
    (os_flow.reshape(*os_flow.shape, 1), v_flow.reshape(*v_flow.shape, 1), u_flow.reshape(*u_flow.shape, 1)),
    axis=2)

这是我找到的TVL1代码

flamefangz commented 6 months ago

def tvl1_ofcalc(path1, path2,epsilon): origin_photo1=cv2.imread(path1) resized_photo1=cv2.resize(origin_photo1,(224,224)) origin_photo2=cv2.imread(path2) resized_photo2=cv2.resize(origin_photo2,(224,224)) img1 = cv2.cvtColor(resized_photo1, cv2.COLOR_BGR2GRAY) img2 = cv2.cvtColor(resized_photo2, cv2.COLOR_BGR2GRAY)

flow = cv2.optflow.createOptFlow_DualTVL1()
flow.setEpsilon(epsilon)  # 设置epsilon参数的值
of = flow.calc(img1, img2, None)

# flow = cv2.optflow.createOptFlow_DeepFlow()
# of = flow.calc(img1, img2, None)

# of = cv2.optflow.calcOpticalFlowSparseToDense(img1,img2)

# flow = cv2.DISOpticalFlow_create(2)
# of = flow.calc(img1, img2, None)
return of

def minmax_norm(x): x_flat = x.reshape(-1) x_max = np.max(x) x_min = np.min(x) if x_max == x_min: x_flat *= 0 else: x_flat = (x_flat - x_min) / (x_max - x_min) return x_flat.reshape(x.shape)

def calc_os_flow(path1, path2): # 调整epsilon参数的值 epsilon = 0.15 flow = tvl1_ofcalc(path1, path2,epsilon) u_flow = minmax_norm(flow[:, :, 0]) 255 v_flow = minmax_norm(flow[:, :, 1]) 255

ux, uy = np.gradient(flow[:, :, 0])
vx, vy = np.gradient(flow[:, :, 1])

os_flow = np.sqrt(ux ** 2 + vy ** 2 + 0.25 * (uy + vx) ** 2)
os_flow = minmax_norm(os_flow) * 255

return np.concatenate(
    (os_flow.reshape(*os_flow.shape, 1), v_flow.reshape(*v_flow.shape, 1), u_flow.reshape(*u_flow.shape, 1)),
    axis=2)

这是我找到的TVL1代码

请问你的问题解决了吗,我也需要帮助

Maskljh commented 6 months ago

def tvl1_ofcalc(path1, path2,epsilon): origin_photo1=cv2.imread(path1) resized_photo1=cv2.resize(origin_photo1,(224,224)) origin_photo2=cv2.imread(path2) resized_photo2=cv2.resize(origin_photo2,(224,224)) img1 = cv2.cvtColor(resized_photo1, cv2.COLOR_BGR2GRAY) img2 = cv2.cvtColor(resized_photo2, cv2.COLOR_BGR2GRAY)

flow = cv2.optflow.createOptFlow_DualTVL1()
flow.setEpsilon(epsilon)  # 设置epsilon参数的值
of = flow.calc(img1, img2, None)

# flow = cv2.optflow.createOptFlow_DeepFlow()
# of = flow.calc(img1, img2, None)

# of = cv2.optflow.calcOpticalFlowSparseToDense(img1,img2)

# flow = cv2.DISOpticalFlow_create(2)
# of = flow.calc(img1, img2, None)
return of

def minmax_norm(x): x_flat = x.reshape(-1) x_max = np.max(x) x_min = np.min(x) if x_max == x_min: x_flat = 0 else: x_flat = (x_flat - x_min) / (x_max - x_min) return x_flat.reshape(x.shape) def calc_os_flow(path1, path2): # 调整epsilon参数的值 epsilon = 0.15 flow = tvl1_ofcalc(path1, path2,epsilon) u_flow = minmax_norm(flow[:, :, 0]) 255 v_flow = minmax_norm(flow[:, :, 1]) * 255

ux, uy = np.gradient(flow[:, :, 0])
vx, vy = np.gradient(flow[:, :, 1])

os_flow = np.sqrt(ux ** 2 + vy ** 2 + 0.25 * (uy + vx) ** 2)
os_flow = minmax_norm(os_flow) * 255

return np.concatenate(
    (os_flow.reshape(*os_flow.shape, 1), v_flow.reshape(*v_flow.shape, 1), u_flow.reshape(*u_flow.shape, 1)),
    axis=2)

这是我找到的TVL1代码

请问你的问题解决了吗,我也需要帮助

代码可以得到特征图,但是相比于作者给出的数据集,没有那么明显

flamefangz commented 6 months ago

def tvl1_ofcalc(path1, path2,epsilon): origin_photo1=cv2.imread(path1) resized_photo1=cv2.resize(origin_photo1,(224,224)) origin_photo2=cv2.imread(path2) resized_photo2=cv2.resize(origin_photo2,(224,224)) img1 = cv2.cvtColor(resized_photo1, cv2.COLOR_BGR2GRAY) img2 = cv2.cvtColor(resized_photo2, cv2.COLOR_BGR2GRAY)

flow = cv2.optflow.createOptFlow_DualTVL1()
flow.setEpsilon(epsilon)  # 设置epsilon参数的值
of = flow.calc(img1, img2, None)

# flow = cv2.optflow.createOptFlow_DeepFlow()
# of = flow.calc(img1, img2, None)

# of = cv2.optflow.calcOpticalFlowSparseToDense(img1,img2)

# flow = cv2.DISOpticalFlow_create(2)
# of = flow.calc(img1, img2, None)
return of

def minmax_norm(x): x_flat = x.reshape(-1) x_max = np.max(x) x_min = np.min(x) if x_max == x_min: x_flat = 0 else: x_flat = (x_flat - x_min) / (x_max - x_min) return x_flat.reshape(x.shape) def calc_os_flow(path1, path2): # 调整epsilon参数的值 epsilon = 0.15 flow = tvl1_ofcalc(path1, path2,epsilon) u_flow = minmax_norm(flow[:, :, 0]) 255 v_flow = minmax_norm(flow[:, :, 1]) * 255

ux, uy = np.gradient(flow[:, :, 0])
vx, vy = np.gradient(flow[:, :, 1])

os_flow = np.sqrt(ux ** 2 + vy ** 2 + 0.25 * (uy + vx) ** 2)
os_flow = minmax_norm(os_flow) * 255

return np.concatenate(
    (os_flow.reshape(*os_flow.shape, 1), v_flow.reshape(*v_flow.shape, 1), u_flow.reshape(*u_flow.shape, 1)),
    axis=2)

这是我找到的TVL1代码

请问你的问题解决了吗,我也需要帮助

代码可以得到特征图,但是相比于作者给出的数据集,没有那么明显

我的也是,farneback算法和tvl1都试过,还是感觉tvl1得到的光流图更明显一点,但是作者文章中有提到是用farneback算法,不知道怎么解决了,希望你解决后可以回答我,谢谢

Maskljh commented 6 months ago

应该使用的是TVL1,这篇文章的数据集是STSNet的数据集,那篇论文提到的是TVL1 optical 我现在只能得到这样的

flamefangz commented 6 months ago

应该使用的是TVL1,这篇文章的数据集是STSNet的数据集,那篇论文提到的是TVL1 optical 我现在只能得到这样的

image 对比一下,你的比我的明显很多,也确实没有作者的好,可以分享一下你是怎么做的吗,或者加个联系方式

Maskljh commented 6 months ago

应该使用的是TVL1,这篇文章的数据集是STSNet的数据集,那篇论文提到的是TVL1 optical 我现在只能得到这样的

image 对比一下,你的比我的明显很多,也确实没有作者的好,可以分享一下你是怎么做的吗,或者加个联系方式

qq1787033211,TVL1的代码我已经发在前面了,得到的就是这样的结果

KINFEEDUHA commented 3 months ago

请问一下,你们得出来得光流用的是图像对是tvl1flow中的俩个图片吗?

Sheldon-ch commented 3 weeks ago

可能和你的图片预处理有关

我就是读取Cropped文件夹中EP02-01f的第一张和最后一张照片,然后cv2.resized将这两张照片变成224*224,然后使用cv2.optflow.createOptFlow_DualTVL1()获取光流特征图,但是获得的特征图不明显

应该使用起帧率和峰值帧的图像来计算光流特征,而非第一张和最后一张