generated from zhangwei/Train_Identify
初版ARM版
This commit is contained in:
parent
9fadfe6a37
commit
d02a50a6c2
|
|
@ -1,5 +1,5 @@
|
||||||
cmake_minimum_required(VERSION 3.5)
|
cmake_minimum_required(VERSION 3.5)
|
||||||
cmake_policy(SET CMP0074 NEW)
|
# cmake_policy(SET CMP0074 NEW)
|
||||||
|
|
||||||
message("NVIDIA NX PLATFORM")
|
message("NVIDIA NX PLATFORM")
|
||||||
set(PROJECT_NAME train)
|
set(PROJECT_NAME train)
|
||||||
|
|
@ -13,19 +13,22 @@ set(CMAKE_CXX_STANDARD 11)
|
||||||
#set(CMAKE_BUILD_TYPE Debug)
|
#set(CMAKE_BUILD_TYPE Debug)
|
||||||
#set(CMAKE_BUILD_TYPE Release)
|
#set(CMAKE_BUILD_TYPE Release)
|
||||||
#add_definitions("-Wall -g")
|
#add_definitions("-Wall -g")
|
||||||
|
find_package(CUDA REQUIRED)
|
||||||
|
|
||||||
#opencv
|
#opencv
|
||||||
find_package(OpenCV REQUIRED)
|
find_package(OpenCV REQUIRED)
|
||||||
# message(STATUS "${OpenCV_LIBS}")
|
# message(STATUS "${OpenCV_LIBS}")
|
||||||
# message(STATUS "${OpenCV_INCLUDE_DIRS}")
|
# message(STATUS "${OpenCV_INCLUDE_DIRS}")
|
||||||
|
|
||||||
find_package(CUDA REQUIRED)
|
|
||||||
|
|
||||||
# 设置编译工具
|
# 设置编译工具
|
||||||
set(CMAKE_SYSTEM_NAME Linux)
|
set(CMAKE_SYSTEM_NAME Linux)
|
||||||
set(CMAKE_C_COMPILER "gcc")
|
set(CMAKE_C_COMPILER "gcc")
|
||||||
set(CMAKE_CXX_COMPILER "g++")
|
set(CMAKE_CXX_COMPILER "g++")
|
||||||
|
# 设置arm交叉编译工具
|
||||||
|
# set(CMAKE_SYSTEM_NAME Linux)
|
||||||
|
# set(CMAKE_SYSTEM_PROCESSOR aarch64)
|
||||||
|
# set(CMAKE_C_COMPILER "aarch64-linux-gnu-gcc")
|
||||||
|
# set(CMAKE_CXX_COMPILER "aarch64-linux-gnu-g++")
|
||||||
|
|
||||||
|
|
||||||
# 设置项目生成目录
|
# 设置项目生成目录
|
||||||
|
|
@ -41,12 +44,10 @@ set(SYS_USR_INCLUDE_DIR "/usr/include")
|
||||||
set(SYS_USR_LIB_DIR "/usr/lib")
|
set(SYS_USR_LIB_DIR "/usr/lib")
|
||||||
set(SYS_USR_LOCAL_INCLUDE_DIR "/usr/local/include")
|
set(SYS_USR_LOCAL_INCLUDE_DIR "/usr/local/include")
|
||||||
set(SYS_USR_LOCAL_LIB_DIR "/usr/local/lib")
|
set(SYS_USR_LOCAL_LIB_DIR "/usr/local/lib")
|
||||||
# -- X86下使用 --
|
# set(AARCH64_LINUX_INCLUDE_DIR "/usr/include/x86_64-linux-gnu")
|
||||||
set(AARCH64_LINUX_INCLUDE_DIR "/usr/include/x86_64-linux-gnu")
|
# set(AARCH64_LINUX_LIB_DIR "/usr/lib/x86_64-linux-gnu")
|
||||||
set(AARCH64_LINUX_LIB_DIR "/usr/lib/x86_64-linux-gnu")
|
set(AARCH64_LINUX_INCLUDE_DIR "/usr/include/aarch64-linux-gnu")
|
||||||
# -- ARM下使用 --
|
set(AARCH64_LINUX_LIB_DIR "/usr/lib/aarch64-linux-gnu")
|
||||||
#set(AARCH64_LINUX_INCLUDE_DIR "/usr/include/aarch64-linux-gnu")
|
|
||||||
#set(AARCH64_LINUX_LIB_DIR "/usr/lib/aarch64-linux-gnu")
|
|
||||||
|
|
||||||
|
|
||||||
#opencv3.2.0的库文件在/usr/lib/aarch64-linux-gnu下 头文件路径在/usr/include/opencv2
|
#opencv3.2.0的库文件在/usr/lib/aarch64-linux-gnu下 头文件路径在/usr/include/opencv2
|
||||||
|
|
@ -55,7 +56,8 @@ set(AARCH64_LINUX_LIB_DIR "/usr/lib/x86_64-linux-gnu")
|
||||||
set(OPENCV_INCLUDE_DIR ${SYS_USR_LOCAL_INCLUDE_DIR}/opencv4)
|
set(OPENCV_INCLUDE_DIR ${SYS_USR_LOCAL_INCLUDE_DIR}/opencv4)
|
||||||
set(OPENCV_LIB_DIR ${SYS_USR_LOCAL_LIB_DIR})
|
set(OPENCV_LIB_DIR ${SYS_USR_LOCAL_LIB_DIR})
|
||||||
|
|
||||||
set(CUDA_DIR "/usr/local/cuda-11.7")
|
# set(CUDA_DIR "/usr/local/cuda-11.7")
|
||||||
|
set(CUDA_DIR "/usr/local/cuda-10.2")
|
||||||
set(CUDA_INCLUDE_DIR ${CUDA_DIR}/include)
|
set(CUDA_INCLUDE_DIR ${CUDA_DIR}/include)
|
||||||
set(CUDA_LIB_DIR ${CUDA_DIR}/lib64)
|
set(CUDA_LIB_DIR ${CUDA_DIR}/lib64)
|
||||||
|
|
||||||
|
|
@ -150,7 +152,7 @@ link_directories(${SYS_USR_LOCAL_LIB_DIR}
|
||||||
${CUDA_LIB_DIR}
|
${CUDA_LIB_DIR}
|
||||||
${TENSORRT_LIB_DIR}
|
${TENSORRT_LIB_DIR}
|
||||||
${TEGRA_LIB_DIR}
|
${TEGRA_LIB_DIR}
|
||||||
)
|
)
|
||||||
|
|
||||||
#源文件
|
#源文件
|
||||||
#公共源文件
|
#公共源文件
|
||||||
|
|
@ -187,19 +189,26 @@ file(GLOB_RECURSE COMMON_SRCS_LISTS
|
||||||
${PROJECT_SOURCE_DIR}/nvidia_ascend_engine/common_engine/TransEngine/*.cpp
|
${PROJECT_SOURCE_DIR}/nvidia_ascend_engine/common_engine/TransEngine/*.cpp
|
||||||
${PROJECT_SOURCE_DIR}/nvidia_ascend_engine/common_engine/DataDealEngine/*.cpp
|
${PROJECT_SOURCE_DIR}/nvidia_ascend_engine/common_engine/DataDealEngine/*.cpp
|
||||||
${PROJECT_SOURCE_DIR}/nvidia_ascend_engine/common_engine/SocketEngine/*.cpp
|
${PROJECT_SOURCE_DIR}/nvidia_ascend_engine/common_engine/SocketEngine/*.cpp
|
||||||
${PROJECT_SOURCE_DIR}/nvidia_ascend_engine/common_engine/SocketEngine/*.cpp
|
|
||||||
${PROJECT_SOURCE_DIR}/nvidia_ascend_engine/common_engine/DataSourceEngine/*.cpp
|
|
||||||
${PROJECT_SOURCE_DIR}/nvidia_ascend_engine/common_engine/SaveEngine/*.cpp
|
|
||||||
${PROJECT_SOURCE_DIR}/nvidia_ascend_engine/common_engine/DeleteExpiredFolderEngine/*.cpp
|
${PROJECT_SOURCE_DIR}/nvidia_ascend_engine/common_engine/DeleteExpiredFolderEngine/*.cpp
|
||||||
|
|
||||||
#common tools rtsp_server src
|
#common tools rtsp_server src
|
||||||
${PROJECT_SOURCE_DIR}/nvidia_ascend_tools/common_tools/rtsp_server/net/*.cpp
|
${PROJECT_SOURCE_DIR}/nvidia_ascend_tools/common_tools/rtsp_server/net/*.cpp
|
||||||
${PROJECT_SOURCE_DIR}/nvidia_ascend_tools/common_tools/rtsp_server/xop/*.cpp
|
${PROJECT_SOURCE_DIR}/nvidia_ascend_tools/common_tools/rtsp_server/xop/*.cpp
|
||||||
)
|
)
|
||||||
|
|
||||||
file(GLOB_RECURSE SRCS_LISTS
|
file(GLOB_RECURSE SRCS_LISTS
|
||||||
#nvidia engine src
|
#nvidia engine src
|
||||||
#nvidia engine include
|
#nvidia engine include
|
||||||
|
${PROJECT_SOURCE_DIR}/nvidia_ascend_engine/common_engine/ControlEngine/*.cpp
|
||||||
|
${PROJECT_SOURCE_DIR}/nvidia_ascend_engine/common_engine/DataSourceEngine/*.cpp
|
||||||
|
${PROJECT_SOURCE_DIR}/nvidia_ascend_engine/common_engine/DataUploadEngine/*.cpp
|
||||||
|
${PROJECT_SOURCE_DIR}/nvidia_ascend_engine/common_engine/FilterEngine/*.cpp
|
||||||
|
${PROJECT_SOURCE_DIR}/nvidia_ascend_engine/common_engine/MergerEngine/*.cpp
|
||||||
|
${PROJECT_SOURCE_DIR}/nvidia_ascend_engine/common_engine/SaveEngine/*.cpp
|
||||||
|
${PROJECT_SOURCE_DIR}/nvidia_ascend_engine/common_engine/SelectBestEngine/*.cpp
|
||||||
|
${PROJECT_SOURCE_DIR}/nvidia_ascend_engine/common_engine/TrainAnaEngine/*.cpp
|
||||||
|
${PROJECT_SOURCE_DIR}/nvidia_ascend_engine/common_engine/TransEngine/*.cpp
|
||||||
|
${PROJECT_SOURCE_DIR}/nvidia_ascend_engine/common_engine/DataDealEngine/*.cpp
|
||||||
|
|
||||||
${PROJECT_SOURCE_DIR}/nvidia_ascend_engine/nvidia_engine/ChkDateStepOneEngine/*.cpp
|
${PROJECT_SOURCE_DIR}/nvidia_ascend_engine/nvidia_engine/ChkDateStepOneEngine/*.cpp
|
||||||
${PROJECT_SOURCE_DIR}/nvidia_ascend_engine/nvidia_engine/ChkDateStepTwoEngine/*.cpp
|
${PROJECT_SOURCE_DIR}/nvidia_ascend_engine/nvidia_engine/ChkDateStepTwoEngine/*.cpp
|
||||||
|
|
@ -215,9 +224,12 @@ file(GLOB_RECURSE SRCS_LISTS
|
||||||
#nvidia tools yolov5 src
|
#nvidia tools yolov5 src
|
||||||
${PROJECT_SOURCE_DIR}/nvidia_ascend_tools/nvidia_tools/yolov5/src/*.cpp
|
${PROJECT_SOURCE_DIR}/nvidia_ascend_tools/nvidia_tools/yolov5/src/*.cpp
|
||||||
${PROJECT_SOURCE_DIR}/nvidia_ascend_tools/nvidia_tools/yolov5/src/*.cu
|
${PROJECT_SOURCE_DIR}/nvidia_ascend_tools/nvidia_tools/yolov5/src/*.cu
|
||||||
)
|
)
|
||||||
|
|
||||||
cuda_add_executable(${PROJECT_NAME} ${COMMON_SRCS_LISTS} ${SRCS_LISTS})
|
cuda_add_executable(${PROJECT_NAME} ${COMMON_SRCS_LISTS} ${SRCS_LISTS})
|
||||||
|
# add_executable(${PROJECT_NAME} ${COMMON_SRCS_LISTS} ${SRCS_LISTS})
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
target_link_libraries(${PROJECT_NAME} pthread) #other
|
target_link_libraries(${PROJECT_NAME} pthread) #other
|
||||||
target_link_libraries(${PROJECT_NAME} nvinfer nvonnxparser nvcaffe_parser nvinfer_plugin) #TensorRT
|
target_link_libraries(${PROJECT_NAME} nvinfer nvonnxparser nvcaffe_parser nvinfer_plugin) #TensorRT
|
||||||
|
|
@ -229,7 +241,7 @@ target_link_libraries(${PROJECT_NAME}
|
||||||
# pcl_common pcl_io_ply pcl_keypoints pcl_registration pcl_segmentation pcl_features pcl_io pcl_octree #pcl
|
# pcl_common pcl_io_ply pcl_keypoints pcl_registration pcl_segmentation pcl_features pcl_io pcl_octree #pcl
|
||||||
# pcl_sample_consensus pcl_surface pcl_filters pcl_kdtree pcl_recognition pcl_search pcl_tracking
|
# pcl_sample_consensus pcl_surface pcl_filters pcl_kdtree pcl_recognition pcl_search pcl_tracking
|
||||||
avformat avcodec avutil avfilter swresample swscale postproc #VideoCodecV2
|
avformat avcodec avutil avfilter swresample swscale postproc #VideoCodecV2
|
||||||
yaml-cpp https_sn
|
yaml-cpp
|
||||||
jsoncpp curl boost_system boost_filesystem ssh2
|
jsoncpp curl boost_system boost_filesystem ssh2
|
||||||
-Wl,-z,relro,-z,now,-z,noexecstack -pie -s
|
-Wl,-z,relro,-z,now,-z,noexecstack -pie -s
|
||||||
)
|
)
|
||||||
|
|
@ -104,10 +104,11 @@ namespace ai_matrix
|
||||||
|
|
||||||
//检查是否有重复engine
|
//检查是否有重复engine
|
||||||
std::string engine_unique = engine_name + "_" + std::to_string(engine_id);
|
std::string engine_unique = engine_name + "_" + std::to_string(engine_id);
|
||||||
printf(engine_unique.c_str());
|
// printf(engine_unique.c_str());
|
||||||
auto iter = engine_map_.find(engine_unique);
|
auto iter = engine_map_.find(engine_unique);
|
||||||
if (iter != engine_map_.end())
|
if (iter != engine_map_.end())
|
||||||
{
|
{
|
||||||
|
LogWarn << "重复engine :" << engine_unique;
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -55,7 +55,6 @@ namespace ai_matrix
|
||||||
std::string get_date();
|
std::string get_date();
|
||||||
//获取时间
|
//获取时间
|
||||||
std::string get_time();
|
std::string get_time();
|
||||||
|
|
||||||
//时间戳转化为时间 毫秒级
|
//时间戳转化为时间 毫秒级
|
||||||
std::string Stamp2Time(long long timestamp, bool has_msec = false);
|
std::string Stamp2Time(long long timestamp, bool has_msec = false);
|
||||||
|
|
||||||
|
|
|
||||||
4
build.sh
4
build.sh
|
|
@ -4,7 +4,7 @@ set -e
|
||||||
|
|
||||||
path_cur=$(cd `dirname $0`; pwd)
|
path_cur=$(cd `dirname $0`; pwd)
|
||||||
build_type="Release"
|
build_type="Release"
|
||||||
# 生成目录 ceshi
|
# 生成目录
|
||||||
app_path="app"
|
app_path="app"
|
||||||
# 可执行程序名
|
# 可执行程序名
|
||||||
appname="train"
|
appname="train"
|
||||||
|
|
@ -39,7 +39,7 @@ function build(){
|
||||||
if [ "$1" == $app_path ]; then
|
if [ "$1" == $app_path ]; then
|
||||||
cmake -DCMAKE_BUILD_TYPE="Release" ..
|
cmake -DCMAKE_BUILD_TYPE="Release" ..
|
||||||
else
|
else
|
||||||
cmake -DCMAKE_BUILD_TYPE="Debug" ..
|
cmake -DCMAKE_BUILD_TYPE="Release" ..
|
||||||
fi
|
fi
|
||||||
|
|
||||||
make -j4
|
make -j4
|
||||||
|
|
|
||||||
26
config.yaml
26
config.yaml
|
|
@ -11,7 +11,8 @@ gc_data_source: "camera" #[camera, images]
|
||||||
camera:
|
camera:
|
||||||
camera_0:
|
camera_0:
|
||||||
#url: "rtsp://admin:sgt12345@10.27.119.13:554/h264/ch1/main/av_stream"
|
#url: "rtsp://admin:sgt12345@10.27.119.13:554/h264/ch1/main/av_stream"
|
||||||
url: "./videos/km70.mp4"
|
# url: "./videos/km70.mp4"
|
||||||
|
url: "./vedio/buertai2.mp4"
|
||||||
skipInterval: 3
|
skipInterval: 3
|
||||||
target: "NUM"
|
target: "NUM"
|
||||||
use: true
|
use: true
|
||||||
|
|
@ -70,7 +71,8 @@ gc_best_path: "./result/best"
|
||||||
#模型参数,只考虑敞车
|
#模型参数,只考虑敞车
|
||||||
model:
|
model:
|
||||||
MoveEngine: #动态检测
|
MoveEngine: #动态检测
|
||||||
om_path: "./model/step0/step0.FP16.engine"
|
# om_path: "./model/step0/step0.FP16.engine"
|
||||||
|
om_path: "./model/step0/step0.engine"
|
||||||
modelinfo_path: "./model/step0/retina_move_modelinfo.txt"
|
modelinfo_path: "./model/step0/retina_move_modelinfo.txt"
|
||||||
model_type: "retina" #(retina, yolov5)
|
model_type: "retina" #(retina, yolov5)
|
||||||
score_threshold: 0.9
|
score_threshold: 0.9
|
||||||
|
|
@ -82,6 +84,7 @@ model:
|
||||||
score_threshold: 0.6
|
score_threshold: 0.6
|
||||||
nms_threshold: 0.3
|
nms_threshold: 0.3
|
||||||
TrainStepTwoEngine: #字符识别
|
TrainStepTwoEngine: #字符识别
|
||||||
|
# om_path: "./model/step2/step2.engine"
|
||||||
om_path: "./model/step2/step2.engine"
|
om_path: "./model/step2/step2.engine"
|
||||||
modelinfo_path: "./model/step2/yolov5_train_step2_modelinfo.txt"
|
modelinfo_path: "./model/step2/yolov5_train_step2_modelinfo.txt"
|
||||||
model_type: "yolov5" #(retina, yolov5)
|
model_type: "yolov5" #(retina, yolov5)
|
||||||
|
|
@ -112,20 +115,21 @@ model:
|
||||||
score_threshold: 0.7
|
score_threshold: 0.7
|
||||||
nms_threshold: 0.3
|
nms_threshold: 0.3
|
||||||
|
|
||||||
gc_http_open: 1
|
gc_http_open: 0
|
||||||
username: "guest_01"
|
# gc_http_url: "http://192.168.2.211:20004/api/train-carriage/identification/video-save"
|
||||||
password: "d55b0f642e817eea24725d2f2a31dd08" # 神东
|
# gc_gettoken_url: "http://192.168.2.211:20004/api/blade-auth/oauth/token"
|
||||||
gc_http_url: "http://192.168.2.211:20004/api/train-carriage/identification/video-save"
|
# gc_image_srv: "http://192.168.2.211:9010/"
|
||||||
gc_gettoken_url: "http://192.168.2.211:20004/api/blade-auth/oauth/token"
|
gc_http_url: "http://192.168.2.121:8081"
|
||||||
gc_image_srv: "http://192.168.2.211:9010/"
|
gc_gettoken_url: "http://192.168.0.121:20004/api/blade-auth/oauth/token"
|
||||||
|
gc_image_srv: "http://192.168.0.121:9010/"
|
||||||
|
|
||||||
gc_device_status_open: 1
|
gc_device_status_open: 0
|
||||||
gc_device_status_url: "http://192.168.2.211:20004/api/blade-train/deviceInfo/save"
|
gc_device_status_url: "http://192.168.2.211:20004/api/blade-train/deviceInfo/save"
|
||||||
|
|
||||||
rfid_ip: "10.27.200.39"
|
rfid_ip: "10.27.200.39"
|
||||||
|
|
||||||
#socket_server 的服务端参数
|
#socket_server 的服务端参数
|
||||||
socket_server_open: 1
|
socket_server_open: 0
|
||||||
socket_server_port: 7000
|
socket_server_port: 7000
|
||||||
socket_server_queue_len: 10
|
socket_server_queue_len: 10
|
||||||
|
|
||||||
|
|
@ -182,5 +186,5 @@ gc_c_space_frame_width: 500
|
||||||
# 是否识别车头
|
# 是否识别车头
|
||||||
gc_train_heard_detect: true
|
gc_train_heard_detect: true
|
||||||
|
|
||||||
#过期文件夹天数
|
# 识别结果保存天数
|
||||||
gc_days_for_result_expire_folder: 3
|
gc_days_for_result_expire_folder: 3
|
||||||
|
|
|
||||||
|
|
@ -70,8 +70,8 @@ connects:
|
||||||
#ControlEngine_0_2: "PushEngine_0_0 1024" #实时推流直播
|
#ControlEngine_0_2: "PushEngine_0_0 1024" #实时推流直播
|
||||||
MoveEngine_0_0: "SaveImgEngine_0_0 1024" #识别过程中数据保存
|
MoveEngine_0_0: "SaveImgEngine_0_0 1024" #识别过程中数据保存
|
||||||
MoveEngine_0_1: "SocketEngine_0_0 1024" #
|
MoveEngine_0_1: "SocketEngine_0_0 1024" #
|
||||||
|
|
||||||
MoveEngine_0_5: "DataDealEngine_0_0 1024"
|
MoveEngine_0_5: "DataDealEngine_0_0 1024"
|
||||||
|
|
||||||
DataDealEngine_0_0: "TrainStepOneEngine_0_0"
|
DataDealEngine_0_0: "TrainStepOneEngine_0_0"
|
||||||
TrainStepOneEngine_0_0: "FilterTrainStepOneEngine_0_0"
|
TrainStepOneEngine_0_0: "FilterTrainStepOneEngine_0_0"
|
||||||
FilterTrainStepOneEngine_0_0: "SaveStepOneResultEngine_0_0 1024"
|
FilterTrainStepOneEngine_0_0: "SaveStepOneResultEngine_0_0 1024"
|
||||||
|
|
@ -89,6 +89,7 @@ connects:
|
||||||
FilterContainerStepOneEngine_0_0: "SaveStepOneResultEngine_0_0"
|
FilterContainerStepOneEngine_0_0: "SaveStepOneResultEngine_0_0"
|
||||||
|
|
||||||
TrainParationMgr_0_0: "DataDealTwoEngine_0_0 1024"
|
TrainParationMgr_0_0: "DataDealTwoEngine_0_0 1024"
|
||||||
|
|
||||||
DataDealTwoEngine_0_0: "TrainStepTwoEngine_0_0"
|
DataDealTwoEngine_0_0: "TrainStepTwoEngine_0_0"
|
||||||
TrainStepTwoEngine_0_0: "TransTrainEngine_0_0"
|
TrainStepTwoEngine_0_0: "TransTrainEngine_0_0"
|
||||||
TransTrainEngine_0_0: "SelectBestEngine_0_0"
|
TransTrainEngine_0_0: "SelectBestEngine_0_0"
|
||||||
|
|
|
||||||
|
|
@ -36,8 +36,8 @@ namespace MatrixAILog
|
||||||
uint32_t Log::logLevel = LOG_LEVEL_INFO;
|
uint32_t Log::logLevel = LOG_LEVEL_INFO;
|
||||||
std::vector<std::string> Log::levelString{"[Debug]", "[Info ]", "[Warn ]", "[Error]", "[Fatal]"};
|
std::vector<std::string> Log::levelString{"[Debug]", "[Info ]", "[Warn ]", "[Error]", "[Fatal]"};
|
||||||
std::mutex Log::mutex;
|
std::mutex Log::mutex;
|
||||||
std::string Log::logFile = "/home/nvidia/train/logs/log.log"; // default log file
|
std::string Log::logFile = "./logs/log.log"; // default log file
|
||||||
std::string Log::logFileBak = "/home/nvidia/train/logs/log.log.bak";
|
std::string Log::logFileBak = "./logs/log.log.bak";
|
||||||
std::string Log::logFileBakPath = "";
|
std::string Log::logFileBakPath = "";
|
||||||
|
|
||||||
Log::Log(std::string file, std::string function, int line, uint32_t level)
|
Log::Log(std::string file, std::string function, int line, uint32_t level)
|
||||||
|
|
@ -69,27 +69,26 @@ namespace MatrixAILog
|
||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
// dstFileSize >= FILE_SIZE
|
|
||||||
|
|
||||||
// "date_格式[yyyy-mm-dd HH:MM:SS:"改为"yyyymmmdd_HHMMSS"
|
// "date_格式[yyyy-mm-dd HH:MM:SS:"改为"yyyymmmdd_HHMMSS"
|
||||||
if (!logFileBakPath.empty())
|
// if (!logFileBakPath.empty())
|
||||||
{
|
// {
|
||||||
CreateDirRecursivelyByFile(logFileBakPath);
|
// CreateDirRecursivelyByFile(logFileBakPath);
|
||||||
std::string strData;
|
// std::string strData;
|
||||||
for (int i = 0; i < date_.size(); i++)
|
// for (int i = 0; i < date_.size(); i++)
|
||||||
{
|
// {
|
||||||
if (date_[i] != '-' && date_[i] != ':' && date_[i] != '[')
|
// if (date_[i] != '-' && date_[i] != ':' && date_[i] != '[')
|
||||||
{
|
// {
|
||||||
if (date_[i] == ' ')
|
// if (date_[i] == ' ')
|
||||||
{
|
// {
|
||||||
strData += "_";
|
// strData += "_";
|
||||||
continue;
|
// continue;
|
||||||
}
|
// }
|
||||||
strData += date_[i];
|
// strData += date_[i];
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
logFileBak = logFileBakPath + strData + "_bak.txt";
|
// logFileBak = logFileBakPath + strData + "_bak.txt";
|
||||||
}
|
// }
|
||||||
|
|
||||||
if (access(logFileBak.c_str(), 0) == APP_ERR_OK)
|
if (access(logFileBak.c_str(), 0) == APP_ERR_OK)
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -516,6 +516,7 @@ typedef struct
|
||||||
uint64_t i64TimeStamp = 0; //帧数据时间戳
|
uint64_t i64TimeStamp = 0; //帧数据时间戳
|
||||||
std::shared_ptr<DecodedData> pDecodeData = nullptr;
|
std::shared_ptr<DecodedData> pDecodeData = nullptr;
|
||||||
int iDirection = 0; //行驶方向(0-未知; 1-向左; 2-向右)
|
int iDirection = 0; //行驶方向(0-未知; 1-向左; 2-向右)
|
||||||
|
int nMonitorState = MONITOR_MODEL_INIT_STATE;
|
||||||
} SaveImgData;
|
} SaveImgData;
|
||||||
|
|
||||||
//识别处理数据
|
//识别处理数据
|
||||||
|
|
|
||||||
|
|
@ -190,14 +190,14 @@ void DataDealEngine::MakeProcessData()
|
||||||
iFrameId = iReRunFrameId;
|
iFrameId = iReRunFrameId;
|
||||||
}
|
}
|
||||||
|
|
||||||
LogInfo << "sourceid:" << iSourceId << " MakeProcessData origtime:" << moveData_.strTrainName << " iOrigFrameId:" << iOrigFrameId
|
// LogInfo << "sourceid:" << iSourceId << " MakeProcessData origtime:" << moveData_.strTrainName << " iOrigFrameId:" << iOrigFrameId
|
||||||
<< " time:" << strTrainName_ << " iFrameId:" << iFrameId << " bIsEndFlag:" << bIsEndFlag;
|
// << " time:" << strTrainName_ << " iFrameId:" << iFrameId << " bIsEndFlag:" << bIsEndFlag;
|
||||||
|
|
||||||
std::string strImgName = strDataDir_ + szCameraNo + std::to_string(iOrigFrameId);
|
std::string strImgName = strDataDir_ + szCameraNo + std::to_string(iOrigFrameId);
|
||||||
strImgName += (iter->second.iRotate != 0) ? "_rotate.jpg" : ".jpg";
|
strImgName += (iter->second.iRotate != 0) ? "_rotate.jpg" : ".jpg";
|
||||||
std::string strFileName = strDataDir_ + szCameraNo + std::to_string(iOrigFrameId) + ".txt";
|
std::string strFileName = strDataDir_ + szCameraNo + std::to_string(iOrigFrameId) + ".txt";
|
||||||
|
|
||||||
//摄像头读取失败后重试30次。
|
//摄像头读取失败后重试2000次。
|
||||||
Json::Value jvFrameInfo;
|
Json::Value jvFrameInfo;
|
||||||
RawData rawData;
|
RawData rawData;
|
||||||
bool bRet = false;
|
bool bRet = false;
|
||||||
|
|
@ -227,7 +227,6 @@ void DataDealEngine::MakeProcessData()
|
||||||
pProcessData->iStatus = TRAINSTATUS_RUN;
|
pProcessData->iStatus = TRAINSTATUS_RUN;
|
||||||
pProcessData->bIsEnd = bIsEndFlag;
|
pProcessData->bIsEnd = bIsEndFlag;
|
||||||
pProcessData->iDataNO = iDataNO_;
|
pProcessData->iDataNO = iDataNO_;
|
||||||
pProcessData->nMonitorState = moveData_.nMonitorState;
|
|
||||||
|
|
||||||
if (bRet)
|
if (bRet)
|
||||||
{
|
{
|
||||||
|
|
@ -237,6 +236,7 @@ void DataDealEngine::MakeProcessData()
|
||||||
pProcessData->iHeight = jvFrameInfo["height"].asInt();
|
pProcessData->iHeight = jvFrameInfo["height"].asInt();
|
||||||
pProcessData->iDirection = jvFrameInfo["direction"].asInt();
|
pProcessData->iDirection = jvFrameInfo["direction"].asInt();
|
||||||
pProcessData->iRate = jvFrameInfo["rate"].asInt();
|
pProcessData->iRate = jvFrameInfo["rate"].asInt();
|
||||||
|
pProcessData->nMonitorState = jvFrameInfo["moveType"].asInt();
|
||||||
|
|
||||||
cv::Mat cvframe = cv::imread(pProcessData->strPicFilePath);
|
cv::Mat cvframe = cv::imread(pProcessData->strPicFilePath);
|
||||||
int iBufferSize = pProcessData->iWidth * pProcessData->iHeight * 3;
|
int iBufferSize = pProcessData->iWidth * pProcessData->iHeight * 3;
|
||||||
|
|
@ -252,14 +252,14 @@ void DataDealEngine::MakeProcessData()
|
||||||
{
|
{
|
||||||
if (iPort == vecPushPorts.size() - 1)
|
if (iPort == vecPushPorts.size() - 1)
|
||||||
{
|
{
|
||||||
//iRet = outputQueMap_[vecPushPorts[iPort]]->push(std::static_pointer_cast<void>(pProcessData));
|
iRet = outputQueMap_[vecPushPorts[iPort]]->push(std::static_pointer_cast<void>(pProcessData), true);
|
||||||
PushData(vecPushPorts[iPort], pProcessData);
|
// PushData(vecPushPorts[iPort], pProcessData);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
std::shared_ptr<ProcessData> pNewProcessData = std::make_shared<ProcessData>();
|
std::shared_ptr<ProcessData> pNewProcessData = std::make_shared<ProcessData>();
|
||||||
*pNewProcessData = *pProcessData;
|
*pNewProcessData = *pProcessData;
|
||||||
//iRet = outputQueMap_[vecPushPorts[iPort]]->push(std::static_pointer_cast<void>(pNewProcessData));
|
iRet = outputQueMap_[vecPushPorts[iPort]]->push(std::static_pointer_cast<void>(pNewProcessData), true);
|
||||||
PushData(vecPushPorts[iPort], pNewProcessData);
|
// PushData(vecPushPorts[iPort], pNewProcessData);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
@ -291,25 +291,14 @@ APP_ERROR DataDealEngine::Process()
|
||||||
//获取主摄像头检测的状态
|
//获取主摄像头检测的状态
|
||||||
std::shared_ptr<void> pVoidData0 = nullptr;
|
std::shared_ptr<void> pVoidData0 = nullptr;
|
||||||
iRet = inputQueMap_[strPort0_]->pop(pVoidData0);
|
iRet = inputQueMap_[strPort0_]->pop(pVoidData0);
|
||||||
|
|
||||||
if (nullptr != pVoidData0)
|
if (nullptr != pVoidData0)
|
||||||
{
|
{
|
||||||
std::shared_ptr<MoveData> pMoveData = std::static_pointer_cast<MoveData>(pVoidData0);
|
std::shared_ptr<MoveData> pMoveData = std::static_pointer_cast<MoveData>(pVoidData0);
|
||||||
|
|
||||||
// queuwMoveData_.push(*pMoveData);
|
|
||||||
moveData_ = *pMoveData;
|
moveData_ = *pMoveData;
|
||||||
LogDebug << "traindate:" << moveData_.strTrainDate << " trainname:" << moveData_.strTrainName
|
LogDebug << "traindate:" << moveData_.strTrainDate << " trainname:" << moveData_.strTrainName
|
||||||
<< " MoveData frameid:" << moveData_.iFrameId << " IsEnd:" << moveData_.bIsEnd;
|
<< " MoveData frameid:" << moveData_.iFrameId << " IsEnd:" << moveData_.bIsEnd;
|
||||||
}
|
}
|
||||||
|
|
||||||
// LogDebug << "【帧号】" << (iDataNO_ * dataSourceConfig_.iSkipInterval);
|
|
||||||
// if (queuwMoveData_.size() > 0 && (iDataNO_ * dataSourceConfig_.iSkipInterval) >= queuwMoveData_.front().iFrameId)
|
|
||||||
// {
|
|
||||||
// moveData_ = queuwMoveData_.front();
|
|
||||||
// queuwMoveData_.pop();
|
|
||||||
// LogDebug << "!!!--- moveDate 更新";
|
|
||||||
// }
|
|
||||||
|
|
||||||
if (!moveData_.bHasTrain)
|
if (!moveData_.bHasTrain)
|
||||||
{
|
{
|
||||||
usleep(1000); //1ms
|
usleep(1000); //1ms
|
||||||
|
|
@ -319,7 +308,7 @@ APP_ERROR DataDealEngine::Process()
|
||||||
//第一个数据,休眠1s,等待图片存入本地
|
//第一个数据,休眠1s,等待图片存入本地
|
||||||
if (iOrigDataNO_ == 1)
|
if (iOrigDataNO_ == 1)
|
||||||
{
|
{
|
||||||
usleep(1000 * 1000); //1s
|
usleep(1000000); //1s
|
||||||
}
|
}
|
||||||
|
|
||||||
if (strDataDir_.empty())
|
if (strDataDir_.empty())
|
||||||
|
|
|
||||||
|
|
@ -407,31 +407,6 @@ int DataDealTwoEngine::GetPostData(std::shared_ptr<ProcessData> pProcessData, Js
|
||||||
return pPostData->vecPostSubData.size();
|
return pPostData->vecPostSubData.size();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* push数据到队列,队列满时则休眠一段时间再push。
|
|
||||||
* inParam : const std::string strPort push的端口
|
|
||||||
: const std::shared_ptr<ProcessData> &pProcessData push的数据
|
|
||||||
* outParam: N/A
|
|
||||||
* return : N/A
|
|
||||||
*/
|
|
||||||
void DataDealTwoEngine::PushData(const std::string &strPort, const std::shared_ptr<ProcessData> &pProcessData)
|
|
||||||
{
|
|
||||||
while (true)
|
|
||||||
{
|
|
||||||
int iRet = outputQueMap_[strPort]->push(std::static_pointer_cast<void>(pProcessData));
|
|
||||||
if (iRet != 0)
|
|
||||||
{
|
|
||||||
LogDebug << "sourceid:" << pProcessData->iDataSource << " frameid:" << pProcessData->iFrameId << " push fail iRet:" << iRet;
|
|
||||||
if (iRet == 2)
|
|
||||||
{
|
|
||||||
usleep(10000); // 10ms
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 构造处理数据并push
|
* 构造处理数据并push
|
||||||
* inParam : N/A
|
* inParam : N/A
|
||||||
|
|
@ -515,14 +490,14 @@ void DataDealTwoEngine::MakeProcessData(std::shared_ptr<TrainRange> pTrainRange)
|
||||||
{
|
{
|
||||||
if (iPort == vecPushPorts.size() - 1)
|
if (iPort == vecPushPorts.size() - 1)
|
||||||
{
|
{
|
||||||
//iRet = outputQueMap_[vecPushPorts[iPort]]->push(std::static_pointer_cast<void>(pProcessData), true);
|
iRet = outputQueMap_[vecPushPorts[iPort]]->push(std::static_pointer_cast<void>(pProcessData), true);
|
||||||
PushData(vecPushPorts[iPort], pProcessData);
|
// PushData(vecPushPorts[iPort], pProcessData);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
std::shared_ptr<ProcessData> pNewProcessData = std::make_shared<ProcessData>();
|
std::shared_ptr<ProcessData> pNewProcessData = std::make_shared<ProcessData>();
|
||||||
*pNewProcessData = *pProcessData;
|
*pNewProcessData = *pProcessData;
|
||||||
//iRet = outputQueMap_[vecPushPorts[iPort]]->push(std::static_pointer_cast<void>(pNewProcessData), true);
|
iRet = outputQueMap_[vecPushPorts[iPort]]->push(std::static_pointer_cast<void>(pNewProcessData), true);
|
||||||
PushData(vecPushPorts[iPort], pNewProcessData);
|
// PushData(vecPushPorts[iPort], pNewProcessData);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -618,7 +593,7 @@ APP_ERROR DataDealTwoEngine::Process()
|
||||||
//处理当车厢的每帧信息
|
//处理当车厢的每帧信息
|
||||||
MakeProcessData(pTrainRange);
|
MakeProcessData(pTrainRange);
|
||||||
// push结果汇总
|
// push结果汇总
|
||||||
iRet = outputQueMap_[engineName_ + "_" + std::to_string(engineId_) + "_9"]->push(std::static_pointer_cast<void>(pTrainRange));
|
iRet = outputQueMap_[engineName_ + "_" + std::to_string(engineId_) + "_9"]->push(std::static_pointer_cast<void>(pTrainRange), true);
|
||||||
|
|
||||||
iTrainIndex_++;
|
iTrainIndex_++;
|
||||||
if (pTrainRange->bIsEnd)
|
if (pTrainRange->bIsEnd)
|
||||||
|
|
|
||||||
|
|
@ -3,25 +3,22 @@
|
||||||
|
|
||||||
using namespace ai_matrix;
|
using namespace ai_matrix;
|
||||||
|
|
||||||
namespace
|
namespace {
|
||||||
{
|
|
||||||
const int LOW_THRESHOLD = 128;
|
const int LOW_THRESHOLD = 128;
|
||||||
const int MAX_THRESHOLD = 4096;
|
const int MAX_THRESHOLD = 4096;
|
||||||
const uint16_t DELAY_TIME = 10000;
|
const uint16_t DELAY_TIME = 20000;
|
||||||
}
|
}
|
||||||
|
|
||||||
CameraEngine::CameraEngine() {}
|
CameraEngine::CameraEngine() {}
|
||||||
|
|
||||||
CameraEngine::~CameraEngine() {}
|
CameraEngine::~CameraEngine() {}
|
||||||
|
|
||||||
APP_ERROR CameraEngine::Init()
|
APP_ERROR CameraEngine::Init() {
|
||||||
{
|
|
||||||
bUseEngine_ = true;
|
bUseEngine_ = true;
|
||||||
bHwDecode_ = MyYaml::GetIns()->GetBoolValue("gc_hardware_decode");
|
bHwDecode_ = MyYaml::GetIns()->GetBoolValue("gc_hardware_decode");
|
||||||
|
|
||||||
dataSourceConfig_ = MyYaml::GetIns()->GetDataSourceConfigById(engineId_); //获取摄像机参数
|
dataSourceConfig_ = MyYaml::GetIns()->GetDataSourceConfigById(engineId_); //获取摄像机参数
|
||||||
if (MyYaml::GetIns()->GetStringValue("gc_data_source") != "camera" || !dataSourceConfig_.bUse)
|
if (MyYaml::GetIns()->GetStringValue("gc_data_source") != "camera" || !dataSourceConfig_.bUse) {
|
||||||
{
|
|
||||||
bUseEngine_ = false;
|
bUseEngine_ = false;
|
||||||
LogWarn << "engineId_:" << engineId_ << " not use engine";
|
LogWarn << "engineId_:" << engineId_ << " not use engine";
|
||||||
return APP_ERR_OK;
|
return APP_ERR_OK;
|
||||||
|
|
@ -35,10 +32,8 @@ APP_ERROR CameraEngine::Init()
|
||||||
return APP_ERR_OK;
|
return APP_ERR_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
APP_ERROR CameraEngine::DeInit()
|
APP_ERROR CameraEngine::DeInit() {
|
||||||
{
|
if (!bUseEngine_) {
|
||||||
if (!bUseEngine_)
|
|
||||||
{
|
|
||||||
LogWarn << "engineId_:" << engineId_ << " not use engine";
|
LogWarn << "engineId_:" << engineId_ << " not use engine";
|
||||||
return APP_ERR_OK;
|
return APP_ERR_OK;
|
||||||
}
|
}
|
||||||
|
|
@ -47,21 +42,17 @@ APP_ERROR CameraEngine::DeInit()
|
||||||
return APP_ERR_OK;
|
return APP_ERR_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
void CameraEngine::ResetCamera()
|
void CameraEngine::ResetCamera() {
|
||||||
{
|
if (pFormatCtx_ != nullptr) {
|
||||||
if (pFormatCtx_ != nullptr)
|
|
||||||
{
|
|
||||||
// clear th cache of the queue
|
// clear th cache of the queue
|
||||||
avformat_close_input(&pFormatCtx_);
|
avformat_close_input(&pFormatCtx_);
|
||||||
pFormatCtx_ = nullptr;
|
pFormatCtx_ = nullptr;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
APP_ERROR CameraEngine::ConnectCamera()
|
APP_ERROR CameraEngine::ConnectCamera() {
|
||||||
{
|
|
||||||
pFormatCtx_ = CreateFormatContext(); // create context
|
pFormatCtx_ = CreateFormatContext(); // create context
|
||||||
if (pFormatCtx_ == nullptr)
|
if (pFormatCtx_ == nullptr) {
|
||||||
{
|
|
||||||
LogError << "engineId_:" << engineId_ << " pFormatCtx_ null!";
|
LogError << "engineId_:" << engineId_ << " pFormatCtx_ null!";
|
||||||
return APP_ERR_COMM_FAILURE;
|
return APP_ERR_COMM_FAILURE;
|
||||||
}
|
}
|
||||||
|
|
@ -72,8 +63,7 @@ APP_ERROR CameraEngine::ConnectCamera()
|
||||||
// get stream infomation
|
// get stream infomation
|
||||||
int iRet = APP_ERR_OK;
|
int iRet = APP_ERR_OK;
|
||||||
iRet = GetStreamInfo();
|
iRet = GetStreamInfo();
|
||||||
if (iRet != APP_ERR_OK)
|
if (iRet != APP_ERR_OK) {
|
||||||
{
|
|
||||||
LogError << "engineId_:" << engineId_ << " Stream Info Check failed, iRet = " << iRet;
|
LogError << "engineId_:" << engineId_ << " Stream Info Check failed, iRet = " << iRet;
|
||||||
return APP_ERR_COMM_FAILURE;
|
return APP_ERR_COMM_FAILURE;
|
||||||
}
|
}
|
||||||
|
|
@ -81,92 +71,68 @@ APP_ERROR CameraEngine::ConnectCamera()
|
||||||
return APP_ERR_OK;
|
return APP_ERR_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
APP_ERROR CameraEngine::GetStreamInfo()
|
APP_ERROR CameraEngine::GetStreamInfo() {
|
||||||
{
|
if (pFormatCtx_ != nullptr) {
|
||||||
if (pFormatCtx_ != nullptr)
|
|
||||||
{
|
|
||||||
iVideoStream_ = -1;
|
iVideoStream_ = -1;
|
||||||
iAudioStream_ = -1;
|
iAudioStream_ = -1;
|
||||||
//frameInfo_.iFrameId = 0; //帧号从0开始
|
//frameInfo_.iFrameId = 0; //帧号从0开始
|
||||||
|
|
||||||
for (unsigned int i = 0; i < pFormatCtx_->nb_streams; i++)
|
for (unsigned int i = 0; i < pFormatCtx_->nb_streams; i++) {
|
||||||
{
|
|
||||||
AVStream *inStream = pFormatCtx_->streams[i];
|
AVStream *inStream = pFormatCtx_->streams[i];
|
||||||
if (inStream->codecpar->codec_type == AVMEDIA_TYPE_VIDEO)
|
if (inStream->codecpar->codec_type == AVMEDIA_TYPE_VIDEO) {
|
||||||
{
|
|
||||||
iVideoStream_ = i;
|
iVideoStream_ = i;
|
||||||
frameInfo_.iHeight = inStream->codecpar->height;
|
frameInfo_.iHeight = inStream->codecpar->height;
|
||||||
frameInfo_.iWidth = inStream->codecpar->width;
|
frameInfo_.iWidth = inStream->codecpar->width;
|
||||||
|
|
||||||
//获取帧率,帧率的打印都在流中的两个成员.且应取平均帧率为先,为{x,0}或者{0,1}则取实时帧率
|
//获取帧率,帧率的打印都在流中的两个成员.且应取平均帧率为先,为{x,0}或者{0,1}则取实时帧率
|
||||||
if (inStream->avg_frame_rate.den == 0 || (inStream->avg_frame_rate.num == 0 && inStream->avg_frame_rate.den == 1))
|
if (inStream->avg_frame_rate.den == 0 ||
|
||||||
{
|
(inStream->avg_frame_rate.num == 0 && inStream->avg_frame_rate.den == 1)) {
|
||||||
frameInfo_.iRate = inStream->r_frame_rate.num / inStream->r_frame_rate.den;
|
frameInfo_.iRate = inStream->r_frame_rate.num / inStream->r_frame_rate.den;
|
||||||
}
|
} else {
|
||||||
else
|
|
||||||
{
|
|
||||||
frameInfo_.iRate = inStream->avg_frame_rate.num / inStream->avg_frame_rate.den;
|
frameInfo_.iRate = inStream->avg_frame_rate.num / inStream->avg_frame_rate.den;
|
||||||
}
|
}
|
||||||
LogDebug << "engineId_:" << engineId_ << " width:" << frameInfo_.iWidth << " height:" << frameInfo_.iHeight
|
LogDebug << "engineId_:" << engineId_ << " width:" << frameInfo_.iWidth << " height:"
|
||||||
|
<< frameInfo_.iHeight
|
||||||
<< " rate:" << frameInfo_.iRate << " iVideoStream_:" << iVideoStream_;
|
<< " rate:" << frameInfo_.iRate << " iVideoStream_:" << iVideoStream_;
|
||||||
}
|
} else if (inStream->codecpar->codec_type == AVMEDIA_TYPE_AUDIO) {
|
||||||
else if (inStream->codecpar->codec_type == AVMEDIA_TYPE_AUDIO)
|
|
||||||
{
|
|
||||||
iAudioStream_ = i;
|
iAudioStream_ = i;
|
||||||
LogDebug << "engineId_:" << engineId_ << " iAudioStream_:" << iAudioStream_;
|
LogDebug << "engineId_:" << engineId_ << " iAudioStream_:" << iAudioStream_;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (iVideoStream_ == -1)
|
if (iVideoStream_ == -1) {
|
||||||
{
|
|
||||||
LogError << "engineId_:" << engineId_ << " Didn't find a video stream!";
|
LogError << "engineId_:" << engineId_ << " Didn't find a video stream!";
|
||||||
return APP_ERR_COMM_FAILURE;
|
return APP_ERR_COMM_FAILURE;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (frameInfo_.iHeight < LOW_THRESHOLD || frameInfo_.iWidth < LOW_THRESHOLD ||
|
if (frameInfo_.iHeight < LOW_THRESHOLD || frameInfo_.iWidth < LOW_THRESHOLD ||
|
||||||
frameInfo_.iHeight > MAX_THRESHOLD || frameInfo_.iWidth > MAX_THRESHOLD)
|
frameInfo_.iHeight > MAX_THRESHOLD || frameInfo_.iWidth > MAX_THRESHOLD) {
|
||||||
{
|
|
||||||
LogError << "engineId_:" << engineId_ << " Size of frame is not supported in DVPP Video Decode!";
|
LogError << "engineId_:" << engineId_ << " Size of frame is not supported in DVPP Video Decode!";
|
||||||
return APP_ERR_COMM_FAILURE;
|
return APP_ERR_COMM_FAILURE;
|
||||||
}
|
}
|
||||||
|
|
||||||
AVCodecID codecId = pFormatCtx_->streams[iVideoStream_]->codecpar->codec_id;
|
AVCodecID codecId = pFormatCtx_->streams[iVideoStream_]->codecpar->codec_id;
|
||||||
if (codecId == AV_CODEC_ID_H264)
|
if (codecId == AV_CODEC_ID_H264) {
|
||||||
{
|
|
||||||
int profile = pFormatCtx_->streams[iVideoStream_]->codecpar->profile;
|
int profile = pFormatCtx_->streams[iVideoStream_]->codecpar->profile;
|
||||||
if (profile == FF_PROFILE_H264_BASELINE)
|
if (profile == FF_PROFILE_H264_BASELINE) {
|
||||||
{
|
|
||||||
frameInfo_.format = H264_BASELINE_LEVEL;
|
frameInfo_.format = H264_BASELINE_LEVEL;
|
||||||
}
|
} else if (profile == FF_PROFILE_H264_MAIN) {
|
||||||
else if (profile == FF_PROFILE_H264_MAIN)
|
|
||||||
{
|
|
||||||
frameInfo_.format = H264_MAIN_LEVEL;
|
frameInfo_.format = H264_MAIN_LEVEL;
|
||||||
}
|
} else if (profile == FF_PROFILE_H264_HIGH) {
|
||||||
else if (profile == FF_PROFILE_H264_HIGH)
|
|
||||||
{
|
|
||||||
frameInfo_.format = H264_HIGH_LEVEL;
|
frameInfo_.format = H264_HIGH_LEVEL;
|
||||||
}
|
} else {
|
||||||
else
|
|
||||||
{
|
|
||||||
LogError << "engineId_:" << engineId_ << " not support h264 profile";
|
LogError << "engineId_:" << engineId_ << " not support h264 profile";
|
||||||
return APP_ERR_COMM_FAILURE;
|
return APP_ERR_COMM_FAILURE;
|
||||||
}
|
}
|
||||||
}
|
} else if (codecId == AV_CODEC_ID_H265) {
|
||||||
else if (codecId == AV_CODEC_ID_H265)
|
|
||||||
{
|
|
||||||
int profile = pFormatCtx_->streams[iVideoStream_]->codecpar->profile;
|
int profile = pFormatCtx_->streams[iVideoStream_]->codecpar->profile;
|
||||||
if (profile == FF_PROFILE_HEVC_MAIN)
|
if (profile == FF_PROFILE_HEVC_MAIN) {
|
||||||
{
|
|
||||||
frameInfo_.format = H265_MAIN_LEVEL;
|
frameInfo_.format = H265_MAIN_LEVEL;
|
||||||
}
|
} else {
|
||||||
else
|
|
||||||
{
|
|
||||||
LogError << "engineId_:" << engineId_ << " not support h265 profile";
|
LogError << "engineId_:" << engineId_ << " not support h265 profile";
|
||||||
return APP_ERR_COMM_FAILURE;
|
return APP_ERR_COMM_FAILURE;
|
||||||
}
|
}
|
||||||
}
|
} else {
|
||||||
else
|
|
||||||
{
|
|
||||||
LogError << "engineId_:" << engineId_ << " Error unsupported format" << codecId;
|
LogError << "engineId_:" << engineId_ << " Error unsupported format" << codecId;
|
||||||
return APP_ERR_COMM_FAILURE;
|
return APP_ERR_COMM_FAILURE;
|
||||||
}
|
}
|
||||||
|
|
@ -174,8 +140,7 @@ APP_ERROR CameraEngine::GetStreamInfo()
|
||||||
return APP_ERR_OK;
|
return APP_ERR_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
AVFormatContext *CameraEngine::CreateFormatContext()
|
AVFormatContext *CameraEngine::CreateFormatContext() {
|
||||||
{
|
|
||||||
// create message for stream pull
|
// create message for stream pull
|
||||||
AVFormatContext *pFormatContext = nullptr;
|
AVFormatContext *pFormatContext = nullptr;
|
||||||
AVDictionary *pOptions = nullptr;
|
AVDictionary *pOptions = nullptr;
|
||||||
|
|
@ -184,24 +149,21 @@ AVFormatContext *CameraEngine::CreateFormatContext()
|
||||||
if (dataSourceConfig_.strUrl.find("rtsp:") != std::string::npos) // rtsp
|
if (dataSourceConfig_.strUrl.find("rtsp:") != std::string::npos) // rtsp
|
||||||
{
|
{
|
||||||
av_dict_set(&pOptions, "rtsp_transport", "tcp", 0); // 指定其传输方式为TCP
|
av_dict_set(&pOptions, "rtsp_transport", "tcp", 0); // 指定其传输方式为TCP
|
||||||
// av_dict_set(&pOptions, "stimeout", "3000000", 0); // 设置超时3秒
|
av_dict_set(&pOptions, "stimeout", "3000000", 0); // 设置超时3秒
|
||||||
// av_dict_set(&pOptions, "rw_timeout", "3000", 0); //单位:ms
|
|
||||||
av_dict_set(&pOptions, "timeout", "3000000", 0); //设置超时时间为3秒
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//av_register_all(); //注册所有支持的格式(这里一定注册这些,否则会因为协议解析问题报错!!!)
|
av_register_all(); //注册所有支持的格式(这里一定注册这些,否则会因为协议解析问题报错!!!)
|
||||||
//avcodec_register_all(); //注册编解码器
|
avcodec_register_all(); //注册编解码器
|
||||||
//avformat_network_init(); //注册网格格式,如果为本地文件则可以去掉该代码
|
avformat_network_init(); //注册网格格式,如果为本地文件则可以去掉该代码
|
||||||
|
|
||||||
int iRet = avformat_open_input(&pFormatContext, dataSourceConfig_.strUrl.c_str(), nullptr, &pOptions);
|
int iRet = avformat_open_input(&pFormatContext, dataSourceConfig_.strUrl.c_str(), nullptr, &pOptions);
|
||||||
if (nullptr != pOptions)
|
if (nullptr != pOptions) {
|
||||||
{
|
|
||||||
av_dict_free(&pOptions);
|
av_dict_free(&pOptions);
|
||||||
}
|
}
|
||||||
if (iRet != 0)
|
if (iRet != 0) {
|
||||||
{
|
LogError << "engineId_:" << engineId_ << " Couldn't open input stream " << dataSourceConfig_.strUrl.c_str()
|
||||||
LogError << "engineId_:" << engineId_ << " Couldn't open input stream " << dataSourceConfig_.strUrl.c_str() << ", iRet=" << iRet;
|
<< ", iRet=" << iRet;
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -216,8 +178,7 @@ AVFormatContext *CameraEngine::CreateFormatContext()
|
||||||
// }
|
// }
|
||||||
|
|
||||||
iRet = avformat_find_stream_info(pFormatContext, nullptr);
|
iRet = avformat_find_stream_info(pFormatContext, nullptr);
|
||||||
if (iRet != 0)
|
if (iRet != 0) {
|
||||||
{
|
|
||||||
LogError << "engineId_:" << engineId_ << " Couldn't find stream information, iRet = " << iRet;
|
LogError << "engineId_:" << engineId_ << " Couldn't find stream information, iRet = " << iRet;
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
@ -225,57 +186,44 @@ AVFormatContext *CameraEngine::CreateFormatContext()
|
||||||
}
|
}
|
||||||
|
|
||||||
//av_read_frame的中断回调函数
|
//av_read_frame的中断回调函数
|
||||||
// int CameraEngine::InterruptCallback(void *pData)
|
int CameraEngine::InterruptCallback(void *pData) {
|
||||||
// {
|
TimeoutContext *pTimeOutCtx = (TimeoutContext *) pData;
|
||||||
// TimeoutContext* pTimeOutCtx = (TimeoutContext*)pData;
|
LogDebug << "InterruptCallback i64Timeout:" << pTimeOutCtx->i64Timeout;
|
||||||
// LogDebug << "InterruptCallback i64Timeout:" << pTimeOutCtx->i64Timeout;
|
return std::chrono::duration_cast<std::chrono::milliseconds>(
|
||||||
// return std::chrono::duration_cast<std::chrono::milliseconds>(
|
std::chrono::system_clock::now().time_since_epoch())
|
||||||
// std::chrono::system_clock::now().time_since_epoch())
|
.count() >= pTimeOutCtx->i64Timeout
|
||||||
// .count() >= pTimeOutCtx->i64Timeout
|
? AVERROR_EXIT
|
||||||
// ? AVERROR_EXIT
|
: 0;
|
||||||
// : 0;
|
}
|
||||||
// }
|
|
||||||
|
|
||||||
APP_ERROR CameraEngine::Process()
|
APP_ERROR CameraEngine::Process() {
|
||||||
{
|
|
||||||
int iRet = APP_ERR_OK;
|
int iRet = APP_ERR_OK;
|
||||||
if (!bUseEngine_)
|
if (!bUseEngine_) {
|
||||||
{
|
|
||||||
LogWarn << "engineId_:" << engineId_ << " not use engine";
|
LogWarn << "engineId_:" << engineId_ << " not use engine";
|
||||||
return APP_ERR_OK;
|
return APP_ERR_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (bHwDecode_)
|
if (bHwDecode_) {
|
||||||
{
|
|
||||||
iRet = ConnectCamera();
|
iRet = ConnectCamera();
|
||||||
if (iRet == APP_ERR_OK)
|
if (iRet == APP_ERR_OK) {
|
||||||
{
|
|
||||||
LogInfo << "engineId_:" << engineId_ << " Start the stream......";
|
LogInfo << "engineId_:" << engineId_ << " Start the stream......";
|
||||||
bReconnectFlag_ = false;
|
bReconnectFlag_ = false;
|
||||||
}
|
} else {
|
||||||
else
|
|
||||||
{
|
|
||||||
ResetCamera();
|
ResetCamera();
|
||||||
bReconnectFlag_ = true;
|
bReconnectFlag_ = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Pull data cyclically
|
// Pull data cyclically
|
||||||
AVPacket pkt;
|
AVPacket pkt;
|
||||||
|
while (!isStop_) {
|
||||||
while (!isStop_)
|
|
||||||
{
|
|
||||||
//重连相机
|
//重连相机
|
||||||
if (bReconnectFlag_)
|
if (bReconnectFlag_) {
|
||||||
{
|
|
||||||
iRet = ConnectCamera();
|
iRet = ConnectCamera();
|
||||||
if (iRet == APP_ERR_OK)
|
if (iRet == APP_ERR_OK) {
|
||||||
{
|
|
||||||
LogInfo << "engineId_:" << engineId_ << " Start the stream......";
|
LogInfo << "engineId_:" << engineId_ << " Start the stream......";
|
||||||
bReconnectFlag_ = false;
|
bReconnectFlag_ = false;
|
||||||
}
|
} else {
|
||||||
else
|
// outputQueMap_[strPort1_]->push(std::static_pointer_cast<void>(std::make_shared<std::string>("摄像头连接失败!")));
|
||||||
{
|
|
||||||
outputQueMap_[strPort1_]->push(std::static_pointer_cast<void>(std::make_shared<std::string>("摄像头连接失败!")));
|
|
||||||
ResetCamera();
|
ResetCamera();
|
||||||
std::this_thread::sleep_for(std::chrono::seconds(3)); //3秒后重连
|
std::this_thread::sleep_for(std::chrono::seconds(3)); //3秒后重连
|
||||||
continue;
|
continue;
|
||||||
|
|
@ -283,16 +231,24 @@ APP_ERROR CameraEngine::Process()
|
||||||
}
|
}
|
||||||
|
|
||||||
//设置av_read_frame中断函数 (中断函数中超过1s,则中断处理)
|
//设置av_read_frame中断函数 (中断函数中超过1s,则中断处理)
|
||||||
// TimeoutContext timeoutCtx = { std::chrono::duration_cast<std::chrono::milliseconds>(std::chrono::system_clock::now().time_since_epoch()).count() + 1000 };
|
TimeoutContext timeoutCtx = {std::chrono::duration_cast<std::chrono::milliseconds>(
|
||||||
// pFormatCtx_->interrupt_callback.callback = &CameraEngine::InterruptCallback;
|
std::chrono::system_clock::now().time_since_epoch()).count() + 1000};
|
||||||
// pFormatCtx_->interrupt_callback.opaque = &timeoutCtx;
|
pFormatCtx_->interrupt_callback.callback = InterruptCallback;
|
||||||
|
pFormatCtx_->interrupt_callback.opaque = &timeoutCtx;
|
||||||
|
|
||||||
av_init_packet(&pkt); //init pkt
|
av_init_packet(&pkt); //init pkt
|
||||||
|
|
||||||
iRet = av_read_frame(pFormatCtx_, &pkt); //需要一直读取,否则获取到的是历史数据
|
iRet = av_read_frame(pFormatCtx_, &pkt); //需要一直读取,否则获取到的是历史数据
|
||||||
if (iRet != 0)
|
|
||||||
{
|
//校验是否存取到结尾
|
||||||
outputQueMap_[strPort1_]->push(std::static_pointer_cast<void>(std::make_shared<std::string>("图像读取失败!")));
|
if (iRet == AVERROR_EOF) {
|
||||||
|
LogInfo << "CameraEngine--av_read_frame--end!";
|
||||||
|
// break;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (iRet != 0) {
|
||||||
|
outputQueMap_[strPort1_]->push(
|
||||||
|
std::static_pointer_cast<void>(std::make_shared<std::string>("图像读取失败!")));
|
||||||
LogError << "engineId_:" << engineId_ << " Read frame failed, reconnect iRet:" << iRet;
|
LogError << "engineId_:" << engineId_ << " Read frame failed, reconnect iRet:" << iRet;
|
||||||
av_packet_unref(&pkt);
|
av_packet_unref(&pkt);
|
||||||
|
|
||||||
|
|
@ -301,64 +257,58 @@ APP_ERROR CameraEngine::Process()
|
||||||
|
|
||||||
bReconnectFlag_ = true;
|
bReconnectFlag_ = true;
|
||||||
continue;
|
continue;
|
||||||
}
|
} else if (pkt.stream_index == iVideoStream_) //只解码视频流
|
||||||
else if (pkt.stream_index == iVideoStream_) //只解码视频流
|
|
||||||
{
|
{
|
||||||
// LogDebug << "iRet:" << iRet << " pkt.size:" << pkt.size;
|
// LogDebug << "iRet:" << iRet << " pkt.size:" << pkt.size;
|
||||||
if (pkt.size <= 0)
|
if (pkt.size <= 0) {
|
||||||
{
|
|
||||||
LogError << "engineId_:" << engineId_ << " Invalid pkt.size: " << pkt.size;
|
LogError << "engineId_:" << engineId_ << " Invalid pkt.size: " << pkt.size;
|
||||||
av_packet_unref(&pkt);
|
av_packet_unref(&pkt);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
if (dataSourceConfig_.strUrl.find(".mp4") != std::string::npos)
|
if (dataSourceConfig_.strUrl.find(".mp4") != std::string::npos) {
|
||||||
{
|
|
||||||
const char szStartCode[4] = {0, 0, 0, 1};
|
const char szStartCode[4] = {0, 0, 0, 1};
|
||||||
if (bIsAvc_ || memcmp(szStartCode, pkt.data, 4) != 0)
|
if (bIsAvc_ || memcmp(szStartCode, pkt.data, 4) != 0) { // is avc1 code, have no start code of H264
|
||||||
{ // is avc1 code, have no start code of H264
|
|
||||||
int iLen = 0;
|
int iLen = 0;
|
||||||
uint8_t *p = pkt.data;
|
uint8_t *p = pkt.data;
|
||||||
bIsAvc_ = true;
|
bIsAvc_ = true;
|
||||||
do
|
do { // add start_code for each NAL, one frame may have multi NALs.
|
||||||
{ // add start_code for each NAL, one frame may have multi NALs.
|
iLen = ntohl(*((long *) p));
|
||||||
iLen = ntohl(*((long *)p));
|
|
||||||
memcpy(p, szStartCode, 4);
|
memcpy(p, szStartCode, 4);
|
||||||
p += 4;
|
p += 4;
|
||||||
p += iLen;
|
p += iLen;
|
||||||
if (p >= pkt.data + pkt.size)
|
if (p >= pkt.data + pkt.size) {
|
||||||
{
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
} while (1);
|
} while (1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void* pH264Buffer = nullptr;
|
void *pH264Buffer = nullptr;
|
||||||
pH264Buffer = new uint8_t[pkt.size];
|
pH264Buffer = new uint8_t[pkt.size];
|
||||||
memcpy(pH264Buffer, pkt.data, pkt.size);
|
memcpy(pH264Buffer, pkt.data, pkt.size);
|
||||||
//组织数据
|
//组织数据
|
||||||
std::shared_ptr<ProcessData> pProcessData = std::make_shared<ProcessData>();
|
std::shared_ptr <ProcessData> pProcessData = std::make_shared<ProcessData>();
|
||||||
pProcessData->iWidth = frameInfo_.iWidth;
|
pProcessData->iWidth = frameInfo_.iWidth;
|
||||||
pProcessData->iHeight = frameInfo_.iHeight;
|
pProcessData->iHeight = frameInfo_.iHeight;
|
||||||
pProcessData->iRate = frameInfo_.iRate;
|
pProcessData->iRate = frameInfo_.iRate;
|
||||||
pProcessData->i64TimeStamp = MyUtils::getins()->GetCurrentTimeMillis();
|
pProcessData->i64TimeStamp = MyUtils::getins()->GetCurrentTimeMillis();
|
||||||
pProcessData->iDataSource = engineId_;
|
pProcessData->iDataSource = engineId_;
|
||||||
pProcessData->iSize = pkt.size;
|
pProcessData->iSize = pkt.size;
|
||||||
pProcessData->pData.reset(pH264Buffer, [](void* data){if(data) {delete[] data; data = nullptr;}}); //智能指针管理内存
|
pProcessData->pData.reset(pH264Buffer, [](void *data) {
|
||||||
|
if (data) {
|
||||||
|
delete[] data;
|
||||||
|
data = nullptr;
|
||||||
|
}
|
||||||
|
}); //智能指针管理内存
|
||||||
|
|
||||||
//push端口0,视频解码
|
//push端口0,视频解码
|
||||||
iRet = outputQueMap_[strPort0_]->push(std::static_pointer_cast<void>(pProcessData));
|
iRet = outputQueMap_[strPort0_]->push(std::static_pointer_cast<void>(pProcessData), true);
|
||||||
if (iRet != APP_ERR_OK)
|
if (iRet != APP_ERR_OK) {
|
||||||
{
|
|
||||||
LogError << "engineId_:" << engineId_ << "push the h264 frame data failed...";
|
LogError << "engineId_:" << engineId_ << "push the h264 frame data failed...";
|
||||||
}
|
}
|
||||||
}
|
} else if (pkt.stream_index == iAudioStream_) {
|
||||||
else if (pkt.stream_index == iAudioStream_)
|
|
||||||
{
|
|
||||||
//音频流不处理。
|
//音频流不处理。
|
||||||
}
|
} else {
|
||||||
else
|
|
||||||
{
|
|
||||||
LogError << "engineId_:" << engineId_ << " stream err stream_index:" << pkt.stream_index;
|
LogError << "engineId_:" << engineId_ << " stream err stream_index:" << pkt.stream_index;
|
||||||
}
|
}
|
||||||
av_packet_unref(&pkt); //unref
|
av_packet_unref(&pkt); //unref
|
||||||
|
|
@ -368,19 +318,17 @@ APP_ERROR CameraEngine::Process()
|
||||||
usleep(DELAY_TIME); // delay 40ms
|
usleep(DELAY_TIME); // delay 40ms
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
} else {
|
||||||
else
|
|
||||||
{
|
|
||||||
//从摄像头RTSP拉流
|
//从摄像头RTSP拉流
|
||||||
const std::string videoStreamAddress = std::string("rtspsrc location=") + dataSourceConfig_.strUrl.c_str() + " latency=10 ! \
|
const std::string videoStreamAddress = std::string("rtspsrc location=") + dataSourceConfig_.strUrl.c_str() + " latency=10 ! \
|
||||||
rtph264depay ! h264parse ! nvv4l2decoder enable-max-performance=1 enable-frame-type-reporting=1 ! nvvidconv ! video/x-raw, format=(string)BGRx ! videoconvert ! appsink";
|
rtph264depay ! h264parse ! nvv4l2decoder enable-max-performance=1 enable-frame-type-reporting=1 ! nvvidconv ! video/x-raw, format=(string)BGRx ! videoconvert ! appsink";
|
||||||
|
|
||||||
VideoCapture capture_video;
|
VideoCapture capture_video;
|
||||||
while(!capture_video.open(videoStreamAddress)){ //, cv::CAP_FFMPEG
|
while (!capture_video.open(videoStreamAddress)) { //, cv::CAP_FFMPEG
|
||||||
LogInfo<<"Restart Opening video stream or file ..."<<std::endl;
|
LogInfo << "Restart Opening video stream or file ..." << std::endl;
|
||||||
sleep(1);
|
sleep(1);
|
||||||
}
|
}
|
||||||
LogInfo<<"Opening video stream or file Success:"<<engineId_;
|
LogInfo << "Opening video stream or file Success:" << engineId_;
|
||||||
|
|
||||||
int frameW = capture_video.get(3);
|
int frameW = capture_video.get(3);
|
||||||
int frameH = capture_video.get(4);
|
int frameH = capture_video.get(4);
|
||||||
|
|
@ -390,25 +338,24 @@ APP_ERROR CameraEngine::Process()
|
||||||
bool breadend = false;
|
bool breadend = false;
|
||||||
cv::Mat frame(frameH, frameW, CV_8UC3);
|
cv::Mat frame(frameH, frameW, CV_8UC3);
|
||||||
|
|
||||||
while (!isStop_)
|
while (!isStop_) {
|
||||||
{
|
std::shared_ptr <FrameData> pBGRFrameData = std::make_shared<FrameData>();
|
||||||
std::shared_ptr<FrameData> pBGRFrameData = std::make_shared<FrameData>();
|
std::shared_ptr <ProcessData> pProcessData = std::make_shared<ProcessData>();
|
||||||
std::shared_ptr<ProcessData> pProcessData = std::make_shared<ProcessData>();
|
if (!capture_video.read(frame)) {
|
||||||
if(!capture_video.read(frame)) {
|
|
||||||
capture_video.release();
|
capture_video.release();
|
||||||
while(!capture_video.open(videoStreamAddress)){ //, cv::CAP_FFMPEG
|
while (!capture_video.open(videoStreamAddress)) { //, cv::CAP_FFMPEG
|
||||||
LogInfo<<"Restart Opening video stream or file ..."<<std::endl;
|
LogInfo << "Restart Opening video stream or file ..." << std::endl;
|
||||||
sleep(1);
|
sleep(1);
|
||||||
}
|
}
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
unsigned int resizepBGRBuffer_Size = IMAGE_WIDTH*IMAGE_HEIGHT*3;
|
unsigned int resizepBGRBuffer_Size = IMAGE_WIDTH * IMAGE_HEIGHT * 3;
|
||||||
|
|
||||||
cv::Mat mtInImage, mtOutImage;
|
cv::Mat mtInImage, mtOutImage;
|
||||||
cv::resize(frame, mtInImage, cv::Size(IMAGE_WIDTH, IMAGE_HEIGHT));
|
cv::resize(frame, mtInImage, cv::Size(IMAGE_WIDTH, IMAGE_HEIGHT));
|
||||||
cv::cvtColor(mtInImage, mtOutImage, cv::COLOR_BGR2RGB);
|
cv::cvtColor(mtInImage, mtOutImage, cv::COLOR_BGR2RGB);
|
||||||
|
|
||||||
void* resizeBGRBufferobj = nullptr;
|
void *resizeBGRBufferobj = nullptr;
|
||||||
resizeBGRBufferobj = new uint8_t[resizepBGRBuffer_Size];
|
resizeBGRBufferobj = new uint8_t[resizepBGRBuffer_Size];
|
||||||
memcpy(resizeBGRBufferobj, mtOutImage.data, resizepBGRBuffer_Size);
|
memcpy(resizeBGRBufferobj, mtOutImage.data, resizepBGRBuffer_Size);
|
||||||
|
|
||||||
|
|
@ -419,16 +366,21 @@ APP_ERROR CameraEngine::Process()
|
||||||
pBGRFrameData->frameInfo.iHeight = IMAGE_HEIGHT;
|
pBGRFrameData->frameInfo.iHeight = IMAGE_HEIGHT;
|
||||||
pBGRFrameData->frameInfo.iRate = frameRate;
|
pBGRFrameData->frameInfo.iRate = frameRate;
|
||||||
pProcessData->pVoidData = std::static_pointer_cast<void>(pBGRFrameData);
|
pProcessData->pVoidData = std::static_pointer_cast<void>(pBGRFrameData);
|
||||||
pProcessData->pData.reset(resizeBGRBufferobj, [](void* data){if(data) {delete[] data; data = nullptr;}});
|
pProcessData->pData.reset(resizeBGRBufferobj, [](void *data) {
|
||||||
if (nFrameid >= 0xFFFFFFFF) {nFrameid = 0;}
|
if (data) {
|
||||||
|
delete[] data;
|
||||||
|
data = nullptr;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
if (nFrameid >= 0xFFFFFFFF) { nFrameid = 0; }
|
||||||
pBGRFrameData->i64TimeStamp = MyUtils::getins()->GetCurrentTimeMillis();
|
pBGRFrameData->i64TimeStamp = MyUtils::getins()->GetCurrentTimeMillis();
|
||||||
pProcessData->iWidth = pBGRFrameData->frameInfo.iWidth;
|
pProcessData->iWidth = pBGRFrameData->frameInfo.iWidth;
|
||||||
pProcessData->iHeight = pBGRFrameData->frameInfo.iHeight;
|
pProcessData->iHeight = pBGRFrameData->frameInfo.iHeight;
|
||||||
pProcessData->iHeight = pBGRFrameData->frameInfo.iRate;
|
pProcessData->iHeight = pBGRFrameData->frameInfo.iRate;
|
||||||
iRet = outputQueMap_[strPort0_]->push(std::static_pointer_cast<void>(pProcessData));
|
iRet = outputQueMap_[strPort0_]->push(std::static_pointer_cast<void>(pProcessData), true);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return APP_ERR_OK;
|
return APP_ERR_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -50,7 +50,7 @@ protected:
|
||||||
APP_ERROR GetStreamInfo();
|
APP_ERROR GetStreamInfo();
|
||||||
APP_ERROR ConnectCamera(); //连接相机
|
APP_ERROR ConnectCamera(); //连接相机
|
||||||
void ResetCamera(); //复位相机连接
|
void ResetCamera(); //复位相机连接
|
||||||
//static int InterruptCallback(void *pData);
|
static int InterruptCallback(void *pData);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
AVFormatContext *pFormatCtx_ = nullptr;
|
AVFormatContext *pFormatCtx_ = nullptr;
|
||||||
|
|
|
||||||
|
|
@ -84,6 +84,7 @@ std::string ReadImgEngine::GetFileName(const std::string &strParam)
|
||||||
|
|
||||||
APP_ERROR ReadImgEngine::Process()
|
APP_ERROR ReadImgEngine::Process()
|
||||||
{
|
{
|
||||||
|
|
||||||
if (!bUseEngine_)
|
if (!bUseEngine_)
|
||||||
{
|
{
|
||||||
LogWarn << "engineId_:" << engineId_ << " not use engine";
|
LogWarn << "engineId_:" << engineId_ << " not use engine";
|
||||||
|
|
@ -103,6 +104,7 @@ APP_ERROR ReadImgEngine::Process()
|
||||||
int iFileIndex = 0; //文件序号
|
int iFileIndex = 0; //文件序号
|
||||||
while (!isStop_)
|
while (!isStop_)
|
||||||
{
|
{
|
||||||
|
|
||||||
std::string strFilePath = vecFiles_.at(iFileIndex);
|
std::string strFilePath = vecFiles_.at(iFileIndex);
|
||||||
cv::Mat matBGR = cv::imread(strFilePath);
|
cv::Mat matBGR = cv::imread(strFilePath);
|
||||||
|
|
||||||
|
|
@ -150,7 +152,6 @@ APP_ERROR ReadImgEngine::Process()
|
||||||
|
|
||||||
//break; //只发布一遍
|
//break; //只发布一遍
|
||||||
}
|
}
|
||||||
|
|
||||||
//模拟1秒25帧
|
//模拟1秒25帧
|
||||||
usleep(40000); //40ms
|
usleep(40000); //40ms
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -41,7 +41,7 @@ void DeleteExpiredFolderEngine::DeletePreviousFolder(std::string path, const std
|
||||||
// 1 computer date
|
// 1 computer date
|
||||||
std::string previous_date = getDateBeforeNDays(date, n_days);
|
std::string previous_date = getDateBeforeNDays(date, n_days);
|
||||||
if (!previous_date.empty())
|
if (!previous_date.empty())
|
||||||
std::cout << "Date before " << n_days << " days from " << date << " is: " << previous_date << std::endl;
|
LogDebug << "Date before " << n_days << " days from " << date << " is: " << previous_date;
|
||||||
|
|
||||||
|
|
||||||
// 2
|
// 2
|
||||||
|
|
@ -139,7 +139,7 @@ void DeleteExpiredFolderEngine::GetSubfolderNames(std::string &directory, std::v
|
||||||
while ((ent = readdir(dir)) != nullptr)
|
while ((ent = readdir(dir)) != nullptr)
|
||||||
{
|
{
|
||||||
// 排除"."和".."
|
// 排除"."和".."
|
||||||
if (ent->d_type == DT_DIR && ent->d_name[0] != '.' && ent->d_name == "best")
|
if (ent->d_type == DT_DIR && ent->d_name[0] != '.' && ent->d_name != "best")
|
||||||
{
|
{
|
||||||
folder_names.push_back(StrToDate(ent->d_name));
|
folder_names.push_back(StrToDate(ent->d_name));
|
||||||
}
|
}
|
||||||
|
|
@ -158,9 +158,9 @@ void DeleteExpiredFolderEngine::DeleteFolder(const std::string directory)
|
||||||
int result = system(command.c_str());
|
int result = system(command.c_str());
|
||||||
|
|
||||||
if (result != 0)
|
if (result != 0)
|
||||||
std::cout << "Failed to remove directory recursively: " << directory << std::endl;
|
LogError << "Failed to remove directory recursively: " << directory;
|
||||||
else
|
else
|
||||||
std::cout << "delete folder successfully : " << directory << std::endl;
|
LogError << "delete folder successfully : " << directory;
|
||||||
}
|
}
|
||||||
|
|
||||||
// 删除向量中小于指定日期的所有元素
|
// 删除向量中小于指定日期的所有元素
|
||||||
|
|
|
||||||
|
|
@ -988,8 +988,9 @@ void FilterTrainStepOneEngine::DealProcessDataPre(std::shared_ptr<ProcessData> p
|
||||||
|
|
||||||
// this->sendComeTrain(pProcessData->strTrainDate, pProcessData->strTrainName, iDirection_);
|
// this->sendComeTrain(pProcessData->strTrainDate, pProcessData->strTrainName, iDirection_);
|
||||||
|
|
||||||
|
outputQueMap_[strPort0_]->push(std::static_pointer_cast<void>(iterProcessData->second), true);
|
||||||
//上一帧,push端口0
|
//上一帧,push端口0
|
||||||
PushData(strPort0_, iterProcessData->second);
|
// PushData(strPort0_, iterProcessData->second);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -1037,7 +1038,8 @@ APP_ERROR FilterTrainStepOneEngine::Process()
|
||||||
{
|
{
|
||||||
//结束帧,push端口0
|
//结束帧,push端口0
|
||||||
LogDebug << "sourceid:" << pProcessData->iDataSource << " frameid:" << pProcessData->iFrameId << " isEnd:" << pProcessData->bIsEnd;
|
LogDebug << "sourceid:" << pProcessData->iDataSource << " frameid:" << pProcessData->iFrameId << " isEnd:" << pProcessData->bIsEnd;
|
||||||
PushData(strPort0_, pProcessData);
|
// PushData(strPort0_, pProcessData);
|
||||||
|
outputQueMap_[strPort0_]->push(std::static_pointer_cast<void>(pProcessData), true);
|
||||||
}
|
}
|
||||||
|
|
||||||
//3. 全部结束,初始化相关参数
|
//3. 全部结束,初始化相关参数
|
||||||
|
|
|
||||||
|
|
@ -113,6 +113,8 @@ void MergerAllEngine::PushData(std::shared_ptr<Train> pTrain)
|
||||||
<< "集装箱2: " << pTrain->container2.strContainerNo << "\n"
|
<< "集装箱2: " << pTrain->container2.strContainerNo << "\n"
|
||||||
<< "集装箱2图片: " << pTrain->container2.strBestImg << "\n"
|
<< "集装箱2图片: " << pTrain->container2.strBestImg << "\n"
|
||||||
<< "集装箱2时间戳: " << pTrain->container2.i64TimeStamp << "\n"
|
<< "集装箱2时间戳: " << pTrain->container2.i64TimeStamp << "\n"
|
||||||
|
<< "车厢开始时间: " << MyUtils::getins()->Stamp2Time(pTrain->i64StartTimeStamp, true) << "\n"
|
||||||
|
<< "车厢结束时间: " << MyUtils::getins()->Stamp2Time(pTrain->i64EndTimeStamp, true) << "\n"
|
||||||
<< " ---所有信息合并结果 END--- ";
|
<< " ---所有信息合并结果 END--- ";
|
||||||
if (pTrain->bIsEnd)
|
if (pTrain->bIsEnd)
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -109,7 +109,7 @@ APP_ERROR LocalDataMoveEngine::Process()
|
||||||
pFtpData->strFtpFilePath = strImgPath;
|
pFtpData->strFtpFilePath = strImgPath;
|
||||||
pFtpData->strFtpFileName = strImgName;
|
pFtpData->strFtpFileName = strImgName;
|
||||||
pFtpData->bIsEnd = pProcessData->bIsEnd;
|
pFtpData->bIsEnd = pProcessData->bIsEnd;
|
||||||
iRet = outputQueMap_[strPort0_]->push(std::static_pointer_cast<void>(pFtpData), false);
|
iRet = outputQueMap_[strPort0_]->push(std::static_pointer_cast<void>(pFtpData), true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -64,7 +64,7 @@ bool SaveCsvEngine::SaveMergerCsv(std::shared_ptr<Train> pTrain)
|
||||||
<< "time" << ','
|
<< "time" << ','
|
||||||
<< "direction" << ','
|
<< "direction" << ','
|
||||||
<< "speed" << ','
|
<< "speed" << ','
|
||||||
<< "camerano" << ','
|
<< "typeId" << ','
|
||||||
<< "skipInterval" << ','
|
<< "skipInterval" << ','
|
||||||
<< "carxh" << ','
|
<< "carxh" << ','
|
||||||
<< "type" << ','
|
<< "type" << ','
|
||||||
|
|
@ -131,7 +131,7 @@ bool SaveCsvEngine::SaveMergerCsv(std::shared_ptr<Train> pTrain)
|
||||||
<< strTime << ','
|
<< strTime << ','
|
||||||
<< pTrain->iDirection << ','
|
<< pTrain->iDirection << ','
|
||||||
<< 0.0 << ','
|
<< 0.0 << ','
|
||||||
<< szCameraNo << ','
|
<< pTrain->trainNum.iTrainTypeId << ','
|
||||||
<< dataSourceConfig.iSkipInterval << ','
|
<< dataSourceConfig.iSkipInterval << ','
|
||||||
<< pTrain->iCarXH << ','
|
<< pTrain->iCarXH << ','
|
||||||
<< pTrain->trainNum.strTrainType << ','
|
<< pTrain->trainNum.strTrainType << ','
|
||||||
|
|
|
||||||
|
|
@ -154,6 +154,7 @@ APP_ERROR SaveImgEngine::Process()
|
||||||
Json::Value jvFrameInfo;
|
Json::Value jvFrameInfo;
|
||||||
jvFrameInfo["timeStamp"] = pSaveImgData->i64TimeStamp;
|
jvFrameInfo["timeStamp"] = pSaveImgData->i64TimeStamp;
|
||||||
jvFrameInfo["status"] = iStatus;
|
jvFrameInfo["status"] = iStatus;
|
||||||
|
jvFrameInfo["moveType"] = pSaveImgData->nMonitorState;
|
||||||
jvFrameInfo["direction"] = pSaveImgData->iDirection;
|
jvFrameInfo["direction"] = pSaveImgData->iDirection;
|
||||||
jvFrameInfo["width"] = iWidth;
|
jvFrameInfo["width"] = iWidth;
|
||||||
jvFrameInfo["height"] = iHeight;
|
jvFrameInfo["height"] = iHeight;
|
||||||
|
|
|
||||||
|
|
@ -192,7 +192,7 @@ void SaveStepOneResultEngine::DealCenterSpace(std::vector<PartionInfo> &vecParat
|
||||||
pPartionInfo->nStatus = ((pProcessData->iStatus == TRAINSTATUS_STOP) ? TRAIN_PAUSE : iDirection_);
|
pPartionInfo->nStatus = ((pProcessData->iStatus == TRAINSTATUS_STOP) ? TRAIN_PAUSE : iDirection_);
|
||||||
|
|
||||||
LogWarn << "--------- 向Paration 发送数据 --------";
|
LogWarn << "--------- 向Paration 发送数据 --------";
|
||||||
outputQueMap_[strPort0_]->push(std::static_pointer_cast<void>(pPartionInfo));
|
outputQueMap_[strPort0_]->push(std::static_pointer_cast<void>(pPartionInfo), true);
|
||||||
|
|
||||||
iPushSpaceFrameId_ = pPartionInfo->modelSpaceFrame;
|
iPushSpaceFrameId_ = pPartionInfo->modelSpaceFrame;
|
||||||
bPushIsEnd_ = pPartionInfo->bIsEnd;
|
bPushIsEnd_ = pPartionInfo->bIsEnd;
|
||||||
|
|
@ -444,7 +444,7 @@ void SaveStepOneResultEngine::SplitTrainByNumPro(std::shared_ptr<PartionInfo> &p
|
||||||
MyUtils::getins()->WriteJsonInfo(jvFrameInfo, strFilePath);
|
MyUtils::getins()->WriteJsonInfo(jvFrameInfo, strFilePath);
|
||||||
|
|
||||||
LogWarn << "--------- 向Paration 发送数据 --------";
|
LogWarn << "--------- 向Paration 发送数据 --------";
|
||||||
outputQueMap_[strPort0_]->push(std::static_pointer_cast<void>(pPartionInfoNew));
|
outputQueMap_[strPort0_]->push(std::static_pointer_cast<void>(pPartionInfoNew), true);
|
||||||
|
|
||||||
iPushSpaceFrameId_ = pPartionInfoNew->modelSpaceFrame;
|
iPushSpaceFrameId_ = pPartionInfoNew->modelSpaceFrame;
|
||||||
bPushIsEnd_ = pPartionInfoNew->bIsEnd;
|
bPushIsEnd_ = pPartionInfoNew->bIsEnd;
|
||||||
|
|
@ -658,7 +658,7 @@ APP_ERROR SaveStepOneResultEngine::Process()
|
||||||
//第一步处理结束后, push端口1,做复制图片文本数据和图片上传处理。
|
//第一步处理结束后, push端口1,做复制图片文本数据和图片上传处理。
|
||||||
if (jvFrameInfo["step1Finish"].asBool())
|
if (jvFrameInfo["step1Finish"].asBool())
|
||||||
{
|
{
|
||||||
iRet = outputQueMap_[strPort1_]->push(std::static_pointer_cast<void>(pProcessData));
|
iRet = outputQueMap_[strPort1_]->push(std::static_pointer_cast<void>(pProcessData), true);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (pProcessData->iDataSource == 0 && pPostData->iModelType == MODELTYPE_NUM)
|
if (pProcessData->iDataSource == 0 && pPostData->iModelType == MODELTYPE_NUM)
|
||||||
|
|
@ -689,7 +689,7 @@ APP_ERROR SaveStepOneResultEngine::Process()
|
||||||
SplitTrainByNumPro(pPartionInfo, pProcessData);
|
SplitTrainByNumPro(pPartionInfo, pProcessData);
|
||||||
|
|
||||||
LogWarn << "--------- 向Paration 发送数据 --------";
|
LogWarn << "--------- 向Paration 发送数据 --------";
|
||||||
outputQueMap_[strPort0_]->push(std::static_pointer_cast<void>(pPartionInfo));
|
outputQueMap_[strPort0_]->push(std::static_pointer_cast<void>(pPartionInfo), true);
|
||||||
|
|
||||||
iPushSpaceFrameId_ = pPartionInfo->modelSpaceFrame;
|
iPushSpaceFrameId_ = pPartionInfo->modelSpaceFrame;
|
||||||
bPushIsEnd_ = pPartionInfo->bIsEnd;
|
bPushIsEnd_ = pPartionInfo->bIsEnd;
|
||||||
|
|
|
||||||
|
|
@ -246,7 +246,7 @@ APP_ERROR TrainParationMgr::Process()
|
||||||
pTrainRange->i64EndTimeStamp = jvPartionInfo["endTimeStamp"].asInt64();
|
pTrainRange->i64EndTimeStamp = jvPartionInfo["endTimeStamp"].asInt64();
|
||||||
pTrainRange->bIsEnd = jvPartionInfo["isEnd"].asBool();
|
pTrainRange->bIsEnd = jvPartionInfo["isEnd"].asBool();
|
||||||
pTrainRange->bmodelconfirmed = jvPartionInfo["modelconfirmed"].asBool();
|
pTrainRange->bmodelconfirmed = jvPartionInfo["modelconfirmed"].asBool();
|
||||||
iRet = outputQueMap_[strPort0_]->push(std::static_pointer_cast<void>(pTrainRange));
|
iRet = outputQueMap_[strPort0_]->push(std::static_pointer_cast<void>(pTrainRange), true);
|
||||||
|
|
||||||
if (pPartionInfo->bIsEnd) {
|
if (pPartionInfo->bIsEnd) {
|
||||||
lstPartInfo.clear();
|
lstPartInfo.clear();
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,7 @@
|
||||||
#include "HardH264FFmpegDecode.h"
|
#include "HardH264FFmpegDecode.h"
|
||||||
|
#include <iostream>
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
using namespace std;
|
using namespace std;
|
||||||
|
|
||||||
|
|
@ -12,103 +15,188 @@ HardH264FFmpegDecode::~HardH264FFmpegDecode()
|
||||||
;
|
;
|
||||||
}
|
}
|
||||||
|
|
||||||
int HardH264FFmpegDecode::HardH264FFmpegDecoderInit(unsigned int uiWidth, unsigned int uiHeight, unsigned int uiFrameRate)
|
// int HardH264FFmpegDecode::HardH264FFmpegDecoderInit(unsigned int uiWidth, unsigned int uiHeight, unsigned int uiFrameRate)
|
||||||
|
// {
|
||||||
|
// uiWidth_ = uiWidth; uiHeight_ = uiHeight;
|
||||||
|
// uiFrameRate_ = uiFrameRate;
|
||||||
|
// iFrameFinished_ = 0;
|
||||||
|
|
||||||
|
// av_log_set_level(AV_LOG_ERROR);
|
||||||
|
|
||||||
|
// // AVCodecID codec_id = AV_CODEC_ID_H264; //解码H264
|
||||||
|
// // pCodec_ = avcodec_find_decoder(codec_id); //获取解码器
|
||||||
|
|
||||||
|
// pCodec_ = avcodec_find_decoder_by_name(NVIDIA_H264_DECODER);
|
||||||
|
// if (!pCodec_) {
|
||||||
|
// fprintf(stderr, "Codec '%s' not found\n", pCodec_->long_name);
|
||||||
|
// exit(1);
|
||||||
|
// }
|
||||||
|
// printf("Codec found with name %d(%s)\n", pCodec_->id, pCodec_->long_name);
|
||||||
|
|
||||||
|
// //创建上下文
|
||||||
|
// pCodecCtx_ = avcodec_alloc_context3(pCodec_);
|
||||||
|
// if (!pCodecCtx_){
|
||||||
|
// fprintf(stderr, "Could not allocate video codec context\n");
|
||||||
|
// exit(1);
|
||||||
|
// }
|
||||||
|
|
||||||
|
// //创建解析器
|
||||||
|
// pCodecParserCtx_ = av_parser_init(pCodec_->id);
|
||||||
|
// if (!pCodecParserCtx_){
|
||||||
|
// fprintf(stderr, "parser not found\n");
|
||||||
|
// exit(1);
|
||||||
|
// }
|
||||||
|
|
||||||
|
// //if(pCodec_->capabilities&CODEC_CAP_TRUNCATED)
|
||||||
|
// // pCodecCtx_->flags|= CODEC_FLAG_TRUNCATED;
|
||||||
|
|
||||||
|
// //打开解码器
|
||||||
|
// int ret = avcodec_open2(pCodecCtx_, pCodec_, nullptr);
|
||||||
|
// if (ret < 0) {
|
||||||
|
// fprintf(stderr, "Could not open codec\n");
|
||||||
|
// printf("avcodec_open2 ret is: %d\n",ret);
|
||||||
|
// exit(1);
|
||||||
|
// }
|
||||||
|
|
||||||
|
// //分配packet
|
||||||
|
// pPacket_ = av_packet_alloc();
|
||||||
|
// if (!pPacket_){
|
||||||
|
// fprintf(stderr, "Could not allocate video packet\n");
|
||||||
|
// exit(1);
|
||||||
|
// }
|
||||||
|
// // av_init_packet(pPacket_);
|
||||||
|
|
||||||
|
// //分配frame
|
||||||
|
// pSrcFrame_ = av_frame_alloc();
|
||||||
|
// if (!pSrcFrame_) {
|
||||||
|
// fprintf(stderr, "Could not allocate video src pFrame\n");
|
||||||
|
// exit(1);
|
||||||
|
// }
|
||||||
|
|
||||||
|
// pDstFrame_ = av_frame_alloc();
|
||||||
|
// if (!pDstFrame_) {
|
||||||
|
// fprintf(stderr, "Could not allocate video dst pFrame\n");
|
||||||
|
// exit(1);
|
||||||
|
// }
|
||||||
|
|
||||||
|
// printf("after align down video_width: %d, video_height: %d\n", uiWidth_, uiHeight_);
|
||||||
|
|
||||||
|
// //初始化解析器参数
|
||||||
|
// pCodecCtx_->time_base.num = 1;
|
||||||
|
// pCodecCtx_->frame_number = 1; //每包一个视频帧
|
||||||
|
// pCodecCtx_->codec_type = AVMEDIA_TYPE_VIDEO;
|
||||||
|
// pCodecCtx_->bit_rate = 0;
|
||||||
|
// pCodecCtx_->time_base.den = uiFrameRate_;//帧率
|
||||||
|
// pCodecCtx_->width = uiWidth_; //视频宽
|
||||||
|
// pCodecCtx_->height = uiHeight_; //视频高
|
||||||
|
// // pCodecCtx_->pix_fmt = AV_PIX_FMT_YUV420P;
|
||||||
|
|
||||||
|
// int bufferSize = av_image_get_buffer_size(AV_PIX_FMT_YUV420P,
|
||||||
|
// pCodecCtx_->width,
|
||||||
|
// pCodecCtx_->height, 1);
|
||||||
|
// pu8OutBuffer_ = (unsigned char *) av_malloc(bufferSize);
|
||||||
|
// av_image_fill_arrays(pDstFrame_->data,
|
||||||
|
// pDstFrame_->linesize,
|
||||||
|
// pu8OutBuffer_,
|
||||||
|
// AV_PIX_FMT_YUV420P,
|
||||||
|
// pCodecCtx_->width,
|
||||||
|
// pCodecCtx_->height, 1);
|
||||||
|
|
||||||
|
// printf("pDstFrame_->linesize: %d, bufferSize: %d\n", pDstFrame_->linesize, bufferSize);
|
||||||
|
|
||||||
|
// pSwsContext_ = sws_getContext(pCodecCtx_->width, pCodecCtx_->height, pCodecCtx_->pix_fmt,
|
||||||
|
// pCodecCtx_->width, pCodecCtx_->height, AV_PIX_FMT_YUV420P, SWS_BICUBIC, nullptr, nullptr, nullptr);
|
||||||
|
// printf("pCodecCtx_->width: %d, pCodecCtx_->height: %d, pCodecCtx_->pix_fmt: %d\n", pCodecCtx_->width, pCodecCtx_->height, pCodecCtx_->pix_fmt);
|
||||||
|
|
||||||
|
|
||||||
|
// return 0;
|
||||||
|
// }
|
||||||
|
|
||||||
|
int HardH264FFmpegDecode::HardH264FFmpegDecoderInit(unsigned int width, unsigned int height, unsigned int frame_rate)
|
||||||
{
|
{
|
||||||
uiWidth_ = uiWidth; uiHeight_ = uiHeight;
|
width_= width;
|
||||||
uiFrameRate_ = uiFrameRate;
|
height_= height;
|
||||||
iFrameFinished_ = 0;
|
frame_rate_= frame_rate;
|
||||||
|
frameFinished_= 0;
|
||||||
|
|
||||||
av_log_set_level(AV_LOG_ERROR);
|
av_log_set_level(AV_LOG_ERROR);
|
||||||
|
|
||||||
|
avcodec_register_all(); // 注册编解码器
|
||||||
|
avformat_network_init(); // 注册网络格式,如果为本地文件则可以去掉该代码
|
||||||
|
|
||||||
// AVCodecID codec_id = AV_CODEC_ID_H264; //解码H264
|
// AVCodecID codec_id = AV_CODEC_ID_H264; //解码H264
|
||||||
// pCodec_ = avcodec_find_decoder(codec_id); //获取解码器
|
// pCodec_ = avcodec_find_decoder(codec_id); //获取解码器
|
||||||
|
|
||||||
pCodec_ = avcodec_find_decoder_by_name(NVIDIA_H264_DECODER);
|
pCodec_ = avcodec_find_decoder_by_name(NVIDIA_H264_DECODER);
|
||||||
if (!pCodec_) {
|
if (!pCodec_)
|
||||||
fprintf(stderr, "Codec '%s' not found\n", pCodec_->long_name);
|
{
|
||||||
|
// fprintf(stderr, "Codec '%s' not found\n", pCodec_->long_name);
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
printf("Codec found with name %d(%s)\n", pCodec_->id, pCodec_->long_name);
|
// printf("Codec found with name %d(%s)\n", pCodec_->id, pCodec_->long_name);
|
||||||
|
|
||||||
//创建上下文
|
// 创建上下文
|
||||||
pCodecCtx_ = avcodec_alloc_context3(pCodec_);
|
pCodecCtx_ = avcodec_alloc_context3(pCodec_);
|
||||||
if (!pCodecCtx_){
|
if (!pCodecCtx_)
|
||||||
fprintf(stderr, "Could not allocate video codec context\n");
|
{
|
||||||
|
// fprintf(stderr, "Could not allocate video codec context\n");
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
//创建解析器
|
// 创建解析器
|
||||||
pCodecParserCtx_ = av_parser_init(pCodec_->id);
|
pCodecParserCtx_ = av_parser_init(pCodec_->id);
|
||||||
if (!pCodecParserCtx_){
|
if (!pCodecParserCtx_)
|
||||||
fprintf(stderr, "parser not found\n");
|
{
|
||||||
|
// fprintf(stderr, "parser not found\n");
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
//if(pCodec_->capabilities&CODEC_CAP_TRUNCATED)
|
// if(pCodec_->capabilities&CODEC_CAP_TRUNCATED)
|
||||||
// pCodecCtx_->flags|= CODEC_FLAG_TRUNCATED;
|
// pCodecCtx_->flags|= CODEC_FLAG_TRUNCATED;
|
||||||
|
|
||||||
//打开解码器
|
// 打开解码器
|
||||||
int ret = avcodec_open2(pCodecCtx_, pCodec_, nullptr);
|
int ret = avcodec_open2(pCodecCtx_, pCodec_, nullptr);
|
||||||
if (ret < 0) {
|
if (ret < 0)
|
||||||
fprintf(stderr, "Could not open codec\n");
|
{
|
||||||
printf("avcodec_open2 ret is: %d\n",ret);
|
// fprintf(stderr, "Could not open codec\n");
|
||||||
|
// printf("avcodec_open2 ret is: %d\n",ret);
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
//分配packet
|
// 初始化解析器参数
|
||||||
pPacket_ = av_packet_alloc();
|
|
||||||
if (!pPacket_){
|
|
||||||
fprintf(stderr, "Could not allocate video packet\n");
|
|
||||||
exit(1);
|
|
||||||
}
|
|
||||||
// av_init_packet(pPacket_);
|
|
||||||
|
|
||||||
//分配frame
|
|
||||||
pSrcFrame_ = av_frame_alloc();
|
|
||||||
if (!pSrcFrame_) {
|
|
||||||
fprintf(stderr, "Could not allocate video src pFrame\n");
|
|
||||||
exit(1);
|
|
||||||
}
|
|
||||||
|
|
||||||
pDstFrame_ = av_frame_alloc();
|
|
||||||
if (!pDstFrame_) {
|
|
||||||
fprintf(stderr, "Could not allocate video dst pFrame\n");
|
|
||||||
exit(1);
|
|
||||||
}
|
|
||||||
|
|
||||||
printf("after align down video_width: %d, video_height: %d\n", uiWidth_, uiHeight_);
|
|
||||||
|
|
||||||
//初始化解析器参数
|
|
||||||
pCodecCtx_->time_base.num = 1;
|
pCodecCtx_->time_base.num = 1;
|
||||||
pCodecCtx_->frame_number = 1; //每包一个视频帧
|
pCodecCtx_->frame_number = 1; // 每包一个视频帧
|
||||||
pCodecCtx_->codec_type = AVMEDIA_TYPE_VIDEO;
|
pCodecCtx_->codec_type = AVMEDIA_TYPE_VIDEO;
|
||||||
pCodecCtx_->bit_rate = 0;
|
pCodecCtx_->bit_rate = 0;
|
||||||
pCodecCtx_->time_base.den = uiFrameRate_;//帧率
|
pCodecCtx_->time_base.den = frame_rate_; // 帧率
|
||||||
pCodecCtx_->width = uiWidth_; //视频宽
|
pCodecCtx_->width = width_; // 视频宽
|
||||||
pCodecCtx_->height = uiHeight_; //视频高
|
pCodecCtx_->height = height_; // 视频高
|
||||||
// pCodecCtx_->pix_fmt = AV_PIX_FMT_YUV420P;
|
|
||||||
|
|
||||||
int bufferSize = av_image_get_buffer_size(AV_PIX_FMT_YUV420P,
|
|
||||||
pCodecCtx_->width,
|
|
||||||
pCodecCtx_->height, 1);
|
|
||||||
pu8OutBuffer_ = (unsigned char *) av_malloc(bufferSize);
|
|
||||||
av_image_fill_arrays(pDstFrame_->data,
|
|
||||||
pDstFrame_->linesize,
|
|
||||||
pu8OutBuffer_,
|
|
||||||
AV_PIX_FMT_YUV420P,
|
|
||||||
pCodecCtx_->width,
|
|
||||||
pCodecCtx_->height, 1);
|
|
||||||
|
|
||||||
printf("pDstFrame_->linesize: %d, bufferSize: %d\n", pDstFrame_->linesize, bufferSize);
|
// 分配frame
|
||||||
|
pFrame_= av_frame_alloc();
|
||||||
|
if (!pFrame_)
|
||||||
|
{
|
||||||
|
// fprintf(stderr, "Could not allocate video frame\n");
|
||||||
|
exit(1);
|
||||||
|
}
|
||||||
|
|
||||||
pSwsContext_ = sws_getContext(pCodecCtx_->width, pCodecCtx_->height, pCodecCtx_->pix_fmt,
|
|
||||||
pCodecCtx_->width, pCodecCtx_->height, AV_PIX_FMT_YUV420P, SWS_BICUBIC, nullptr, nullptr, nullptr);
|
|
||||||
printf("pCodecCtx_->width: %d, pCodecCtx_->height: %d, pCodecCtx_->pix_fmt: %d\n", pCodecCtx_->width, pCodecCtx_->height, pCodecCtx_->pix_fmt);
|
|
||||||
|
|
||||||
|
// 分配packet
|
||||||
|
pPacket_ = av_packet_alloc();
|
||||||
|
if (!pPacket_)
|
||||||
|
{
|
||||||
|
// fprintf(stderr, "Could not allocate video packet\n");
|
||||||
|
exit(1);
|
||||||
|
}
|
||||||
|
|
||||||
|
// av_init_packet(pPacket_);
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
int HardH264FFmpegDecode::HardH264FFmpegDecoderDeInit()
|
int HardH264FFmpegDecode::HardH264FFmpegDecoderDeInit()
|
||||||
{
|
{
|
||||||
if(pu8OutBuffer_){
|
if(pu8OutBuffer_){
|
||||||
|
|
@ -190,7 +278,7 @@ int HardH264FFmpegDecode::HardH264FFmpegDecoderConfigureVideoFilters(AVFilterGra
|
||||||
pDecoderFilterIn = pFiltSrc;
|
pDecoderFilterIn = pFiltSrc;
|
||||||
pDecoderFilterOut = pFiltDst;
|
pDecoderFilterOut = pFiltDst;
|
||||||
|
|
||||||
fail:
|
fail:
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -245,48 +333,87 @@ int HardH264FFmpegDecode::HardH264FFmpegDecoder(AVCodecContext *pDecCtx, AVFrame
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
int HardH264FFmpegDecode::HardH264FFmpegDecoderV2(AVCodecContext *pDecCtx, SwsContext *pSwsCtx, AVFrame *pSrcFrame, AVFrame *pDstFrame, AVPacket *pPkt, void* pOutputData,unsigned int* puiOutputDataSize)
|
// int HardH264FFmpegDecode::HardH264FFmpegDecoderV2(AVCodecContext *pDecCtx, SwsContext *pSwsCtx, AVFrame *pSrcFrame, AVFrame *pDstFrame, AVPacket *pPkt, void* pOutputData,unsigned int* puiOutputDataSize)
|
||||||
|
// {
|
||||||
|
// std::cout << "HardH264FFmpegDecoderV2--in " << std::endl;
|
||||||
|
// int ret;
|
||||||
|
|
||||||
|
// ret = avcodec_send_packet(pDecCtx, pPkt); //接收packet解码
|
||||||
|
// if (ret < 0) {
|
||||||
|
// fprintf(stderr, "Error sending a packet for decoding\n");
|
||||||
|
// exit(1);
|
||||||
|
// }
|
||||||
|
// std::cout << "HardH264FFmpegDecoderV2--in " << std::endl;
|
||||||
|
|
||||||
|
// while (ret >= 0) {
|
||||||
|
// ret = avcodec_receive_frame(pDecCtx, pSrcFrame); //解码
|
||||||
|
// if (ret == AVERROR(EAGAIN) || ret == AVERROR_EOF){
|
||||||
|
// fprintf(stderr, "During decoding eof\n");
|
||||||
|
// return -1;
|
||||||
|
// }
|
||||||
|
// else if (ret < 0) {
|
||||||
|
// fprintf(stderr, "Error during decoding\n");
|
||||||
|
// exit(1);
|
||||||
|
// }
|
||||||
|
|
||||||
|
// // pDecCtx->width = ALIGN_DOWN(pDecCtx->width, 32);
|
||||||
|
// // pDecCtx->height = ALIGN_DOWN(pDecCtx->height, 32);
|
||||||
|
|
||||||
|
// sws_scale(pSwsCtx,
|
||||||
|
// (const uint8_t *const *)pSrcFrame->data,
|
||||||
|
// pSrcFrame->linesize,
|
||||||
|
// 0,
|
||||||
|
// pDecCtx->height,
|
||||||
|
// pDstFrame->data,
|
||||||
|
// pDstFrame->linesize);
|
||||||
|
|
||||||
|
// //printf("saving frame %3d\n", pDecCtx->frame_number);
|
||||||
|
// fflush(stdout);
|
||||||
|
|
||||||
|
// int iSize = pDecCtx->width * pDecCtx->height;
|
||||||
|
|
||||||
|
// memcpy(pOutputData, pDstFrame->data[0], iSize); //Y
|
||||||
|
// memcpy(pOutputData+iSize, pDstFrame->data[1], iSize/4); //U
|
||||||
|
// memcpy(pOutputData+iSize+iSize/4, pDstFrame->data[2], iSize/4); //V
|
||||||
|
// *puiOutputDataSize = iSize*3/2;
|
||||||
|
// return iSize*3/2;
|
||||||
|
// }
|
||||||
|
// return 0;
|
||||||
|
// }
|
||||||
|
|
||||||
|
int HardH264FFmpegDecode::HardH264FFmpegDecoderV2(AVCodecContext* pDecCtx, AVFrame* pSrcFrame, AVPacket* pPkt, void* pOutputData, unsigned int* puiOutputDataSize)
|
||||||
{
|
{
|
||||||
int ret;
|
int ret;
|
||||||
|
|
||||||
ret = avcodec_send_packet(pDecCtx, pPkt); //接收packet解码
|
ret = avcodec_send_packet(pDecCtx, pPkt); // 接收packet解码
|
||||||
if (ret < 0) {
|
if (ret < 0)
|
||||||
fprintf(stderr, "Error sending a packet for decoding\n");
|
{
|
||||||
|
// fprintf(stderr, "Error sending a packet for decoding\n");
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
while (ret >= 0) {
|
while (ret >= 0)
|
||||||
ret = avcodec_receive_frame(pDecCtx, pSrcFrame); //解码
|
{
|
||||||
if (ret == AVERROR(EAGAIN) || ret == AVERROR_EOF){
|
ret = avcodec_receive_frame(pDecCtx, pSrcFrame); // 解码
|
||||||
fprintf(stderr, "During decoding eof\n");
|
if (ret == AVERROR(EAGAIN) || ret == AVERROR_EOF)
|
||||||
|
{
|
||||||
|
// fprintf(stderr, "During decoding eof\n");
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
else if (ret < 0) {
|
else if (ret < 0)
|
||||||
fprintf(stderr, "Error during decoding\n");
|
{
|
||||||
|
// fprintf(stderr, "Error during decoding\n");
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
// pDecCtx->width = ALIGN_DOWN(pDecCtx->width, 32);
|
////printf("saving frame %3d\n", pDecCtx->frame_number);
|
||||||
// pDecCtx->height = ALIGN_DOWN(pDecCtx->height, 32);
|
// fflush(stdout);
|
||||||
|
|
||||||
sws_scale(pSwsCtx,
|
memcpy(pOutputData, pSrcFrame->data[0], pSrcFrame->width * pSrcFrame->height); // Y
|
||||||
(const uint8_t *const *)pSrcFrame->data,
|
memcpy(pOutputData + pSrcFrame->width * pSrcFrame->height, pSrcFrame->data[1], pSrcFrame->width * pSrcFrame->height / 4); // U
|
||||||
pSrcFrame->linesize,
|
memcpy(pOutputData + pSrcFrame->width * pSrcFrame->height + pSrcFrame->width * pSrcFrame->height / 4, pSrcFrame->data[2], pSrcFrame->width * pSrcFrame->height / 4); // V
|
||||||
0,
|
*puiOutputDataSize = pSrcFrame->width * pSrcFrame->height * 3 / 2;
|
||||||
pDecCtx->height,
|
return pSrcFrame->width * pSrcFrame->height * 3 / 2;
|
||||||
pDstFrame->data,
|
|
||||||
pDstFrame->linesize);
|
|
||||||
|
|
||||||
//printf("saving frame %3d\n", pDecCtx->frame_number);
|
|
||||||
fflush(stdout);
|
|
||||||
|
|
||||||
int iSize = pDecCtx->width * pDecCtx->height;
|
|
||||||
|
|
||||||
memcpy(pOutputData, pDstFrame->data[0], iSize); //Y
|
|
||||||
memcpy(pOutputData+iSize, pDstFrame->data[1], iSize/4); //U
|
|
||||||
memcpy(pOutputData+iSize+iSize/4, pDstFrame->data[2], iSize/4); //V
|
|
||||||
*puiOutputDataSize = iSize*3/2;
|
|
||||||
return iSize*3/2;
|
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
@ -56,7 +56,8 @@ extern "C"
|
||||||
frame->linesize[2] \
|
frame->linesize[2] \
|
||||||
);}
|
);}
|
||||||
|
|
||||||
#define NVIDIA_H264_DECODER "h264_cuvid"
|
#define NVIDIA_H264_DECODER "h264_nvmpi"
|
||||||
|
// #define NVIDIA_H264_DECODER "h264_cuvid"
|
||||||
// #define NVIDIA_H264_DECODER "h264_v4l2m2m"
|
// #define NVIDIA_H264_DECODER "h264_v4l2m2m"
|
||||||
|
|
||||||
class HardH264FFmpegDecode
|
class HardH264FFmpegDecode
|
||||||
|
|
@ -65,14 +66,16 @@ public:
|
||||||
HardH264FFmpegDecode();
|
HardH264FFmpegDecode();
|
||||||
~HardH264FFmpegDecode();
|
~HardH264FFmpegDecode();
|
||||||
|
|
||||||
int HardH264FFmpegDecoderInit(unsigned int uiWidth, unsigned int uiHeight, unsigned int uiFrameRate = 30);
|
int HardH264FFmpegDecoderInit(unsigned int width, unsigned int height, unsigned int frame_rate = 30);
|
||||||
int HardH264FFmpegDecoderDeInit();
|
int HardH264FFmpegDecoderDeInit();
|
||||||
int HardH264FFmpegDecoder(AVCodecContext *pDecCtx, AVFrame *pFrame, AVPacket *pPkt, void* pOutputData, unsigned int* puiOutputDataSize);
|
int HardH264FFmpegDecoder(AVCodecContext *pDecCtx, AVFrame *pFrame, AVPacket *pPkt, void* pOutputData, unsigned int* puiOutputDataSize);
|
||||||
int HardH264FFmpegDecoderV2(AVCodecContext *pDecCtx, SwsContext *pSwsCtx, AVFrame *pSrcFrame, AVFrame *pDstFrame, AVPacket *pPkt, void* pOutputData, unsigned int* puiOutputDataSize);
|
// int HardH264FFmpegDecoderV2(AVCodecContext *pDecCtx, SwsContext *pSwsCtx, AVFrame *pSrcFrame, AVFrame *pDstFrame, AVPacket *pPkt, void* pOutputData, unsigned int* puiOutputDataSize);
|
||||||
|
int HardH264FFmpegDecoderV2(AVCodecContext* pDecCtx, AVFrame* pSrcFrame, AVPacket* pPkt, void* pOutputData, unsigned int* puiOutputDataSize);
|
||||||
|
|
||||||
const AVCodec *pCodec_ = nullptr; //解码器
|
const AVCodec *pCodec_ = nullptr; //解码器
|
||||||
AVCodecContext *pCodecCtx_ = nullptr; //上下文
|
AVCodecContext *pCodecCtx_ = nullptr; //上下文
|
||||||
AVCodecParserContext *pCodecParserCtx_ = nullptr; //解析器上下文
|
AVCodecParserContext *pCodecParserCtx_ = nullptr; //解析器上下文
|
||||||
|
AVFrame *pFrame_ = nullptr;
|
||||||
AVFrame *pSrcFrame_ = nullptr;
|
AVFrame *pSrcFrame_ = nullptr;
|
||||||
AVFrame *pDstFrame_ = nullptr;
|
AVFrame *pDstFrame_ = nullptr;
|
||||||
AVPacket *pPacket_ = nullptr;
|
AVPacket *pPacket_ = nullptr;
|
||||||
|
|
@ -85,6 +88,9 @@ private:
|
||||||
int HardH264FFmpegDecoderConfigureVideoFilters(AVFilterGraph *pGraph, AVFilterContext* &pDecoderFilterIn, AVFilterContext* &pDecoderFilterOut, const int iWidth, const int iHeight, const int iFormat);
|
int HardH264FFmpegDecoderConfigureVideoFilters(AVFilterGraph *pGraph, AVFilterContext* &pDecoderFilterIn, AVFilterContext* &pDecoderFilterOut, const int iWidth, const int iHeight, const int iFormat);
|
||||||
|
|
||||||
unsigned int uiWidth_, uiHeight_;
|
unsigned int uiWidth_, uiHeight_;
|
||||||
|
unsigned int width_, height_;
|
||||||
|
unsigned int frame_rate_;
|
||||||
|
int frameFinished_;
|
||||||
|
|
||||||
int iFrameFinished_;
|
int iFrameFinished_;
|
||||||
unsigned int uiFrameRate_;
|
unsigned int uiFrameRate_;
|
||||||
|
|
|
||||||
|
|
@ -59,6 +59,8 @@ APP_ERROR VideoDecodeEngine::Process()
|
||||||
int iSkipCount = 1;
|
int iSkipCount = 1;
|
||||||
int iNoCameraDataCnt = 0;
|
int iNoCameraDataCnt = 0;
|
||||||
while (!isStop_)
|
while (!isStop_)
|
||||||
|
{
|
||||||
|
try
|
||||||
{
|
{
|
||||||
//从上一引擎接收图像数据
|
//从上一引擎接收图像数据
|
||||||
std::shared_ptr<void> pVoidData0 = nullptr;
|
std::shared_ptr<void> pVoidData0 = nullptr;
|
||||||
|
|
@ -67,19 +69,19 @@ APP_ERROR VideoDecodeEngine::Process()
|
||||||
{
|
{
|
||||||
usleep(10*1000); //10ms
|
usleep(10*1000); //10ms
|
||||||
|
|
||||||
// iNoCameraDataCnt++;
|
iNoCameraDataCnt++;
|
||||||
// if (iNoCameraDataCnt >= 1000) //10秒内收不到,认为相机断开
|
if (iNoCameraDataCnt >= 1000) //10秒内收不到,认为相机断开
|
||||||
// {
|
{
|
||||||
// LogError << "engineId:" << engineId_ << " 超过10秒获取到摄像头数据,疑似摄像头断开。计数:" << iNoCameraDataCnt;
|
LogError << "engineId:" << engineId_ << " 超过10秒获取到摄像头数据,疑似摄像头断开。计数:" << iNoCameraDataCnt;
|
||||||
// iNoCameraDataCnt = 0;
|
iNoCameraDataCnt = 0;
|
||||||
// //camera异常时,构造空的解码数据push,确保一直有数据流转到后面Engine
|
//camera异常时,构造空的解码数据push,确保一直有数据流转到后面Engine
|
||||||
// std::shared_ptr<ProcessData> pProcessData = std::make_shared<ProcessData>();
|
std::shared_ptr<ProcessData> pProcessData = std::make_shared<ProcessData>();
|
||||||
// pProcessData->iDataSource = engineId_;
|
pProcessData->iDataSource = engineId_;
|
||||||
// pProcessData->i64TimeStamp = MyUtils::getins()->GetCurrentTimeMillis();
|
pProcessData->i64TimeStamp = MyUtils::getins()->GetCurrentTimeMillis();
|
||||||
// pProcessData->iSize = 0;
|
pProcessData->iSize = 0;
|
||||||
// pProcessData->pData = nullptr;
|
pProcessData->pData = nullptr;
|
||||||
// iRet = outputQueMap_[strPort0_]->push(std::static_pointer_cast<void>(pProcessData));
|
iRet = outputQueMap_[strPort0_]->push(std::static_pointer_cast<void>(pProcessData));
|
||||||
// }
|
}
|
||||||
|
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
@ -115,16 +117,20 @@ APP_ERROR VideoDecodeEngine::Process()
|
||||||
hard_h264_ffmpeg_decoder_->pPacket_->size = pProcessData->iSize; //这个填入H264数据帧的大小
|
hard_h264_ffmpeg_decoder_->pPacket_->size = pProcessData->iSize; //这个填入H264数据帧的大小
|
||||||
|
|
||||||
// H264硬件解码
|
// H264硬件解码
|
||||||
// int iDecodeRet= hard_h264_ffmpeg_decoder_->HardH264FFmpegDecoderV2(hard_h264_ffmpeg_decoder_->pCodecCtx_, hard_h264_ffmpeg_decoder_->pFrame_,
|
int iDecodeRet= hard_h264_ffmpeg_decoder_->HardH264FFmpegDecoderV2(hard_h264_ffmpeg_decoder_->pCodecCtx_,
|
||||||
// hard_h264_ffmpeg_decoder_->pPacket_, pYUV420MBuffer, &pYUV420MBuffer_Size);
|
hard_h264_ffmpeg_decoder_->pFrame_,
|
||||||
|
|
||||||
int iDecodeRet = hard_h264_ffmpeg_decoder_->HardH264FFmpegDecoderV2(hard_h264_ffmpeg_decoder_->pCodecCtx_,
|
|
||||||
hard_h264_ffmpeg_decoder_->pSwsContext_,
|
|
||||||
hard_h264_ffmpeg_decoder_->pSrcFrame_,
|
|
||||||
hard_h264_ffmpeg_decoder_->pDstFrame_,
|
|
||||||
hard_h264_ffmpeg_decoder_->pPacket_,
|
hard_h264_ffmpeg_decoder_->pPacket_,
|
||||||
pYUV420MBuffer,
|
pYUV420MBuffer,
|
||||||
&pYUV420MBuffer_Size);
|
&pYUV420MBuffer_Size);
|
||||||
|
|
||||||
|
// int iDecodeRet = hard_h264_ffmpeg_decoder_->HardH264FFmpegDecoderV2(hard_h264_ffmpeg_decoder_->pCodecCtx_,
|
||||||
|
// hard_h264_ffmpeg_decoder_->pSwsContext_,
|
||||||
|
// hard_h264_ffmpeg_decoder_->pSrcFrame_,
|
||||||
|
// hard_h264_ffmpeg_decoder_->pDstFrame_,
|
||||||
|
// hard_h264_ffmpeg_decoder_->pPacket_,
|
||||||
|
// pYUV420MBuffer,
|
||||||
|
// &pYUV420MBuffer_Size);
|
||||||
|
|
||||||
if (iDecodeRet > 0)
|
if (iDecodeRet > 0)
|
||||||
{
|
{
|
||||||
if (iSkipCount++ % dataSourceConfig_.iSkipInterval != 0)
|
if (iSkipCount++ % dataSourceConfig_.iSkipInterval != 0)
|
||||||
|
|
@ -139,7 +145,6 @@ APP_ERROR VideoDecodeEngine::Process()
|
||||||
|
|
||||||
cv::Mat matBGR(pProcessData->iHeight, pProcessData->iWidth, CV_8UC3);
|
cv::Mat matBGR(pProcessData->iHeight, pProcessData->iWidth, CV_8UC3);
|
||||||
cv::cvtColor(matYUV, matBGR, cv::COLOR_YUV2BGR_I420);
|
cv::cvtColor(matYUV, matBGR, cv::COLOR_YUV2BGR_I420);
|
||||||
|
|
||||||
cv::resize(matBGR, matBGR, cv::Size(IMAGE_WIDTH, IMAGE_HEIGHT));
|
cv::resize(matBGR, matBGR, cv::Size(IMAGE_WIDTH, IMAGE_HEIGHT));
|
||||||
unsigned int iResizeSize = IMAGE_WIDTH * IMAGE_HEIGHT * 3;
|
unsigned int iResizeSize = IMAGE_WIDTH * IMAGE_HEIGHT * 3;
|
||||||
void *pResizeBGRBuffer = nullptr;
|
void *pResizeBGRBuffer = nullptr;
|
||||||
|
|
@ -161,5 +166,10 @@ APP_ERROR VideoDecodeEngine::Process()
|
||||||
LogError << "engineId:" << engineId_ << " HardH264FFmpegDecoderV2 failed...iDecodeRet:" << iDecodeRet;
|
LogError << "engineId:" << engineId_ << " HardH264FFmpegDecoderV2 failed...iDecodeRet:" << iDecodeRet;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
catch(...)
|
||||||
|
{
|
||||||
|
LogError << "解码异常!!";
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -211,6 +211,7 @@ void MoveEngine::SingleDeviceProcess(std::shared_ptr<ProcessData> pProcessData,
|
||||||
pSaveImgData->bIsEnd = pProcessData->bIsEnd;
|
pSaveImgData->bIsEnd = pProcessData->bIsEnd;
|
||||||
pSaveImgData->bSaveToFtp = true;
|
pSaveImgData->bSaveToFtp = true;
|
||||||
pSaveImgData->i64TimeStamp = pProcessData->i64TimeStamp;
|
pSaveImgData->i64TimeStamp = pProcessData->i64TimeStamp;
|
||||||
|
pSaveImgData->nMonitorState = nType;
|
||||||
outputQueMap_[strPort0_]->push(std::static_pointer_cast<void>(pSaveImgData));
|
outputQueMap_[strPort0_]->push(std::static_pointer_cast<void>(pSaveImgData));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -234,7 +235,7 @@ APP_ERROR MoveEngine::Process()
|
||||||
int nType = MONITOR_MODEL_INIT_STATE;
|
int nType = MONITOR_MODEL_INIT_STATE;
|
||||||
if (iQueueSize > 5)
|
if (iQueueSize > 5)
|
||||||
{
|
{
|
||||||
LogDebug << "iQueueSize: " << iQueueSize;
|
// LogDebug << "iQueueSize: " << iQueueSize;
|
||||||
g_bNoDealStepTwoFlag = true;
|
g_bNoDealStepTwoFlag = true;
|
||||||
}
|
}
|
||||||
else if (g_bNoDealStepTwoFlag)
|
else if (g_bNoDealStepTwoFlag)
|
||||||
|
|
|
||||||
|
|
@ -14,7 +14,7 @@ APP_ERROR TrainStepOneEngine::Init()
|
||||||
bUseEngine_ = MyUtils::getins()->ChkIsHaveTarget("NUM");
|
bUseEngine_ = MyUtils::getins()->ChkIsHaveTarget("NUM");
|
||||||
if (!bUseEngine_)
|
if (!bUseEngine_)
|
||||||
{
|
{
|
||||||
LogInfo << "engineId_:" << engineId_ << " not use engine";
|
LogWarn << "engineId_:" << engineId_ << " not use engine";
|
||||||
return APP_ERR_OK;
|
return APP_ERR_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -98,7 +98,7 @@ APP_ERROR TrainStepOneEngine::InitModel()
|
||||||
int nRet = yolov5model.YoloV5ClearityInferenceInit(&modelinfo, strModelName, modelConfig_.strOmPath);
|
int nRet = yolov5model.YoloV5ClearityInferenceInit(&modelinfo, strModelName, modelConfig_.strOmPath);
|
||||||
if (nRet != 0)
|
if (nRet != 0)
|
||||||
{
|
{
|
||||||
LogError << "YoloV5ClassifyInferenceInit nRet:" << nRet;
|
LogInfo << "YoloV5ClassifyInferenceInit nRet:" << nRet;
|
||||||
return APP_ERR_COMM_READ_FAIL;
|
return APP_ERR_COMM_READ_FAIL;
|
||||||
}
|
}
|
||||||
return APP_ERR_OK;
|
return APP_ERR_OK;
|
||||||
|
|
@ -147,7 +147,7 @@ APP_ERROR TrainStepOneEngine::DeInit()
|
||||||
{
|
{
|
||||||
if (!bUseEngine_)
|
if (!bUseEngine_)
|
||||||
{
|
{
|
||||||
LogInfo << "engineId_:" << engineId_ << " not use engine";
|
LogWarn << "engineId_:" << engineId_ << " not use engine";
|
||||||
return APP_ERR_OK;
|
return APP_ERR_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -170,7 +170,7 @@ void TrainStepOneEngine::PushData(const std::string &strPort, const std::shared_
|
||||||
int iRet = outputQueMap_[strPort]->push(std::static_pointer_cast<void>(pProcessData));
|
int iRet = outputQueMap_[strPort]->push(std::static_pointer_cast<void>(pProcessData));
|
||||||
if (iRet != 0)
|
if (iRet != 0)
|
||||||
{
|
{
|
||||||
LogError << " frameid:" << pProcessData->iFrameId << " push fail iRet:" << iRet;
|
LogDebug << "sourceid:" << pProcessData->iDataSource << " frameid:" << pProcessData->iFrameId << " push fail iRet:" << iRet;
|
||||||
if (iRet == 2)
|
if (iRet == 2)
|
||||||
{
|
{
|
||||||
usleep(10000); // 10ms
|
usleep(10000); // 10ms
|
||||||
|
|
@ -211,7 +211,7 @@ void TrainStepOneEngine::FilterInvalidInfo(std::vector<stDetection> &vecRet, std
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
// 如果设置了不识别车头,则去掉车头标记的大框
|
// 如果设置了不识别车头,则去掉车头所有大框
|
||||||
if (!MyYaml::GetIns()->GetBoolValue("gc_train_heard_detect") && it->class_id == TRAIN_HEAD)
|
if (!MyYaml::GetIns()->GetBoolValue("gc_train_heard_detect") && it->class_id == TRAIN_HEAD)
|
||||||
{
|
{
|
||||||
LogDebug << "frameId:" << pProcessData->iFrameId << " 过滤掉车头编号";
|
LogDebug << "frameId:" << pProcessData->iFrameId << " 过滤掉车头编号";
|
||||||
|
|
@ -219,7 +219,7 @@ void TrainStepOneEngine::FilterInvalidInfo(std::vector<stDetection> &vecRet, std
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
// 去除车头时的非车头编号信息
|
// 过滤车头部分的非车头编号大框
|
||||||
if(pProcessData->nMonitorState == MONITOR_MODEL_TRAIN_HEAD )
|
if(pProcessData->nMonitorState == MONITOR_MODEL_TRAIN_HEAD )
|
||||||
{
|
{
|
||||||
if(it->class_id != TRAIN_HEAD)
|
if(it->class_id != TRAIN_HEAD)
|
||||||
|
|
@ -231,18 +231,6 @@ void TrainStepOneEngine::FilterInvalidInfo(std::vector<stDetection> &vecRet, std
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// 去除车尾的车头编号信息
|
|
||||||
if (pProcessData->nMonitorState != MONITOR_MODEL_TRAIN_HEAD)
|
|
||||||
{
|
|
||||||
if (it->class_id == TRAIN_HEAD)
|
|
||||||
{
|
|
||||||
LogDebug << " 帧号:" << pProcessData->iFrameId
|
|
||||||
<< " 大类:" << it->class_id << " 识别于非车头位置,无效!";
|
|
||||||
it = vecRet.erase(it);
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// 去除车尾的间隔信息
|
// 去除车尾的间隔信息
|
||||||
if (pProcessData->nMonitorState == MONITOR_MODEL_TRAIN_TAIL
|
if (pProcessData->nMonitorState == MONITOR_MODEL_TRAIN_TAIL
|
||||||
&& ((it->class_id >= 9 && it->class_id <= 17 && it->class_id != 15) || it->class_id == 18))
|
&& ((it->class_id >= 9 && it->class_id <= 17 && it->class_id != 15) || it->class_id == 18))
|
||||||
|
|
@ -254,12 +242,12 @@ void TrainStepOneEngine::FilterInvalidInfo(std::vector<stDetection> &vecRet, std
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
// 过滤掉识别于模型反馈无车状态下的所有大框信息
|
// 去除无车状态下的大框信息
|
||||||
if (pProcessData->nMonitorState == MONITOR_MODEL_NO_TRAIN)
|
if (pProcessData->nMonitorState == MONITOR_MODEL_NO_TRAIN)
|
||||||
{
|
{
|
||||||
LogDebug << " frameId:" << pProcessData->iFrameId
|
LogDebug << " frameId:" << pProcessData->iFrameId
|
||||||
<< " bigclassid:" << it->class_id
|
<< " bigclassid:" << it->class_id
|
||||||
<<" 识别于模型反馈的无车状态下,无效!";
|
<<" 识别于无车状态,无效!";
|
||||||
it = vecRet.erase(it);
|
it = vecRet.erase(it);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
@ -413,7 +401,7 @@ APP_ERROR TrainStepOneEngine::Process()
|
||||||
{
|
{
|
||||||
if (!bUseEngine_)
|
if (!bUseEngine_)
|
||||||
{
|
{
|
||||||
LogInfo << "engineId_:" << engineId_ << " not use engine";
|
LogWarn << "engineId_:" << engineId_ << " not use engine";
|
||||||
return APP_ERR_OK;
|
return APP_ERR_OK;
|
||||||
}
|
}
|
||||||
int iRet = APP_ERR_OK;
|
int iRet = APP_ERR_OK;
|
||||||
|
|
@ -443,7 +431,10 @@ APP_ERROR TrainStepOneEngine::Process()
|
||||||
|
|
||||||
//进行推理
|
//进行推理
|
||||||
std::vector<stDetection> res;
|
std::vector<stDetection> res;
|
||||||
|
//auto start = std::chrono::system_clock::now(); //计时开始
|
||||||
yolov5model.YoloV5ClearityInferenceModel(img, res);
|
yolov5model.YoloV5ClearityInferenceModel(img, res);
|
||||||
|
//auto end = std::chrono::system_clock::now();
|
||||||
|
//LogInfo << "nopr1 inference time: " << std::chrono::duration_cast<std::chrono::milliseconds>(end - start).count() << "ms";
|
||||||
|
|
||||||
//过滤无效信息
|
//过滤无效信息
|
||||||
FilterInvalidInfo(res, pProcessData);
|
FilterInvalidInfo(res, pProcessData);
|
||||||
|
|
@ -501,7 +492,8 @@ APP_ERROR TrainStepOneEngine::Process()
|
||||||
|
|
||||||
//push端口0,第1步推理
|
//push端口0,第1步推理
|
||||||
pProcessData->pVoidData = std::static_pointer_cast<void>(pPostData);
|
pProcessData->pVoidData = std::static_pointer_cast<void>(pPostData);
|
||||||
PushData(strPort0_, pProcessData);
|
iRet = outputQueMap_[strPort0_]->push(std::static_pointer_cast<void>(pProcessData), true);
|
||||||
|
// PushData(strPort0_, pProcessData);
|
||||||
}
|
}
|
||||||
return APP_ERR_OK;
|
return APP_ERR_OK;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -239,7 +239,8 @@ APP_ERROR TrainStepTwoEngine::Process()
|
||||||
|
|
||||||
// push端口0,第1步推理
|
// push端口0,第1步推理
|
||||||
pProcessData->pVoidData = std::static_pointer_cast<void>(pPostData);
|
pProcessData->pVoidData = std::static_pointer_cast<void>(pPostData);
|
||||||
PushData(strPort0_, pProcessData);
|
iRet = outputQueMap_[strPort0_]->push(std::static_pointer_cast<void>(pProcessData));
|
||||||
|
// PushData(strPort0_, pProcessData);
|
||||||
}
|
}
|
||||||
return APP_ERR_OK;
|
return APP_ERR_OK;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -432,12 +432,12 @@ void preprocess_kernel_img(
|
||||||
|
|
||||||
s2d.value[0] = scale;
|
s2d.value[0] = scale;
|
||||||
s2d.value[1] = 0;
|
s2d.value[1] = 0;
|
||||||
// s2d.value[2] = 0; //左上顶点贴图
|
s2d.value[2] = 0; //左上顶点贴图
|
||||||
s2d.value[2] = -scale * src_width * 0.5 + dst_width * 0.5; //中心贴图
|
// s2d.value[2] = -scale * src_width * 0.5 + dst_width * 0.5; //中心贴图
|
||||||
s2d.value[3] = 0;
|
s2d.value[3] = 0;
|
||||||
s2d.value[4] = scale;
|
s2d.value[4] = scale;
|
||||||
// s2d.value[5] = 0; //左上顶点贴图
|
s2d.value[5] = 0; //左上顶点贴图
|
||||||
s2d.value[5] = -scale * src_height * 0.5 + dst_height * 0.5; //中心贴图
|
// s2d.value[5] = -scale * src_height * 0.5 + dst_height * 0.5; //中心贴图
|
||||||
|
|
||||||
cv::Mat m2x3_s2d(2, 3, CV_32F, s2d.value);
|
cv::Mat m2x3_s2d(2, 3, CV_32F, s2d.value);
|
||||||
cv::Mat m2x3_d2s(2, 3, CV_32F, d2s.value);
|
cv::Mat m2x3_d2s(2, 3, CV_32F, d2s.value);
|
||||||
|
|
|
||||||
|
|
@ -186,6 +186,7 @@ int YoloV8Inference::YoloV8InferenceModelCommon(cv::Mat& frame, float& fResizeRa
|
||||||
size_t size_image_dst = pYoloV5ModelInfo_->modelCommonInfo.uiModelWidth * pYoloV5ModelInfo_->modelCommonInfo.uiModelHeight * pYoloV5ModelInfo_->modelCommonInfo.uiChannel;
|
size_t size_image_dst = pYoloV5ModelInfo_->modelCommonInfo.uiModelWidth * pYoloV5ModelInfo_->modelCommonInfo.uiModelHeight * pYoloV5ModelInfo_->modelCommonInfo.uiChannel;
|
||||||
auto preprocess_start = std::chrono::system_clock::now(); //计时开始
|
auto preprocess_start = std::chrono::system_clock::now(); //计时开始
|
||||||
|
|
||||||
|
|
||||||
#ifdef ENABLE_CUDA_PREPROCESS
|
#ifdef ENABLE_CUDA_PREPROCESS
|
||||||
memcpy(pu8ImgHost_, frame.data, size_image_src); //拷贝预处理数据到HOST侧
|
memcpy(pu8ImgHost_, frame.data, size_image_src); //拷贝预处理数据到HOST侧
|
||||||
CUDA_CHECK(cudaMemcpyAsync(pu8ImgDevice_, pu8ImgHost_, size_image_src, cudaMemcpyHostToDevice, *pImagePreprocessStream_)); //拷贝预处理数据到Device侧
|
CUDA_CHECK(cudaMemcpyAsync(pu8ImgDevice_, pu8ImgHost_, size_image_src, cudaMemcpyHostToDevice, *pImagePreprocessStream_)); //拷贝预处理数据到Device侧
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue