VideoPipe視覺化影片結構化框架更新總結(2023-3-30)

周見智發表於2023-03-30

專案地址:https://github.com/sherlockchou86/video_pipe_c

往期文章:https://www.cnblogs.com/xiaozhi_5638/p/16969546.html

最近有多個更新,有興趣的掃碼加群交流。

新增例項分割相關支援

增加了基於mask-rcnn的例項分割外掛和相關sample。

 1 #include "VP.h"
 2 
 3 #include "../nodes/vp_file_src_node.h"
 4 #include "../nodes/infers/vp_mask_rcnn_detector_node.h"
 5 #include "../nodes/track/vp_sort_track_node.h"
 6 #include "../nodes/osd/vp_osd_node_v3.h"
 7 #include "../nodes/vp_screen_des_node.h"
 8 
 9 #include "../utils/analysis_board/vp_analysis_board.h"
10 
11 /*
12 * ## mask rcnn sample ##
13 * image segmentation using mask rcnn.
14 */
15 
16 #if mask_rcnn_sample
17 
18 int main() {
19     VP_SET_LOG_LEVEL(vp_utils::vp_log_level::INFO);
20     VP_LOGGER_INIT();
21 
22     // create nodes
23     auto file_src_0 = std::make_shared<vp_nodes::vp_file_src_node>("file_src_0", 0, "./test_video/19.mp4", 0.6);
24     auto mask_rcnn_detector = std::make_shared<vp_nodes::vp_mask_rcnn_detector_node>("mask_rcnn_detector", "./models/mask_rcnn/frozen_inference_graph.pb", "./models/mask_rcnn/mask_rcnn_inception_v2_coco_2018_01_28.pbtxt", "./models/coco_80classes.txt");
25     auto track_0 = std::make_shared<vp_nodes::vp_sort_track_node>("sort_track_0");
26     auto osd_v3_0 = std::make_shared<vp_nodes::vp_osd_node_v3>("osd_v3_0", "../third_party/paddle_ocr/font/NotoSansCJKsc-Medium.otf");
27     auto screen_des_0 = std::make_shared<vp_nodes::vp_screen_des_node>("screen_des_0", 0);
28 
29     // construct pipeline
30     mask_rcnn_detector->attach_to({file_src_0});
31     track_0->attach_to({mask_rcnn_detector});
32     osd_v3_0->attach_to({track_0});
33     screen_des_0->attach_to({osd_v3_0});
34 
35     file_src_0->start();
36 
37     // for debug purpose
38     vp_utils::vp_analysis_board board({file_src_0});
39     board.display();
40 }
41 
42 
43 #endif

上面程式碼效果圖如下:

 

 

新增語義分割相關支援

新增了基於ENet網路的語義分割外掛和sample。

 1 #include "VP.h"
 2 
 3 #include "../nodes/vp_file_src_node.h"
 4 #include "../nodes/infers/vp_enet_seg_node.h"
 5 #include "../nodes/osd/vp_seg_osd_node.h"
 6 #include "../nodes/vp_screen_des_node.h"
 7 
 8 #include "../utils/analysis_board/vp_analysis_board.h"
 9 
10 /*
11 * ## enet seg sample ##
12 * semantic segmentation based on ENet.
13 * 1 input, 2 outputs including orignal frame and mask frame.
14 */
15 
16 #if enet_seg_sample
17 
18 int main() {
19     VP_SET_LOG_LEVEL(vp_utils::vp_log_level::INFO);
20     VP_LOGGER_INIT();
21 
22     // create nodes
23     auto file_src_0 = std::make_shared<vp_nodes::vp_file_src_node>("file_src_0", 0, "./test_video/21.mp4");
24     auto enet_seg = std::make_shared<vp_nodes::vp_enet_seg_node>("enet_seg", "models/enet-cityscapes/enet-model.net");
25     auto seg_osd_0 = std::make_shared<vp_nodes::vp_seg_osd_node>("seg_osd_0", "models/enet-cityscapes/enet-classes.txt", "models/enet-cityscapes/enet-colors.txt");
26     auto screen_des_mask = std::make_shared<vp_nodes::vp_screen_des_node>("screen_des_mask", 0, true, vp_objects::vp_size(400, 225));
27     auto screen_des_original = std::make_shared<vp_nodes::vp_screen_des_node>("screen_des_original", 0, false, vp_objects::vp_size(400, 225));
28 
29     // construct pipeline
30     enet_seg->attach_to({file_src_0});
31     seg_osd_0->attach_to({enet_seg});
32     screen_des_mask->attach_to({seg_osd_0});
33     screen_des_original->attach_to({seg_osd_0});
34 
35     file_src_0->start();
36 
37     // for debug purpose
38     vp_utils::vp_analysis_board board({file_src_0});
39     board.display();
40 }
41 
42 #endif

