updated README, changed calculator name

This commit is contained in:
akash 2022-05-17 17:27:54 +05:30
parent 49d9440db9
commit e610e80c9e
3 changed files with 33 additions and 5 deletions

View File

@ -154,3 +154,17 @@ We welcome contributions. Please follow these
We use GitHub issues for tracking requests and bugs. Please post questions to We use GitHub issues for tracking requests and bugs. Please post questions to
the MediaPipe Stack Overflow with a `mediapipe` tag. 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 <cc_library> entry for your calculator (the name is 'custom_calculator' in this case, mentioning the name the calculator src file in last step in the <srcs> section).
3. Edit the /mediapipe/modules/pose_landmark/pose_landmark_cpu.pbtxt , creating a <node> 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 <PoseLandmarkCpu> in the <register_as> section. <PoseLandmarkCpu> 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.

View File

@ -59,7 +59,7 @@ using GpuBuffer = mediapipe::GpuBuffer;
// } // }
// } // }
// } // }
class AkashImageFlipCalculator : public Node { class CustomImageFlipCalculator : public Node {
public: public:
static constexpr Input<ImageFrame> kIn{"IMAGE"}; static constexpr Input<ImageFrame> kIn{"IMAGE"};
static constexpr Output<ImageFrame> kOut{"IMAGE"}; static constexpr Output<ImageFrame> kOut{"IMAGE"};
@ -125,6 +125,20 @@ class AkashImageFlipCalculator : public Node {
input_mat = formats::MatView(&input); input_mat = formats::MatView(&input);
format = input.Format(); format = input.Format();
/*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>>>>"<<input_mat.size;*/
// code to flip // code to flip
cv::flip(input_mat, flipped_mat, 1); cv::flip(input_mat, flipped_mat, 1);
// Use Flip code 0 to flip vertically // Use Flip code 0 to flip vertically
@ -159,7 +173,7 @@ class AkashImageFlipCalculator : public Node {
mediapipe::GlCalculatorHelper gpu_helper_; mediapipe::GlCalculatorHelper gpu_helper_;
#endif // !MEDIAPIPE_DISABLE_GPU #endif // !MEDIAPIPE_DISABLE_GPU
}; };
MEDIAPIPE_REGISTER_NODE(AkashImageFlipCalculator); MEDIAPIPE_REGISTER_NODE(CustomImageFlipCalculator);
} // namespace api2 } // namespace api2
} // namespace mediapipe } // namespace mediapipe

View File

@ -130,10 +130,10 @@ node {
} }
} }
# added by Akash # added by Akash for Image Flip Calculator
node { node {
calculator: "AkashImageFlipCalculator" calculator: "CustomImageFlipCalculator"
input_stream: "IMAGE:image1" input_stream: "IMAGE:image1"
output_stream: "IMAGE:image" output_stream: "IMAGE:image"
} }