前言
本文記錄在云服務(wù)器autodl上選擇安裝cuda、cudnn開始,部署相同視角、相同時(shí)間、相同地點(diǎn)拍攝的紅外和可見光圖像數(shù)據(jù)集OTCBVS在Github目前開源的圖像融合PIAFusion、目標(biāo)檢測Yolo-v4、目標(biāo)跟蹤DeepSort算法上實(shí)現(xiàn)單數(shù)據(jù)集貫通。
本文只做到以下幾點(diǎn):
1、列舉常見紅外-可見光圖像數(shù)據(jù)集及其特征。
2、僅提供在云服務(wù)器上部署實(shí)現(xiàn)的流程經(jīng)驗(yàn)。
本文不提供以下幾點(diǎn):
1、不對算法做任何優(yōu)化,也不討論最后的圖像結(jié)果。如果需要,可以自行加入創(chuàng)新點(diǎn)去發(fā)揮。
2、不討論任何指標(biāo)。
3、對開源的其他圖像融合、目標(biāo)檢測、目標(biāo)跟蹤算法不做調(diào)研。
本文較為基礎(chǔ),只是因?yàn)檎{(diào)研了CSDN上罕有分享整個(gè)過程打通的技術(shù)實(shí)現(xiàn),嗶哩嗶哩上也僅提供實(shí)現(xiàn)后的結(jié)果,不少up主為了一鍵三連不公開源碼。筆者在公開的源碼上提供整個(gè)技術(shù)實(shí)現(xiàn)參考。
一、任務(wù)概述
無人機(jī)上常采用多相機(jī)拍攝的方式獲取目標(biāo)特征,這是因?yàn)榧t外相機(jī)和可見光相機(jī)拍攝得到的圖片有各自的特征顯示優(yōu)勢。紅外相機(jī)通過目標(biāo)物和背景之間的溫差使得目標(biāo)物可以被顯著標(biāo)記,同時(shí)也具備一定的紋理特征,可以比較好地觀測到白天陰影中的目標(biāo)和夜間目標(biāo);而可見光相機(jī)拍攝得到的圖片由于突出的邊緣信息,具備更多的紋理特征,但對于陰影、黑夜中的人物不具備很好的信息表達(dá)性。多模態(tài)圖像融合通過提取紅外的顯著特征和可見光的紋理特征,根據(jù)靈活的特征融合規(guī)則將紅外特征和可見光特征融合,最后使用圖像重建將融合特征重建為圖片。無人機(jī)通過目標(biāo)識別和定位對信息量更為豐富的融合圖片處理分析,得到目標(biāo)物的位置和類別。隨后根據(jù)需要,標(biāo)記感興趣目標(biāo)物進(jìn)行目標(biāo)跟蹤(目標(biāo)跟蹤是在相鄰兩幀圖片中對目標(biāo)物的進(jìn)行定位和識別,可對目標(biāo)接下來的運(yùn)動進(jìn)行預(yù)測,屬于中級計(jì)算機(jī)視覺任務(wù))。目標(biāo)跟蹤得到的感興趣目標(biāo)的位置,將其反饋到無人機(jī)視覺伺服模塊,調(diào)整無人機(jī)機(jī)身姿態(tài)、速度,可定向追蹤目標(biāo)物。
無人機(jī)通過紅外相機(jī)和可見光相機(jī)拍攝,無法做到兩臺相機(jī)是從同一視覺拍攝的,這一塊涉及圖像配準(zhǔn)。由于尚沒找到可利用的公開數(shù)據(jù)集,暫時(shí)不考慮圖像配準(zhǔn)的任務(wù)。視覺伺服模塊屬于控制類模塊,不屬于我們要解決的范疇,因此也不考慮在內(nèi)。
二、常見紅外-可見光圖像數(shù)據(jù)集
2.1 OTCBVS
包含16個(gè)子類的紅外和可見光圖片數(shù)據(jù)集(本次使用OTCBVS的第2個(gè)子類中的一部分),第2個(gè)子類的信息:總大小為1.83 GB,圖像尺寸為320 x 240 像素(可見和熱成像),4228對熱圖像和可見圖像。
鏈接:http://vcipl-okstate.org/pbvs/bench/
2.2 TNO image fusion dataset
包含軍隊(duì)夜間場景相關(guān)的多光譜如近紅外、遠(yuǎn)紅外、可見光的圖像,圖像尺寸為768 × 576像素。
鏈接:https://figshare.com/articles/dataset/TNO_Image_Fusion_Dataset/1008029
2.3 INO image fusion dataset
包含多天氣、夜間條件下的彩色、紅外圖像,圖像尺寸為328×254像素。
鏈接:http://www.ino.ca/en/video-analytics-dataset/
2.4 Eden Project Multi-Sensor Dataset
圖像尺寸為560×468像素
鏈接:http://www.cis.rit.edu/pelz/scanpaths/data/bristol-eden.htm
三、圖像融合
3.1 開源圖像融合算法PIAFusion
PIAFusion是2022年發(fā)表在融合領(lǐng)域頂刊《Information Fusion》上的圖像融合算法
鏈接:https://github.com/Linfeng-Tang/PIAFusion
文章:《PIAFusion: A progressive infrared and visible image fusion network based on illumination aware》
3.2 安裝環(huán)境及相關(guān)包版本
考慮到云服務(wù)器在配置上的便捷性,我們采用市面上實(shí)惠的云服務(wù)器autodl配置圖像融合。后期可以考慮對配置好的環(huán)境進(jìn)行鏡像遷移,便于實(shí)現(xiàn)在NVIDIA不同算力顯卡上的測試。
cuda和cuDNN版本如下:
cuDNN7.4
cuda10.0
其他庫的安裝版本
tensorflow-gpu==1.14.0
opencv-python==3.4.2.17
scipy==1.2.0
numpy==1.19.2
pandas==1.1.5
openpyxl==3.0.10
protobuf==3.19.0
cuda和cuDNN與其他庫選擇版本的依據(jù)可參考下面幾張圖
然而autodl官網(wǎng)并不直接提供上述cuda和cuDNN版本鏡像,因此需要我們自行安裝。我們首先選擇RTX2080卡,選擇TensorFlow1.15.5,Python3.8,cuda11.4的鏡像。
3.2.1 檢查(安裝)NVIDIA驅(qū)動
nvidia-smi
得到如下
Sun Jul 31 15:04:41 2022
+-----------------------------------------------------------------------------+
| NVIDIA-SMI 495.44 Driver Version: 495.44 CUDA Version: 11.5 |
|-------------------------------+----------------------+----------------------+
| GPU Name Persistence-M| Bus-Id Disp.A | Volatile Uncorr. ECC |
| Fan Temp Perf Pwr:Usage/Cap| Memory-Usage | GPU-Util Compute M. |
| | | MIG M. |
|===============================+======================+======================|
| 0 NVIDIA GeForce ... On | 00000000:1A:00.0 Off | N/A |
| 54% 47C P8 5W / 250W | 0MiB / 11019MiB | 0% Default |
| | | N/A |
+-------------------------------+----------------------+----------------------+
+-----------------------------------------------------------------------------+
| Processes: |
| GPU GI CI PID Type Process name GPU Memory |
| ID ID Usage |
|=============================================================================|
| No running processes found |
+-----------------------------------------------------------------------------+
我們只需重點(diǎn)關(guān)注驅(qū)動版本為495.44,支持CUDA最高版本到11.5,如果輸出信息,表明已經(jīng)安裝了NVIDIA驅(qū)動,如果需要在自己筆記本上安裝驅(qū)動,另外找驅(qū)動安裝教程。
3.2.2 檢查(安裝)cuda和cuDNN版本
檢查cuda使用
nvcc -V
輸出
Copyright (c) 2005-2018 NVIDIA Corporation
Built on Sat_Aug_25_21:08:01_CDT_2018
Cuda compilation tools, release 10.0, V10.0.130
驗(yàn)證cuda版本為10.0
檢查cuDNN使用
cat /usr/local/cuda/include/cudnn.h | grep CUDNN_MAJOR -A2
輸出
#define CUDNN_MAJOR 7
#define CUDNN_MINOR 4
#define CUDNN_PATCHLEVEL 1
--
#define CUDNN_VERSION (CUDNN_MAJOR * 1000 + CUDNN_MINOR * 100 + CUDNN_PATCHLEVEL)
#include "driver_types.h"
驗(yàn)證cuDNN版本為7.4.1
這是我安裝后的結(jié)果,如果需要安裝,參考下面幾個(gè)步驟
3.2.2.1 官網(wǎng)下載cuda
鏈接:https://developer.nvidia.com/cuda-toolkit-archive
下載.run格式的安裝包后:
chmod 777 cuda_10.0.130_410.48_linux.run # 修改權(quán)限使其可運(yùn)行
./cuda_10.0.130_410.48_linux.run --override # 運(yùn)行安裝包
添加到環(huán)境變量中
echo "export PATH=/usr/local/cuda-10.0/bin:${PATH} \n" >> ~/.bashrc
echo "export LD_LIBRARY_PATH=/usr/local/cuda/lib64/:${LD_LIBRARY_PATH} \n" >> ~/.bashrc
使用以下讓環(huán)境變量生效
source ~/.bashrc
3.2.2.2 確認(rèn)cuda是否安裝成功
重啟后,使用
nvcc -V
如果順利輸出cuda版本號,表明已經(jīng)安裝成功。
如果需要額外測試cuda功能,可以
cd /usr/local/cuda-10.0/samples/1_Utilities/deviceQuery
make
./deviceQuery
輸出
......
deviceQuery, CUDA Driver = CUDART, CUDA Driver Version = 11.5, CUDA Runtime Version = 10.0, NumDevs = 1
Result = PASS
3.2.2.3 官網(wǎng)下載cuDNN
鏈接:https://developer.nvidia.com/cudnn
mv cuda/include/* /usr/local/cuda/include/
chmod +x cuda/lib64/* && mv cuda/lib64/* /usr/local/cuda/lib64/
使用以下使其生效
ldconfig
3.2.2.4 驗(yàn)證GPU是否可以利用
import tensorflow as tf
print(tf.test.is_gpu_available())
輸出
......
2022-07-31 15:26:53.092539: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1326] Created TensorFlow device (/device:GPU:0 with 10322 MB memory) -> physical GPU (device: 0, name: NVIDIA GeForce RTX 2080 Ti, pci bus id: 0000:1a:00.0, compute capability: 7.5)
True
表明GPU可被調(diào)用
3.2.3 安裝環(huán)境
建議使用我上方提供的版本去更新源碼提供的requirements.txt
pip install -r requirements.txt
3.3 下載數(shù)據(jù)集并批量化修改圖片名
數(shù)據(jù)集選擇OTCBVS的第二個(gè)子數(shù)據(jù)集,我列舉了該數(shù)據(jù)集第一張紅外-可見圖片組,可以直觀地看出紅外圖片和可見光圖片之間的差別。
圖像融合PIAFusion源碼對圖片名稱有要求,可以使用下面去批量修改文件名。
import os
dirpath_top = os.path.dirname(os.path.abspath(__file__))
filelist_name = "OCTBVS0312"
filelist_se1 = "ir"
filelist_se2 = "vi"
otcbvs_path1 =os.path.join(dirpath_top, filelist_name, filelist_se1)
otcbvs_path2 =os.path.join(dirpath_top, filelist_name, filelist_se2)
#print(otcbvs_path1)
otcbvsir = os.listdir(otcbvs_path1)
otcbvsvi = os.listdir(otcbvs_path2)
#print(otcbvsir)
i=0
for item in otcbvsir:
if item.endswith('.bmp'):
src = os.path.join(os.path.abspath(otcbvs_path1), item) #原本的名稱
dst = os.path.join(os.path.abspath(otcbvs_path1), str(i).zfill(4) + '.bmp') #這里我把格式統(tǒng)一改成了 .jpg
try:
os.rename(src, dst) #意思是將 src 替換為 dst
i+=1
print('rename from %s to %s' % (src, dst))
except:
continue
print('ending...')
i=0
for item in otcbvsvi:
if item.endswith('.bmp'):
src = os.path.join(os.path.abspath(otcbvs_path2), item)
dst = os.path.join(os.path.abspath(otcbvs_path2), str(i).zfill(4) + '.bmp')
try:
os.rename(src, dst)
i+=1
print('rename from %s to %s' % (src, dst))
except:
continue
print('ending...')
3.4 運(yùn)行PIAFusion
為方便,可以將OTCBVS名稱修改為TNO,放在測試數(shù)據(jù)中,運(yùn)行
python main.py --is_train=False model_type=PIAFusion --DataSet=TNO
也可以在相關(guān)文件里面添加argparse項(xiàng)。懶人用上面那個(gè)方法就行了!
就可以將600對紅外-可見光圖片融合,下圖是融合后的圖片
3.5 融合后圖片做成視頻
import numpy as np
import cv2
import os
size = (320,240)
print("每張圖片的大小為({},{})".format(size[0],size[1]))
dirpath_top = os.path.dirname(os.path.abspath(__file__))
src_path = os.path.join(dirpath_top,"OTCBVS")
sav_path = os.path.join(dirpath_top,"OTCBVS.mp4")
all_files = os.listdir(src_path)
index = len(all_files)
print("圖片總數(shù)為:" + str(index) + "張")
fourcc = cv2.VideoWriter_fourcc(*'mp4v')#MP4格式
videowrite = cv2.VideoWriter(sav_path,fourcc,20,size)#2是每秒的幀數(shù),size是圖片尺寸
img_array=[]
tmp_name_list = []
for i in range(0,index):
tmp_i=str(i).zfill(4)
tmp_name_list.append(os.path.join(src_path,r'{0}.bmp'.format(tmp_i)))
#for filename in [src_path + r'{0}.bmp'.format(i) for i in tmp_name]:
for filename in tmp_name_list:
img = cv2.imread(filename)
if img is None:
print(filename + " is error!")
continue
img_array.append(img)
for i in range(0,index):
img_array[i] = cv2.resize(img_array[i],(320,240))
videowrite.write(img_array[i])
print('第{}張圖片合成成功'.format(i))
print('------done!!!-------')
視頻效果
OTCBVS-fusedresults
四、目標(biāo)檢測和目標(biāo)跟蹤
4.1 開源目標(biāo)檢測和跟蹤算法Yolo-v4&DeepSort
Yolo-v4
鏈接:https://github.com/AlexeyAB/darknet
DeepSort
鏈接:https://github.com/ZQPei/deep_sort_pytorch
我們使用封裝好的Yolo-v4和DeepSort
https://github.com/TsMask/deep-sort-yolov4
4.2 使用圖像融合后得到的視頻作為目標(biāo)檢測和跟蹤的輸入
運(yùn)行
python detect_video_tracker.py --video OTCBVS.mp4 --min_score 0.3 --model_yolo model_data/yolov4.h5 --model_feature model_data/mars-small128.pb
視頻效果
OTCBVS-D+TVideo文章來源:http://www.zghlxwxcb.cn/news/detail-443185.html
五、總結(jié)
本教程粗糙地提供了在云服務(wù)器autodl上的圖像融合、目標(biāo)檢測、目標(biāo)跟蹤的技術(shù)實(shí)現(xiàn),后續(xù)筆者應(yīng)該會根據(jù)組內(nèi)要求對算法優(yōu)化并部署到開發(fā)板上做輕量級實(shí)現(xiàn)。歡迎同道中人一起交流!文章來源地址http://www.zghlxwxcb.cn/news/detail-443185.html
到了這里,關(guān)于利用紅外-可見光圖像數(shù)據(jù)集OTCBVS打通圖像融合、目標(biāo)檢測和目標(biāo)跟蹤的文章就介紹完了。如果您還想了解更多內(nèi)容,請?jiān)谟疑辖撬阉鱐OY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章,希望大家以后多多支持TOY模板網(wǎng)!