From e610e80c9ee76355f336f9047f68359a42a80eec Mon Sep 17 00:00:00 2001 From: akash Date: Tue, 17 May 2022 17:27:54 +0530 Subject: [PATCH] updated README, changed calculator name --- README.md | 14 +++++++++++++ .../image/image_flip_calculator.cc | 20 ++++++++++++++++--- .../pose_landmark/pose_landmark_cpu.pbtxt | 4 ++-- 3 files changed, 33 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index 9c81095c5..5e08c3e27 100644 --- a/README.md +++ b/README.md @@ -154,3 +154,17 @@ We welcome contributions. Please follow these We use GitHub issues for tracking requests and bugs. Please post questions to the MediaPipe Stack Overflow with a `mediapipe` tag. + + +## Steps to add an image_flip_calculator +Objective of this exercise is to create a custom calculator which can do some custom prcessing of the image('flipping') and then insert this calculator in the mediapipe graph pipe line. +Description: Calculators are the blocks of code which reperesent a node in a subgraph in mediapipe computational graphs. + +1. Goto /mediapipe/calculators/image directory , which contains several image manipulation calculators, place your custom calculator code in a .cc file right here. +2. Edit the BUILD file in the same image folder by creating a entry for your calculator (the name is 'custom_calculator' in this case, mentioning the name the calculator src file in last step in the section). +3. Edit the /mediapipe/modules/pose_landmark/pose_landmark_cpu.pbtxt , creating a entry for your calculator by giving it a name ('CustomImageFlipCalculator' in this case, same as that of the class defined by the calculator in step 1. ) whose input willbe the inputstream of the graph and output will connect to the node previously connected to the original input stream) +4. The node created in the step 3 will connect to you custom_calculator by making an entry in the BUILD file in /mediapipe/modules/pose_landmark/ ; edit the file by finding the entry which mentions name in the section. is the name of the sub_graph described by the pose_landmark_cpu.pbtxt. +In the 'deps' section, add the calculator entry as dependency to the subgraph(in this case "//mediapipe/calculators/image:custom_calculator"). +5. BUILD your custom calculator by running +"bazel build -c opt --define MEDIAPIPE_DISABLE_GPU=1 mediapipe/calculators/image:custom_calculator" , and also for the pose_detection by running +"bazel build -c opt --define MEDIAPIPE_DISABLE_GPU=1 mediapipe/examples/desktop/pose_tracking:pose_tracking_cpu", and then run the pose detection desktop example. \ No newline at end of file diff --git a/mediapipe/calculators/image/image_flip_calculator.cc b/mediapipe/calculators/image/image_flip_calculator.cc index d48c52cc4..1db22341a 100755 --- a/mediapipe/calculators/image/image_flip_calculator.cc +++ b/mediapipe/calculators/image/image_flip_calculator.cc @@ -59,7 +59,7 @@ using GpuBuffer = mediapipe::GpuBuffer; // } // } // } -class AkashImageFlipCalculator : public Node { +class CustomImageFlipCalculator : public Node { public: static constexpr Input kIn{"IMAGE"}; static constexpr Output kOut{"IMAGE"}; @@ -125,7 +125,21 @@ class AkashImageFlipCalculator : public Node { input_mat = formats::MatView(&input); format = input.Format(); - // code to flip + /*cv::Rect myROI(0, 0, output_width/2, output_height/2); + cv::Mat croppedRef(input_mat, myROI); + cv::Mat cropped; + croppedRef.copyTo(cropped); + cv::Mat imgPanel(480, 640, CV_8UC1, Scalar(0)); + Mat imgPanelRoi(imgPanel, Rect(0, 0, imgSrc.cols, imgSrc.rows)); + imgSrc.copyTo(imgPanelRoi); + cv::resize(cropped, input_mat, cv::Size(), 2, 2); + std::cout<<"size>>>>"<