背景
視頻特征提取過程發現出現很多檢索不到的問題,且對於拼接視頻的檢索也有問題。分析了下視頻,發現原始視頻是分辨率不一的,使用軟件拼接后導致某些片段視頻出現黑邊,從而統一resize及提取ROI后的圖像不完整,以至於特征提取不全,最終導致檢索失敗。
所以需要對視頻關鍵幀進行去邊操作后再進行后續處理。
方法
1、Opencv-Python
閾值篩選全局檢測 去黑邊
裁剪結果不完整 由於閾值函數的問題 不推薦
https://github.com/younkun/image_image-processing/blob/master/remove_BlackEdge.py
https://blog.csdn.net/qianqing13579/article/details/42323397
2、Opencv-Python
直方圖標准差、轉換二值圖像、OTSU確定分割閾值、SOBEL算子邊緣計算、NMS等算法實現
https://blog.csdn.net/u010333076/article/details/87900631
3、ffmpeg去黑邊 自動裁剪
https://blog.csdn.net/rootusers/article/details/41674553
問題:自動濾鏡怎么下載及編譯ffmpeg?未研究
4、imagemagick 去黑邊、白邊
# 命令行方式
magick convert image-233.jpg -fuzz 10% -trim ../../test2.jpg
// C++代碼實現
// @file: demo_trim.cpp
#include <Magick++.h>
#include <string>
#include <iostream>
using namespace std;
using namespace Magick;
int main(int argc, char**argv)
{
if(argc != 3)
{
cout << "Usage: ./trim input.jpg out.jpg\n";
return -1;
}
string srcpath((const char*)argv[1]);
string dstpath((const char*)argv[2]);
Image image;
try{
image.read(srcpath);
image.colorFuzz(0.15*QuantumRange);
image.trim();
image.display();
image.write(dstpath);
}
catch(Exception &error_)
{
cout << "Caught exception: " << error_.what() << endl;
return 1;
}
return 0;
}
cat Makefile
CPP:=g++ -g `Magick++-config --cxxflags --cppflags --ldflags --libs`
trim:demo_trim.cpp
${CPP} $< -o $@
clean:
rm -rf trim
效果
參考
1、imagemagick處理命令
2、imagemagick官網去邊使用說明
3、imagemagick官網地址
4、imagemagick trim