Skip to content

Instantly share code, notes, and snippets.

@phreeza
Created July 19, 2012 09:50
Show Gist options
  • Save phreeza/0d3d25b7634cb5247bba to your computer and use it in GitHub Desktop.
Save phreeza/0d3d25b7634cb5247bba to your computer and use it in GitHub Desktop.
OpenCV DynamicImager example
#include <iostream> // for standard I/O
#include <string> // for strings
#include <iomanip> // for controlling float print precision
#include <sstream> // string to number conversion
#include <opencv2/imgproc/imgproc.hpp> // Gaussian Blur
#include <opencv2/core/core.hpp> // Basic OpenCV structures (cv::Mat, Scalar)
#include <mtip.h>
int ocvMedianBlurMDF(HMTIPMOD hMod)
{
INPUT_DATASET("Input image", 0, 0, DST_BYTE, CONN_REQUIRED);
CONTROL_INT_SLIDER(
"Window Width", // name
5,1,30); // default,min,max value
OUTPUT_DATASET("Output image", 0, 0, DST_BYTE, 0);
return MRV_SUCCESS;
}
int ocvMedianBlurMIF(HMTIPMOD hMod, Dataset_byte *in, int window, Dataset_byte **out)
{
if(!in)
{
mmsg_ReportError("Missing input!");
return MRV_FAILURE;
}
*out = (Dataset_byte*)md_DatasetClone((Dataset*)in, DST_SAME);
if(!*out)
{
mmsg_ReportError("Could not clone image!");
return MRV_FAILURE;
}
BYTE *pin = DATA_PTR(in);
BYTE *pout = DATA_PTR(*out);
cv::Mat img_in(NY(in), NX(in), CV_MAKETYPE(CV_8U,NCHANNELS(in)), pin);
cv::Mat img_out(NY(in), NX(in), CV_MAKETYPE(CV_8U,NCHANNELS(in)), pout);
cv::medianBlur(img_in, img_out, 2*window + 1);
return MRV_SUCCESS;
}
REGISTER_MTIP_MODULE("OpenCV Median Blur", ocvMedianBlurMDF, ocvMedianBlurMIF, 0, 0, 0);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment