diff --git a/build/src/Makefile b/build/src/Makefile index a53a705..216042e 100644 --- a/build/src/Makefile +++ b/build/src/Makefile @@ -70,6 +70,7 @@ SRCS := $(wildcard $(CUR_PROJ_PATH)/*.cpp) \ $(wildcard $(CUR_PROJ_PATH)/common/cnn/*.cpp) \ $(wildcard $(CUR_PROJ_PATH)/common/dvppx/*.cpp) \ $(wildcard $(CUR_PROJ_PATH)/common/model_process/*.cpp) \ + $(wildcard $(CUR_PROJ_PATH)/utils/*.cpp) \ DIRS := $(notdir $(SRCS)) OBJS := $(patsubst %cpp, %o, $(DIRS)) @@ -106,6 +107,9 @@ $(TARGET):$(OBJS) %.o:$(CUR_PROJ_PATH)/common/model_process/%.cpp $(XX) $(CXXFLAGS) -c $< +%.o:$(CUR_PROJ_PATH)/utils/%.cpp + $(XX) $(CXXFLAGS) -c $< + clean: @rm -f $(TARGET) @rm -f $(OBJS) diff --git a/src/PicAnalysis.cpp b/src/PicAnalysis.cpp index eedd84f..b93c45a 100644 --- a/src/PicAnalysis.cpp +++ b/src/PicAnalysis.cpp @@ -60,6 +60,11 @@ int PicAnalysis::init(int dev_id) { return -1; } + ret = m_crop_util.init(dev_id); + if(0 != ret){ + return -1; + } + ACL_CALL(aclrtCreateContext(&m_ctx, 0), ACL_SUCCESS, SY_FAILED); ACL_CALL(aclrtSetCurrentContext(m_ctx), ACL_SUCCESS, SY_FAILED); ACL_CALL(aclrtCreateStream(&stream), ACL_SUCCESS, SY_FAILED); @@ -105,7 +110,98 @@ int PicAnalysis::analysis_sync(vector vec_file_path){ vec_img.push_back(img); } - m_vehicle_analysis.detect(vec_img); + va_result* result = m_vehicle_analysis.detect(vec_img); + + m_road_seg_algorithm.detect(vec_img); + + for (int b = 0; b < batch_size; b++) + { + ImageData src = dvpp_data[b]; + for(int c=0;calignWidth; + img.h_ = human_data->alignHeight; + img.data_ = human_data->data_naked; + + vector vec_human_img; + vec_human_img.push_back(img); + + human_analysis(vec_human_img); + + delete human_data; + human_data = nullptr; + } + + // 司乘 + int vpd_num = result_info.vehicle_pendant_det_res.count; + vector vec_human_img; + for(int p=0; palignWidth; + img.h_ = human_data->alignHeight; + img.data_ = human_data->data_naked; + + vec_human_img.push_back(img); + } + } + + m_clothes_algorithm.detect(vec_human_img); + + for(int p=0; palignWidth; + img.h_ = motor_data->alignHeight; + img.data_ = motor_data->data_naked; + + vector vec_motor_img; + vec_motor_img.push_back(img); + + m_motor_rainshed_algorithm.detect(vec_motor_img); + + m_motor_phone_algorithm.detect(vec_motor_img); + + // + + + delete motor_data; + motor_data = nullptr; + } + + } + } vector head_tail_result; ret = m_head_tail_algorithm.detect(vec_img, head_tail_result); @@ -114,17 +210,7 @@ int PicAnalysis::analysis_sync(vector vec_file_path){ head_tail_result.clear(); } - m_clothes_algorithm.detect(vec_img); - - m_human_algorithm.detect(vec_img); - - m_human_car_algorithm.detect(vec_img); - - m_motor_rainshed_algorithm.detect(vec_img); - - m_motor_phone_algorithm.detect(vec_img); - - m_road_seg_algorithm.detect(vec_img); + LOG_INFO("analysis_sync finished!"); @@ -149,4 +235,12 @@ int PicAnalysis::release() { aclrtDestroyContext(m_ctx); return 0; +} + +int PicAnalysis::human_analysis(vector vec_img) { + vector vec_body_color = m_human_algorithm.detect(vec_img); +} + +int PicAnalysis::check_motor_retrograde_motion(vector vec_motor_img) { + m_human_car_algorithm.detect(vec_motor_img); } \ No newline at end of file diff --git a/src/PicAnalysis.h b/src/PicAnalysis.h index 07353d3..1ba204e 100644 --- a/src/PicAnalysis.h +++ b/src/PicAnalysis.h @@ -8,6 +8,8 @@ #include "./ai_engine_module/MotorPhoneAnalysis.h" #include "./ai_engine_module/RoadSegAnalysis.h" +#include "./utils/CropUtil.h" + using namespace std; @@ -25,6 +27,11 @@ public: int release(); private: + int human_analysis(vector vec_img); + + int check_motor_retrograde_motion(vector vec_img); + +private: aclrtContext m_ctx{nullptr}; aclrtStream stream{nullptr}; DvppProcess* m_dvpp{nullptr}; @@ -37,6 +44,8 @@ private: MotorRainshedAnalysis m_motor_rainshed_algorithm; MotorPhoneAnalysis m_motor_phone_algorithm; RoadSegAnalysis m_road_seg_algorithm; + + CropUtil m_crop_util; }; diff --git a/src/ai_engine_module/HumanAnalysis.cpp b/src/ai_engine_module/HumanAnalysis.cpp index 18d9e05..75ea6c2 100644 --- a/src/ai_engine_module/HumanAnalysis.cpp +++ b/src/ai_engine_module/HumanAnalysis.cpp @@ -1,5 +1,7 @@ #include "HumanAnalysis.h" +static std::string body_colors[] = { "黑", "白", "灰", "红", "蓝", "黄", "绿", "多色", "其他" }; + HumanAnalysis::HumanAnalysis(/* args */) { } @@ -28,27 +30,35 @@ int HumanAnalysis::init(int devId){ return SY_SUCCESS; } -int HumanAnalysis::detect(vector vec_img){ - - ACL_CALL(aclrtSetCurrentContext(ctx), SY_SUCCESS, SY_FAILED); +vector HumanAnalysis::detect(vector vec_img){ const int batchsize = vec_img.size(); hp_analysis_res * results = new hp_analysis_res[batchsize]; int ret = SY_FAILED; + vector vec_body_color; do { + ret = aclrtSetCurrentContext(ctx); + if (SY_SUCCESS != ret) { + printf("aclrtSetCurrentContext failed!"); + break; + } + ret = hp_batch(m_handle, vec_img.data(), batchsize, results); if (SY_SUCCESS != ret) { printf("hp_batch failed!"); break; } - for(int batchIdx = 0;batchIdx vec_img){ delete [] results; } - return ret; + return vec_body_color; } int HumanAnalysis::release() { diff --git a/src/ai_engine_module/HumanAnalysis.h b/src/ai_engine_module/HumanAnalysis.h index 32da3b8..ca52a1f 100644 --- a/src/ai_engine_module/HumanAnalysis.h +++ b/src/ai_engine_module/HumanAnalysis.h @@ -1,6 +1,11 @@ #include "include.h" #include "human_parsing.h" +struct BodyColorInfo{ + int upper_body_color; + int lower_body_color; +}; + class HumanAnalysis { public: @@ -9,7 +14,7 @@ public: int init(int devId); - int detect(vector vec_img); + vector detect(vector vec_img); private: int release(); diff --git a/src/ai_engine_module/RoadSegAnalysis.cpp b/src/ai_engine_module/RoadSegAnalysis.cpp index a199f10..c2d9d08 100644 --- a/src/ai_engine_module/RoadSegAnalysis.cpp +++ b/src/ai_engine_module/RoadSegAnalysis.cpp @@ -55,8 +55,10 @@ int RoadSegAnalysis::detect(vector vec_img){ } while (0); for (int b = 0; b < batchsize; b++) { - delete[] results[b].seg_array; results[b].seg_array = NULL; - delete[] results[b].direct_seg; results[b].direct_seg = NULL; + delete[] results[b].seg_array; + results[b].seg_array = NULL; + delete[] results[b].direct_seg; + results[b].direct_seg = NULL; } return ret; diff --git a/src/ai_engine_module/VehicleAnalysis.cpp b/src/ai_engine_module/VehicleAnalysis.cpp index 249ef69..2f67e73 100644 --- a/src/ai_engine_module/VehicleAnalysis.cpp +++ b/src/ai_engine_module/VehicleAnalysis.cpp @@ -67,7 +67,7 @@ int VehicleAnalysis::init(int devId, int max_batch_size) { return 0; } -int VehicleAnalysis::detect(vector vec_img) { +va_result * VehicleAnalysis::detect(vector vec_img) { int batch_size = vec_img.size(); @@ -83,514 +83,207 @@ int VehicleAnalysis::detect(vector vec_img) { } int ret = va_batch(m_handle, vec_img.data(), batch_size, result); + + vector vec_result; for (int b = 0; b < batch_size; b++) - { - if(param.vehicle_detect_config==SY_CONFIG_CLOSE)//不做车头检测时,应设result[b].count=1,即输入是车头图像,只含1辆车。 - result[b].count=1; - - //oFile << file << ","<< result[b].count<< "," <0) + if(result_info.vehicle_body_detect_res.rect.width_>0) { - float vehicle_body_detect_res_score = result[b].info[c].vehicle_body_detect_res.score; - int x1=result[b].info[c].vehicle_body_detect_res.rect.left_; - int y1=result[b].info[c].vehicle_body_detect_res.rect.top_; - int x2=result[b].info[c].vehicle_body_detect_res.rect.left_+result[b].info[c].vehicle_body_detect_res.rect.width_; - int y2=result[b].info[c].vehicle_body_detect_res.rect.top_+result[b].info[c].vehicle_body_detect_res.rect.height_; + float vehicle_body_detect_res_score = result_info.vehicle_body_detect_res.score; + int x1=result_info.vehicle_body_detect_res.rect.left_; + int y1=result_info.vehicle_body_detect_res.rect.top_; + int x2=result_info.vehicle_body_detect_res.rect.left_+result_info.vehicle_body_detect_res.rect.width_; + int y2=result_info.vehicle_body_detect_res.rect.top_+result_info.vehicle_body_detect_res.rect.height_; std::cout << " vehicle_body_detect_res_score:" <0) - { - float vehicle_detect_res_score = result[b].info[c].vehicle_detect_res.score; - int x1=result[b].info[c].vehicle_detect_res.rect.left_; - int y1=result[b].info[c].vehicle_detect_res.rect.top_; - int x2=result[b].info[c].vehicle_detect_res.rect.left_+result[b].info[c].vehicle_detect_res.rect.width_; - int y2=result[b].info[c].vehicle_detect_res.rect.top_+result[b].info[c].vehicle_detect_res.rect.height_; - std::cout << " vehicle_detect_res_score:" <0) - { - float vehicle_win_detect_res_score = result[b].info[c].vehicle_win_detect_res.score; - int x1=result[b].info[c].vehicle_win_detect_res.rect.left_; - int y1=result[b].info[c].vehicle_win_detect_res.rect.top_; - int x2=result[b].info[c].vehicle_win_detect_res.rect.left_+result[b].info[c].vehicle_win_detect_res.rect.width_; - int y2=result[b].info[c].vehicle_win_detect_res.rect.top_+result[b].info[c].vehicle_win_detect_res.rect.height_; - std::cout << " vehicle_win_detect_res_score:" <0) + // { + // float vehicle_detect_res_score = result_info.vehicle_detect_res.score; + // int x1=result_info.vehicle_detect_res.rect.left_; + // int y1=result_info.vehicle_detect_res.rect.top_; + // int x2=result_info.vehicle_detect_res.rect.left_+result_info.vehicle_detect_res.rect.width_; + // int y2=result_info.vehicle_detect_res.rect.top_+result_info.vehicle_detect_res.rect.height_; + // std::cout << " vehicle_detect_res_score:" <0.5) - { - std::cout << " car color info:"<< endl; - std::cout << " index:"<< index<<" score:"<< score<< std::endl; - - // std::string str_i = CARCOLOR1[index]; - // cv::putText(cvImg, str_i, - // cv::Point(result[b].info[c].vehicle_body_detect_res.rect.left_+5, result[b].info[c].vehicle_body_detect_res.rect.top_+50), - // cv::FONT_HERSHEY_COMPLEX_SMALL, - // 1.3, - // cv::Scalar(0, 0, 255), - // 2); - } + // //车窗 + // if(result_info.vehicle_win_detect_res.rect.width_>0) + // { + // float vehicle_win_detect_res_score = result_info.vehicle_win_detect_res.score; + // int x1=result_info.vehicle_win_detect_res.rect.left_; + // int y1=result_info.vehicle_win_detect_res.rect.top_; + // int x2=result_info.vehicle_win_detect_res.rect.left_+result_info.vehicle_win_detect_res.rect.width_; + // int y2=result_info.vehicle_win_detect_res.rect.top_+result_info.vehicle_win_detect_res.rect.height_; + // std::cout << " vehicle_win_detect_res_score:" < name_score_thre) { - cout << " vehicle_recg info: " << endl; - std::cout << " name_score: " << name_score << std::endl; - std::cout << " vehicle_brand: " << vehicle_brand << std::endl; - std::cout << " vehicle_subbrand: " << vehicle_subbrand << std::endl; - std::cout << " vehicle_issue_year: " << vehicle_issue_year << std::endl; - std::cout << " vehicle_type_: " << vehicle_type_ << std::endl; - std::cout << " freight_ton: " << freight_ton << std::endl; - - //printf("name_score:%f\n", name_score); - //printf("vehicle_brand:%s\n", vehicle_brand); - //printf("vehicle_subbrand:%s\n", vehicle_subbrand); - //printf("vehicle_issue_year:%s\n", vehicle_issue_year); - //printf("vehicle_type_:%s\n", vehicle_type_); - //printf("freight_ton:%s\n", freight_ton); + analysis_result.vehicle_type = vehicle_type_; } - + } else { + analysis_result.vehicle_type = str_vehicle_type; } - - + std::cout << "vehicle_type_: " << analysis_result.vehicle_type << std::endl; + //5.VP车牌检测识别 - if(param.vehicle_plate_det_recg_config==SY_CONFIG_OPEN && (vehicle_type==0 || vehicle_type==1)) + if(param.vehicle_plate_det_recg_config==SY_CONFIG_OPEN && (shot_type==0 || shot_type==1)) { + vplate_results plate_result = result_info.vehicle_plate_det_recg_res; std::cout << " car plate info:"<< endl; - int special_type=result[b].info[c].vehicle_plate_det_recg_res.special_type;//常规车牌、临时车牌、低速车牌。0-common,1-temporary_license_plate,2-low_speed_license_plate. + int special_type=plate_result.special_type;//常规车牌、临时车牌、低速车牌。0-common,1-temporary_license_plate,2-low_speed_license_plate. std::cout << " special_type:" << special_type<< std::endl; - float detect_score=result[b].info[c].vehicle_plate_det_recg_res.detect_score; - //std::cout << "detect_score:" << detect_score<< std::endl; + float detect_score=plate_result.detect_score; if(detect_score>0.3) - { - int type=result[b].info[c].vehicle_plate_det_recg_res.type; - sy_rect rect=result[b].info[c].vehicle_plate_det_recg_res.rect; - - int x1=rect.left_; - int y1=rect.top_; - int x2=rect.left_+rect.width_; - int y2=rect.top_+rect.height_; - std::cout << " vp_type:"<0.99)//车牌识别建议置信度阈值0.99 { - //printf("plate: "); for (int m = 0; m < PLATENUM; m++) { - //printf("%s", result[b].info[c].vehicle_plate_det_recg_res.recg[m].character); - plate_recg=plate_recg + result[b].info[c].vehicle_plate_det_recg_res.recg[m].character; + plate_recg=plate_recg + plate_result.recg[m].character; + character_prob += std::string(plate_result.recg[m].character) + "-" + std::to_string(plate_result.recg[m].maxprob) + ","; } - //printf("\n"); - - //printf("maxprob: "); - //for (int m = 0; m < PLATENUM; m++) - //{ - // printf("%f ", result[b].info[c].vehicle_plate_det_recg_res.vehicle_plate_infos[0].recg[m].maxprob); - //} - //printf("\n"); - - - //std::cout << "type:" << type<<" num_score:" <= 3){ + analysis_result.motor_manned = 1; + } } - } - - //测试相似度比对函数,batch_size设为2 - //double similarity=va_compute_similarity(result[0].info[0].vehicle_fea_res.feature, result[1].info[0].vehicle_fea_res.feature, FEATURESIZE); - //std::cout << "similarity: "< vec_img) { if(result!=NULL){ delete[] result; } - - return 0; -} - -void VehicleAnalysis::release(){ - if (m_handle) { - va_release(&m_handle); - } } diff --git a/src/ai_engine_module/VehicleAnalysis.h b/src/ai_engine_module/VehicleAnalysis.h index f6237bc..b48adbb 100644 --- a/src/ai_engine_module/VehicleAnalysis.h +++ b/src/ai_engine_module/VehicleAnalysis.h @@ -6,6 +6,31 @@ #include "vehicle_analysis.h" #include "vehicle_result.h" +struct DriverInfo { + sy_rect driver_rect; + float driver_prob; + int driver_color; +}; + +struct VehicleAnalysisResult{ + int shot_type; + sy_rect vehicle_rect; + string vehicle_type; + + sy_rect plate_rect;//车牌检测坐标 + float plate_det_score;//车牌检测置信度 + string plate_num; + string character_prob; + float plate_num_score;//识别置信度 + int plate_type; //车牌类型:0-单排蓝色 1-单排黄色 2-单排白色 3-单排黑色 4-双排黄色 5-双排白色 6-新能源黄绿色 7-新能源白绿色 + int special_type; //常规车牌、临时车牌、低速车牌。0-common,1-temporary_license_plate,2-low_speed_license_plate. + + vector vec_drivers; // 副驾也被认为是司机 + + int motor_helmeted; + int motor_manned{0}; +}; + class VehicleAnalysis { private: @@ -16,7 +41,9 @@ public: int init(int devId, int max_batch_size); - int detect(vector vec_img); + va_result* detect(vector vec_img); + + void release_result(va_result*, int); private: void release(); diff --git a/src/ai_engine_module/include.h b/src/ai_engine_module/include.h index 5e9eaed..3ed0b74 100644 --- a/src/ai_engine_module/include.h +++ b/src/ai_engine_module/include.h @@ -25,4 +25,5 @@ using namespace std; using namespace cv; + #endif \ No newline at end of file diff --git a/src/common/dvppx/dvpp_cropandpastex.cpp b/src/common/dvppx/dvpp_cropandpastex.cpp index f52a901..8ee2b24 100755 --- a/src/common/dvppx/dvpp_cropandpastex.cpp +++ b/src/common/dvppx/dvpp_cropandpastex.cpp @@ -57,7 +57,12 @@ int DvppCropAndPastex::InitCropAndPasteInputDesc(ImageData& inputImage) return SY_FAILED; } - acldvppSetPicDescData(vpcInputDesc_, inputImage.data.get()); // JpegD . vpcResize + if (inputImage.data_naked == nullptr) { + acldvppSetPicDescData(vpcInputDesc_, inputImage.data.get()); // JpegD . vpcResize + } else { + acldvppSetPicDescData(vpcInputDesc_, inputImage.data_naked); // JpegD . vpcResize + } + acldvppSetPicDescFormat(vpcInputDesc_, format_); acldvppSetPicDescWidth(vpcInputDesc_, inputImage.width); acldvppSetPicDescHeight(vpcInputDesc_, inputImage.height); @@ -266,8 +271,6 @@ int DvppCropAndPastex::ResizeWithPadding(ImageData& resizedImage, ImageData& src return SY_SUCCESS; } - - int DvppCropAndPastex::PatchProcess(ImageData& resizedImage, ImageData& srcImage, uint32_t xmin, uint32_t ymin, uint32_t xmax, uint32_t ymax) { @@ -329,6 +332,73 @@ int DvppCropAndPastex::PatchProcess(ImageData& resizedImage, ImageData& srcImage return SY_SUCCESS; } +ImageData* DvppCropAndPastex::Crop_naked(ImageData& srcImage, uint32_t xmin, uint32_t ymin, uint32_t xmax, uint32_t ymax) +{ + ImageData* resizedImage = nullptr; + + do + { + if (SY_SUCCESS != InitCropAndPasteResource(srcImage)) { + ERROR_LOG("Dvpp cropandpaste failed for init error"); + break; + } + + uint32_t cropLeftOffset = ((xmin >> 1) << 1); // must even + uint32_t cropTopOffset = ((ymin >> 1) << 1); // must even + uint32_t cropRightOffset = ((xmax >> 1) << 1) -1; // must odd + uint32_t cropBottomOffset = ((ymax >> 1) << 1) -1; // must odd + + cropArea_ = acldvppCreateRoiConfig(cropLeftOffset, cropRightOffset, + cropTopOffset, cropBottomOffset); + if (cropArea_ == nullptr) { + ERROR_LOG("acldvppCreateRoiConfig cropArea_ failed"); + break; + } + //printf("debug crop area: %d %d %d %d\n", cropLeftOffset, cropTopOffset, cropRightOffset, cropBottomOffset); + + uint32_t pasteLeftOffset = 0; // must even + uint32_t pasteTopOffset = 0; // must even + uint32_t pasteRightOffset = (((pasteLeftOffset + size_.width) >> 1) << 1) -1; // must odd + uint32_t pasteBottomOffset = (((pasteTopOffset + size_.height) >> 1) << 1) -1; // must odd + + pasteArea_ = acldvppCreateRoiConfig(pasteLeftOffset, pasteRightOffset, + pasteTopOffset, pasteBottomOffset); + if (pasteArea_ == nullptr) { + ERROR_LOG("acldvppCreateRoiConfig pasteArea_ failed"); + break; + } + //printf("debug paste area: %d %d %d %d\n", pasteLeftOffset, pasteTopOffset, pasteRightOffset, pasteBottomOffset); + + // crop and patse pic + aclError aclRet = acldvppVpcCropAndPasteAsync(dvppChannelDesc_, vpcInputDesc_, + vpcOutputDesc_, cropArea_, pasteArea_, stream_); + //printf("debug crop line:%d\n",__LINE__); + if (aclRet != ACL_SUCCESS) { + ERROR_LOG("acldvppVpcCropAndPasteAsync failed, aclRet = %d", aclRet); + break; + } + + aclRet = aclrtSynchronizeStream(stream_); + if (aclRet != ACL_SUCCESS) { + ERROR_LOG("crop and paste aclrtSynchronizeStream failed, aclRet = %d", aclRet); + break; + } + + resizedImage = new ImageData(); + resizedImage->width = size_.width; + resizedImage->height = size_.height; + resizedImage->alignWidth = ALIGN_UP16(size_.width); + resizedImage->alignHeight = ALIGN_UP2(size_.height); + resizedImage->size = vpcOutBufferSize_; + resizedImage->data_naked = (uint8_t*)vpcOutBufferDev_; + + } while (0); + + DestroyCropAndPasteResource(); + + return resizedImage; +} + int DvppCropAndPastex::Crop2Process(ImageData& resizedImage, ImageData& leftImage, ImageData& rightImage, ImageData& srcImage) { //left @@ -500,7 +570,6 @@ int DvppCropAndPastex::Process(ImageData& resizedImage, ImageData& srcImage) return SY_SUCCESS; } - void DvppCropAndPastex::DestroyCropAndPasteResource() { if (cropArea_ != nullptr) { diff --git a/src/common/dvppx/dvpp_cropandpastex.h b/src/common/dvppx/dvpp_cropandpastex.h index b5106cb..4a17fc1 100755 --- a/src/common/dvppx/dvpp_cropandpastex.h +++ b/src/common/dvppx/dvpp_cropandpastex.h @@ -56,12 +56,15 @@ public: * @return result */ int Process(ImageData& resizedImage, ImageData& srcImage); + int Crop2Process(ImageData& resizedImage, ImageData& leftImage, ImageData& rightImage, ImageData& srcImage); int PatchProcess(ImageData& resizedImage, ImageData& srcImage, uint32_t xmin, uint32_t ymin, uint32_t xmax, uint32_t ymax); int ResizeWithPadding(ImageData& resizedImage, ImageData& srcImage); + ImageData* Crop_naked(ImageData& srcImage, uint32_t xmin, uint32_t ymin, uint32_t xmax, uint32_t ymax); + private: int InitCropAndPasteResource(ImageData& inputImage); int InitCropAndPasteInputDesc(ImageData& inputImage); diff --git a/src/common/dvppx/dvpp_processx.cpp b/src/common/dvppx/dvpp_processx.cpp index e3cd0c7..d51bab6 100755 --- a/src/common/dvppx/dvpp_processx.cpp +++ b/src/common/dvppx/dvpp_processx.cpp @@ -93,13 +93,18 @@ int DvppProcessx::CropAndPadding(ImageData& dest, ImageData& src, return cropandpaddingOp.ResizeWithPadding(dest, src); } - int DvppProcessx::PatchCropAndPaste(ImageData& dest, ImageData& src, uint32_t xmin, uint32_t ymin, uint32_t xmax, uint32_t ymax, uint32_t width, uint32_t height) { DvppCropAndPastex patchcropandpasteOp(stream_, dvppChannelDesc_, width, height); return patchcropandpasteOp.PatchProcess(dest, src, xmin, ymin, xmax, ymax); } +ImageData* DvppProcessx::Crop_naked(ImageData& src, uint32_t xmin, uint32_t ymin, + uint32_t xmax, uint32_t ymax, uint32_t width, uint32_t height) { + DvppCropAndPastex cropandpasteOp(stream_, dvppChannelDesc_, width, height); + return cropandpasteOp.Crop_naked(src, xmin, ymin, xmax, ymax); +} + int DvppProcessx::CvtJpegToYuv420sp(ImageData& dest, ImageData& src) { DvppJpegDx jpegD(stream_, dvppChannelDesc_); return jpegD.Process(dest, src); diff --git a/src/common/dvppx/dvpp_processx.h b/src/common/dvppx/dvpp_processx.h index 05d58d5..2c9d49c 100755 --- a/src/common/dvppx/dvpp_processx.h +++ b/src/common/dvppx/dvpp_processx.h @@ -62,6 +62,7 @@ public: uint32_t width, uint32_t height); int CropAndPaste(ImageData& src, ImageData& dest, uint32_t width, uint32_t height); + ImageData* Crop_naked(ImageData& src, uint32_t xmin, uint32_t ymin, uint32_t xmax, uint32_t ymax, uint32_t width, uint32_t height); int PatchCropAndPaste(ImageData& dest, ImageData& src, uint32_t xmin, uint32_t ymin, uint32_t xmax, uint32_t ymax, uint32_t width, uint32_t height); int Crop2Paste(ImageData& dest, ImageData& leftImage, ImageData& rightImage, diff --git a/src/common/stream_data.h b/src/common/stream_data.h index 5b3131b..f31320f 100644 --- a/src/common/stream_data.h +++ b/src/common/stream_data.h @@ -2,6 +2,8 @@ #define _STREAM_DATA_H_ #include +#include "acl/acl.h" +#include "acl/ops/acl_dvpp.h" struct ImageData { uint32_t width = 0; @@ -10,6 +12,17 @@ struct ImageData { uint32_t alignHeight = 0; uint32_t size = 0; std::shared_ptr data; + uint8_t* data_naked; + + ImageData(){ + data_naked = nullptr; + } + + ~ImageData(){ + if (data_naked) { + acldvppFree(data_naked); + } + } }; #endif \ No newline at end of file diff --git a/src/main.cpp b/src/main.cpp index 8d77bea..d6cf06d 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -7,9 +7,9 @@ int main() { pic_analysis.init(0); vector vec_path; - for (size_t i = 0; i < 10; i++) + for (size_t i = 0; i < 1; i++) { - vec_path.push_back("./test_hv.jpg"); + vec_path.push_back("./test_all.jpg"); } pic_analysis.analysis_sync(vec_path); diff --git a/src/utils/CropUtil.cpp b/src/utils/CropUtil.cpp new file mode 100644 index 0000000..b3a6d53 --- /dev/null +++ b/src/utils/CropUtil.cpp @@ -0,0 +1,61 @@ +#include "CropUtil.h" +#include "logger.hpp" +#include "sy_errorinfo.h" + +CropUtil::CropUtil(/* args */) +{ +} + +CropUtil::~CropUtil() +{ + release(); +} + +int CropUtil::init(int devId){ + ACL_CALL(aclrtCreateContext(&m_ctx, devId), ACL_SUCCESS, SY_FAILED); + + ACL_CALL(aclrtCreateStream(&stream), ACL_SUCCESS, SY_FAILED); + m_dvpp = new DvppProcessx(); + int ret = m_dvpp->InitResource(stream); + if (ret != SY_SUCCESS) { + delete m_dvpp; + m_dvpp = nullptr; + LOG_ERROR("dvpp init failed!"); + return SY_FAILED; + } + + return SY_SUCCESS; +} + +int CropUtil::release(){ + ACL_CALL(aclrtSetCurrentContext(m_ctx), ACL_SUCCESS, SY_FAILED); + + if (m_dvpp) { + delete m_dvpp; + m_dvpp = nullptr; + } + + if (stream != nullptr) { + int ret = aclrtDestroyStream(stream); + if (ret != ACL_SUCCESS) { + LOG_ERROR("destroy stream failed"); + } + stream = nullptr; + } + + aclrtDestroyContext(m_ctx); +} + +ImageData* CropUtil::crop(ImageData& src, uint32_t xmin, uint32_t ymin, uint32_t xmax, uint32_t ymax) { + int ret = aclrtSetCurrentContext(m_ctx); + if (ACL_SUCCESS != ret) + { + return nullptr; + } + + int width = xmax - xmin; + int height = ymax - ymin; + uint32_t alignWidth = (width + 127) / 128 * 128; + uint32_t alignHeight = (height + 15) / 16 * 16; + return m_dvpp->Crop_naked(src, xmin, ymin, xmax, ymax, alignWidth, alignHeight); +} \ No newline at end of file diff --git a/src/utils/CropUtil.h b/src/utils/CropUtil.h new file mode 100644 index 0000000..78ec279 --- /dev/null +++ b/src/utils/CropUtil.h @@ -0,0 +1,20 @@ +#include "../dvppx/dvpp_processx.h" + +class CropUtil +{ +public: + CropUtil(/* args */); + ~CropUtil(); + + int init(int devId); + + ImageData* crop(ImageData& src, uint32_t xmin, uint32_t ymin, uint32_t xmax, uint32_t ymax); + +private: + int release(); + +private: + aclrtContext m_ctx; + aclrtStream stream; + DvppProcessx* m_dvpp; +};