上面程式碼效果圖如下:

 

新增多級推理外掛sample

多個檢測、分類外掛串聯,不同分類器作用於不同的主目標:

 1 #include "VP.h"
 2 
 3 #include "../nodes/vp_file_src_node.h"
 4 #include "../nodes/infers/vp_yolo_detector_node.h"
 5 #include "../nodes/infers/vp_classifier_node.h"
 6 #include "../nodes/osd/vp_osd_node.h"
 7 #include "../nodes/vp_screen_des_node.h"
 8 #include "../utils/analysis_board/vp_analysis_board.h"
 9 
10 /*
11 * ## multi detectors and classifiers sample ##
12 * show multi infer nodes work together.
13 * 1 detector and 2 classifiers applied on primary class ids(1/2/3).
14 */
15 
16 #if multi_detectors_and_classifiers_sample
17 
18 int main() {
19     VP_SET_LOG_LEVEL(vp_utils::vp_log_level::INFO);
20     VP_LOGGER_INIT();
21 
22     // create nodes
23     auto file_src_0 = std::make_shared<vp_nodes::vp_file_src_node>("file_src_0", 0, "test_video/20.mp4", 0.6);
24     /* primary detector */
25     // labels for detector model
26     // 0 - person
27     // 1 - car
28     // 2 - bus
29     // 3 - truck
30     // 4 - 2wheel
31     auto primary_detector = std::make_shared<vp_nodes::vp_yolo_detector_node>("primary_detector", "models/det_cls/yolov3-tiny-2022-0721_best.weights", "models/det_cls/yolov3-tiny-2022-0721.cfg", "models/det_cls/yolov3_tiny_5classes.txt", 416, 416, 1);
32     /* secondary classifier 1, applied to car(1)/bus(2)/truck(3) only */
33     auto _1st_classifier = std::make_shared<vp_nodes::vp_classifier_node>("1st_classifier", "models/det_cls/vehicle/resnet18-batch=N-type_view_0322_nhwc.onnx", "", "models/det_cls/vehicle/vehicle_types.txt", 224, 224, 1, std::vector<int>{1, 2, 3}, 10, false, 1, cv::Scalar(), cv::Scalar(), true, true);
34     /* secondary classifier 2, applied to car(1)/bus(2)/truck(3) only */
35     auto _2nd_classifier = std::make_shared<vp_nodes::vp_classifier_node>("2nd_classifier", "models/det_cls/vehicle/resnet18-batch=N-color_view_0322_nhwc.onnx", "", "models/det_cls/vehicle/vehicle_colors.txt", 224, 224, 1, std::vector<int>{1, 2, 3}, 10, false, 1, cv::Scalar(), cv::Scalar(), true, true);
36     auto osd_0 = std::make_shared<vp_nodes::vp_osd_node>("osd_0");
37     auto screen_des_0 = std::make_shared<vp_nodes::vp_screen_des_node>("screen_des_o", 0);
38 
39     // construct pipeline
40     primary_detector->attach_to({file_src_0});
41     _1st_classifier->attach_to({primary_detector});
42     _2nd_classifier->attach_to({_1st_classifier});
43     osd_0->attach_to({_2nd_classifier});
44     screen_des_0->attach_to({osd_0});
45 
46     // start
47     file_src_0->start();
48 
49     // for debug purpose
50     vp_utils::vp_analysis_board board({file_src_0});
51     board.display();
52 }
53 
54 #endif

上面程式碼執行效果如下:

 

新增圖片源輸入外掛

支援以圖片方式輸入(檔案或UDP),頻率可調、各個通道互相獨立。

 1 #include "VP.h"
 2 
 3 #include "../nodes/vp_image_src_node.h"
 4 #include "../nodes/infers/vp_yolo_detector_node.h"
 5 #include "../nodes/osd/vp_osd_node.h"
 6 #include "../nodes/vp_split_node.h"
 7 #include "../nodes/vp_screen_des_node.h"
 8 
 9 #include "../utils/analysis_board/vp_analysis_board.h"
