Compare commits
5 Commits
65ee0565c2
...
45db741f35
Author | SHA1 | Date | |
---|---|---|---|
45db741f35 | |||
5df0e15baf | |||
5e72ac28cc | |||
5b61b48d50 | |||
160bb2e365 |
@ -13,7 +13,7 @@ from ultralytics import YOLO
|
||||
|
||||
# 添加YOLOv8模型初始化
|
||||
yolo_model = YOLO("yolov8n.pt") # 可替换为yolov8s/m/l等
|
||||
yolo_model.to('cuda') # 启用GPU加速(可选)
|
||||
yolo_model.to('cuda') # 启用GPU加速
|
||||
|
||||
|
||||
def sift_registration(img1, img2):
|
||||
@ -125,6 +125,7 @@ def Images_matching(img_base, img_target):
|
||||
src_pts = np.array([kp1[m.queryIdx].pt for m in good]) # 查询图像的特征描述子索引 # 134, 2
|
||||
dst_pts = np.array([kp2[m.trainIdx].pt for m in good]) # 训练(模板)图像的特征描述子索引
|
||||
if len(src_pts) <= 4:
|
||||
print("Not enough matches are found - {}/{}".format(len(good), 4))
|
||||
return 0, None, 0
|
||||
else:
|
||||
# print(len(dst_pts), len(src_pts), "配准坐标点")
|
||||
@ -204,38 +205,66 @@ 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))
|
||||
# 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()
|
||||
|
||||
# 转换为灰度图(红外图像处理)
|
||||
frame_gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)
|
||||
# === 新增静态图片测试代码 ===
|
||||
# 输入可见光和红外图像路径
|
||||
visible_path = "../test_images/visible.jpg" # 可见光图片路径
|
||||
infrared_path = "../test_images/infrared.jpg" # 红外图片路径
|
||||
|
||||
# 调用main函数进行融合和检测
|
||||
flag, fusion, dot = main(frame2, frame_gray)
|
||||
# 读取图像
|
||||
img_visible = cv2.imread(visible_path)
|
||||
img_infrared = cv2.imread(infrared_path)
|
||||
|
||||
if flag == 1:
|
||||
# 显示带检测结果的融合图像
|
||||
cv2.imshow("Fusion with YOLOv8 Detection", fusion)
|
||||
out.write(fusion)
|
||||
if img_visible is None or img_infrared is None:
|
||||
print("Error: 图片加载失败,请检查路径!")
|
||||
exit()
|
||||
|
||||
if cv2.waitKey(1) == ord('q'):
|
||||
break
|
||||
# 释放资源
|
||||
capture.release()
|
||||
capture2.release()
|
||||
cv2.destroyAllWindows()
|
||||
ave = time_all / i
|
||||
print(ave, "平均时间")
|
||||
cv2.destroyAllWindows()
|
||||
# 转换为灰度图(红外图像处理)
|
||||
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("融合失败!")
|
||||
|
BIN
image_fusion/yolov8n.pt
Normal file
BIN
image_fusion/yolov8n.pt
Normal file
Binary file not shown.
BIN
output/fusion_result.jpg
Normal file
BIN
output/fusion_result.jpg
Normal file
Binary file not shown.
After Width: | Height: | Size: 152 KiB |
41
requirements.txt
Normal file
41
requirements.txt
Normal file
@ -0,0 +1,41 @@
|
||||
certifi==2025.1.31
|
||||
charset-normalizer==3.4.1
|
||||
colorama==0.4.6
|
||||
contourpy==1.3.2
|
||||
cycler==0.12.1
|
||||
filelock==3.18.0
|
||||
fonttools==4.57.0
|
||||
fsspec==2025.3.2
|
||||
idna==3.10
|
||||
Jinja2==3.1.6
|
||||
kiwisolver==1.4.8
|
||||
MarkupSafe==3.0.2
|
||||
matplotlib==3.10.1
|
||||
mpmath==1.3.0
|
||||
networkx==3.4.2
|
||||
numpy==2.1.1
|
||||
opencv-python==4.11.0.86
|
||||
packaging==24.2
|
||||
pandas==2.2.3
|
||||
pillow==11.2.1
|
||||
psutil==7.0.0
|
||||
py-cpuinfo==9.0.0
|
||||
pyparsing==3.2.3
|
||||
python-dateutil==2.9.0.post0
|
||||
pytz==2025.2
|
||||
PyYAML==6.0.2
|
||||
requests==2.32.3
|
||||
scipy==1.15.2
|
||||
seaborn==0.13.2
|
||||
setuptools==78.1.0
|
||||
six==1.17.0
|
||||
sympy==1.13.1
|
||||
torch==2.6.0+cu124
|
||||
torchaudio==2.6.0+cu124
|
||||
torchvision==0.21.0+cu124
|
||||
tqdm==4.67.1
|
||||
typing_extensions==4.13.2
|
||||
tzdata==2025.2
|
||||
ultralytics==8.3.111
|
||||
ultralytics-thop==2.0.14
|
||||
urllib3==2.4.0
|
BIN
test_images/infrared.jpg
Normal file
BIN
test_images/infrared.jpg
Normal file
Binary file not shown.
After Width: | Height: | Size: 28 KiB |
BIN
test_images/visible.jpg
Normal file
BIN
test_images/visible.jpg
Normal file
Binary file not shown.
After Width: | Height: | Size: 67 KiB |
Loading…
Reference in New Issue
Block a user