Compare commits
4 Commits
45db741f35
...
0d84bba234
Author | SHA1 | Date | |
---|---|---|---|
0d84bba234 | |||
c81de41b3e | |||
b8ffb902b3 | |||
da36a8fc09 |
1
.gitignore
vendored
1
.gitignore
vendored
@ -297,3 +297,4 @@ Network Trash Folder
|
||||
Temporary Items
|
||||
.apdisk
|
||||
|
||||
/whl_packages/
|
||||
|
@ -1,10 +1,8 @@
|
||||
#!/usr/bin/env python
|
||||
# -*- coding: utf-8 -*-
|
||||
# @Time :
|
||||
# @Author :
|
||||
# @File : Image_Registration_test.py
|
||||
|
||||
import time
|
||||
import argparse
|
||||
|
||||
import cv2
|
||||
import numpy as np
|
||||
@ -128,7 +126,7 @@ def Images_matching(img_base, img_target):
|
||||
print("Not enough matches are found - {}/{}".format(len(good), 4))
|
||||
return 0, None, 0
|
||||
else:
|
||||
# print(len(dst_pts), len(src_pts), "配准坐标点")
|
||||
print(len(dst_pts), len(src_pts), "配准坐标点")
|
||||
H = cv2.findHomography(dst_pts, src_pts, cv2.RANSAC, 4) # 生成变换矩阵 H[0]: 3, 3 H[1]: 134, 1
|
||||
end = time.time()
|
||||
times = end - start
|
||||
@ -201,70 +199,121 @@ def main(matchimg_vi, matchimg_in):
|
||||
return 0, None, 0
|
||||
|
||||
|
||||
def parse_args():
|
||||
# 输入可见光和红外图像路径
|
||||
visible_image_path = "../test/visible.jpg" # 可见光图片路径
|
||||
infrared_image_path = "../test/infrared.jpg" # 红外图片路径
|
||||
# 输入可见光和红外视频路径
|
||||
visible_video_path = "../test/visible.mp4" # 可见光视频路径
|
||||
infrared_video_path = "../test/infrared.mp4" # 红外视频路径
|
||||
|
||||
"""解析命令行参数"""
|
||||
parser = argparse.ArgumentParser(description='图像融合与目标检测')
|
||||
|
||||
parser.add_argument('--mode', type=str, choices=['video', 'image'], default='image',
|
||||
help='输入模式:video(视频流) 或 image(静态图片)')
|
||||
|
||||
# 区分摄像头或视频文件
|
||||
parser.add_argument('--source', type=str, choices=['camera', 'file'],
|
||||
help='视频输入类型:camera(摄像头)或 file(视频文件)')
|
||||
|
||||
# 视频模式参数
|
||||
parser.add_argument('--video1', type=str, default=visible_video_path,
|
||||
help='可见光视频路径(仅在source=file时需要)')
|
||||
parser.add_argument('--video2', type=str, default=infrared_video_path,
|
||||
help='红外视频路径(仅在source=file时需要)')
|
||||
|
||||
# 摄像头模式参数
|
||||
parser.add_argument('--camera_id1', type=int, default=0,
|
||||
help='可见光摄像头ID(仅在source=camera时需要,默认0)')
|
||||
parser.add_argument('--camera_id2', type=int, default=1,
|
||||
help='红外摄像头ID(仅在source=camera时需要,默认1)')
|
||||
parser.add_argument('--output', type=str, default='output.mp4',
|
||||
help='输出视频路径(仅在video模式需要)')
|
||||
|
||||
# 图片模式参数
|
||||
parser.add_argument('--visible', type=str, default=visible_image_path,
|
||||
help='可见光图片路径(仅在image模式需要)')
|
||||
parser.add_argument('--infrared', type=str, default=infrared_image_path,
|
||||
help='红外图片路径(仅在image模式需要)')
|
||||
|
||||
return parser.parse_args()
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
time_all = 0
|
||||
dots = 0
|
||||
i = 0
|
||||
# fourcc = cv2.VideoWriter_fourcc(*'XVID')
|
||||
# capture = cv2.VideoCapture("video/20190926_141816_1_8/20190926_141816_1_8/infrared.mp4")
|
||||
# capture2 = cv2.VideoCapture("video/20190926_141816_1_8/20190926_141816_1_8/visible.mp4")
|
||||
# fps = capture.get(cv2.CAP_PROP_FPS)
|
||||
# out = cv2.VideoWriter('output2.mp4', fourcc, fps, (640, 480))
|
||||
# # 持续读取摄像头数据
|
||||
# while True:
|
||||
# read_code, frame = capture.read() # 红外帧
|
||||
# read_code2, frame2 = capture2.read() # 可见光帧
|
||||
# if not read_code:
|
||||
# break
|
||||
# i += 1
|
||||
# # frame = cv2.resize(frame, (1920, 1080))
|
||||
# # frame2 = cv2.resize(frame2, (640, 512))
|
||||
#
|
||||
# # 转换为灰度图(红外图像处理)
|
||||
# frame_gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)
|
||||
#
|
||||
# # 调用main函数进行融合和检测
|
||||
# flag, fusion, dot = main(frame2, frame_gray)
|
||||
#
|
||||
# if flag == 1:
|
||||
# # 显示带检测结果的融合图像
|
||||
# cv2.imshow("Fusion with YOLOv8 Detection", fusion)
|
||||
# out.write(fusion)
|
||||
#
|
||||
# if cv2.waitKey(1) == ord('q'):
|
||||
# break
|
||||
# # 释放资源
|
||||
# capture.release()
|
||||
# capture2.release()
|
||||
# cv2.destroyAllWindows()
|
||||
# ave = time_all / i
|
||||
# print(ave, "平均时间")
|
||||
# cv2.destroyAllWindows()
|
||||
args = parse_args()
|
||||
|
||||
# === 新增静态图片测试代码 ===
|
||||
# 输入可见光和红外图像路径
|
||||
visible_path = "../test_images/visible.jpg" # 可见光图片路径
|
||||
infrared_path = "../test_images/infrared.jpg" # 红外图片路径
|
||||
if args.mode == 'video':
|
||||
if args.source == 'file':
|
||||
# ========== 视频流处理模式 ==========
|
||||
if not args.video1 or not args.video2:
|
||||
raise ValueError("视频模式需要指定 --video1 和 --video2 参数")
|
||||
capture = cv2.VideoCapture(args.video2)
|
||||
capture2 = cv2.VideoCapture(args.video1)
|
||||
elif args.source == 'camera':
|
||||
# ========== 摄像头处理模式 ==========
|
||||
capture = cv2.VideoCapture(args.camera_id1)
|
||||
capture2 = cv2.VideoCapture(args.camera_id2)
|
||||
else:
|
||||
raise ValueError("必须指定 --source 参数(camera 或 file)")
|
||||
|
||||
# 读取图像
|
||||
img_visible = cv2.imread(visible_path)
|
||||
img_infrared = cv2.imread(infrared_path)
|
||||
# 公共视频处理逻辑
|
||||
fps = capture.get(cv2.CAP_PROP_FPS) if args.source == 'file' else 30
|
||||
fourcc = cv2.VideoWriter_fourcc(*'XVID')
|
||||
out = cv2.VideoWriter(args.output, fourcc, fps, (640, 480))
|
||||
|
||||
if img_visible is None or img_infrared is None:
|
||||
print("Error: 图片加载失败,请检查路径!")
|
||||
exit()
|
||||
while True:
|
||||
ret1, frame_vi = capture.read() # 可见光帧
|
||||
ret2, frame_ir = capture2.read() # 红外帧
|
||||
if not ret1 or not ret2:
|
||||
break
|
||||
|
||||
# 转换为灰度图(红外图像处理)
|
||||
img_inf_gray = cv2.cvtColor(img_infrared, cv2.COLOR_BGR2GRAY)
|
||||
# 红外图像转灰度
|
||||
frame_ir_gray = cv2.cvtColor(frame_ir, cv2.COLOR_BGR2GRAY)
|
||||
|
||||
# 执行融合与检测
|
||||
flag, fusion_result, _ = main(img_visible, img_inf_gray)
|
||||
# 执行融合与检测
|
||||
flag, fusion, _ = main(frame_vi, frame_ir_gray)
|
||||
|
||||
if flag == 1:
|
||||
# 显示并保存结果
|
||||
cv2.imshow("Fusion with Detection", fusion_result)
|
||||
cv2.imwrite("../output/fusion_result.jpg", fusion_result)
|
||||
cv2.waitKey(0)
|
||||
if flag == 1:
|
||||
cv2.imshow("Fusion with YOLOv8 Detection", fusion)
|
||||
out.write(fusion)
|
||||
|
||||
if cv2.waitKey(1) == ord('q'):
|
||||
break
|
||||
|
||||
# 释放资源
|
||||
capture.release()
|
||||
capture2.release()
|
||||
out.release()
|
||||
cv2.destroyAllWindows()
|
||||
else:
|
||||
print("融合失败!")
|
||||
|
||||
elif args.mode == 'image':
|
||||
# ========= 图片处理模式 ==========
|
||||
if not args.infrared or not args.visible:
|
||||
raise ValueError("图片模式需要指定 --visible 和 --infrared 参数")
|
||||
|
||||
# 读取图像
|
||||
img_visible = cv2.imread(args.visible)
|
||||
img_infrared = cv2.imread(args.infrared)
|
||||
|
||||
if img_visible is None or img_infrared is None:
|
||||
print("Error: 图片加载失败,请检查路径!")
|
||||
exit()
|
||||
|
||||
# 转换为灰度图(红外图像处理)
|
||||
img_inf_gray = cv2.cvtColor(img_infrared, cv2.COLOR_BGR2GRAY)
|
||||
|
||||
# 执行融合与检测
|
||||
flag, fusion_result, _ = main(img_visible, img_inf_gray)
|
||||
|
||||
if flag == 1:
|
||||
# 显示并保存结果
|
||||
cv2.imshow("Fusion with Detection", fusion_result)
|
||||
cv2.imwrite("../output/fusion_result.jpg", fusion_result)
|
||||
cv2.waitKey(0)
|
||||
cv2.destroyAllWindows()
|
||||
else:
|
||||
print("融合失败!")
|
||||
|
Before Width: | Height: | Size: 28 KiB After Width: | Height: | Size: 28 KiB |
Before Width: | Height: | Size: 67 KiB After Width: | Height: | Size: 67 KiB |
Loading…
Reference in New Issue
Block a user