10 
11 /*
12 * ## image_src_sample ##
13 * show how vp_image_src_node works, read image from local file or receive image from remote via udp.
14 */
15 
16 #if image_src_sample
17 
18 int main() {
19     VP_SET_LOG_LEVEL(vp_utils::vp_log_level::INFO);
20     VP_LOGGER_INIT();
21 
22     // create nodes
23     auto image_src_0 = std::make_shared<vp_nodes::vp_image_src_node>("image_file_src_0", 0, "./images/test_%d.jpg", 1, 0.4); // read 1 image EVERY 1 second from local files, such as test_0.jpg,test_1.jpg
24     /* sending command for test: `gst-launch-1.0 filesrc location=16.mp4 ! qtdemux ! avdec_h264 ! videoconvert ! videoscale ! video/x-raw,width=416,height=416 ! videorate ! video/x-raw,framerate=1/1 ! jpegenc ! rtpjpegpay ! udpsink host=ip port=6000` */
25     auto image_src_1 = std::make_shared<vp_nodes::vp_image_src_node>("image_udp_src_1", 1, "6000", 3);                       // receive 1 image EVERY 3 seconds from remote via udp , such as 127.0.0.1:6000
26     auto yolo_detector = std::make_shared<vp_nodes::vp_yolo_detector_node>("yolo_detector", "models/det_cls/yolov3-tiny-2022-0721_best.weights", "models/det_cls/yolov3-tiny-2022-0721.cfg", "models/det_cls/yolov3_tiny_5classes.txt");
27     auto osd = std::make_shared<vp_nodes::vp_osd_node>("osd");
28     auto split = std::make_shared<vp_nodes::vp_split_node>("split_by_channel", true);    // split by channel index (important!)
29     auto screen_des_0 = std::make_shared<vp_nodes::vp_screen_des_node>("screen_des_0", 0);
30     auto screen_des_1 = std::make_shared<vp_nodes::vp_screen_des_node>("screen_des_1", 1);
31     
32     // construct pipeline
33     yolo_detector->attach_to({image_src_0, image_src_1});
34     osd->attach_to({yolo_detector});
35     split->attach_to({osd});
36     screen_des_0->attach_to({split});
37     screen_des_1->attach_to({split});
38 
39     image_src_0->start();  // start read from local file
40     image_src_1->start();  // start receive from remote via udp
41 
42     // for debug purpose
43     vp_utils::vp_analysis_board board({image_src_0, image_src_1});
44     board.display();
45 }
46 
47 #endif

上面程式碼執行效果如下:

 

新增圖片結果輸出外掛

支援以圖片格式輸出結果(檔案或UDP),頻率可調、各通道互相獨立。

 1 #include "VP.h"
 2 
 3 #include "../nodes/vp_file_src_node.h"
 4 #include "../nodes/infers/vp_yunet_face_detector_node.h"
 5 #include "../nodes/infers/vp_sface_feature_encoder_node.h"
 6 #include "../nodes/osd/vp_face_osd_node_v2.h"
 7 #include "../nodes/vp_screen_des_node.h"
 8 #include "../nodes/vp_image_des_node.h"
 9 
10 #include "../utils/analysis_board/vp_analysis_board.h"
11 
12 /*
13 * ## image_des_sample ##
14 * show how vp_image_des_node works, save image to local file or push image to remote via udp.
15 */
16 
17 #if image_des_sample
18 
19 int main() {
20     VP_SET_LOG_LEVEL(vp_utils::vp_log_level::INFO);
21     VP_LOGGER_INIT();
22 
23     // create nodes
24     auto file_src_0 = std::make_shared<vp_nodes::vp_file_src_node>("file_src_0", 0, "./test_video/10.mp4", 0.6);
25     auto yunet_face_detector_0 = std::make_shared<vp_nodes::vp_yunet_face_detector_node>("yunet_face_detector_0", "./models/face/face_detection_yunet_2022mar.onnx");
26     auto sface_face_encoder_0 = std::make_shared<vp_nodes::vp_sface_feature_encoder_node>("sface_face_encoder_0", "./models/face/face_recognition_sface_2021dec.onnx");
27     auto osd_0 = std::make_shared<vp_nodes::vp_face_osd_node_v2>("osd_0");
28     auto screen_des_0 = std::make_shared<vp_nodes::vp_screen_des_node>("screen_des_0", 0);
29     
30     /* save to file, `%d` is placeholder for filename index */
31     //auto image_des_0 = std::make_shared<vp_nodes::vp_image_des_node>("image_file_des_0", 0, "./images/%d.jpg", 3);
32     
33     /* push via udp,  receiving command for test: `gst-launch-1.0 udpsrc port=6000 ! application/x-rtp,encoding-name=jpeg ! rtpjpegdepay ! jpegparse ! jpegdec ! queue ! videoconvert ! autovideosink` */
34     auto image_des_0 = std::make_shared<vp_nodes::vp_image_des_node>("image_udp_des_0", 0, "192.168.77.248:6000", 3, vp_objects::vp_size(400, 200));
35 
36     // construct pipeline
37     yunet_face_detector_0->attach_to({file_src_0});
38     sface_face_encoder_0->attach_to({yunet_face_detector_0});
39     osd_0->attach_to({sface_face_encoder_0});
40     screen_des_0->attach_to({osd_0});
41     image_des_0->attach_to({osd_0});
42 
43     file_src_0->start();
44 
45     // for debug purpose
46     vp_utils::vp_analysis_board board({file_src_0});
47     board.display();
48 }
49 
50 #endif

上面程式碼執行效果如下:

 

更多更新掃碼加入微信群,及時獲取通知。

相關文章