I am using this library for GPUImage processing.
I am trying to run filters in parallel like we do in iOS GPUImage library, but I am having issues while adding 3 inputs to one filter which extends MultiInputFilter
.
I am trying to combine
BasicCameraInputFilter
CannyEdgeDetectionFilter
SobelEdgeDetectionFilter
where BasicCameraInputFilter
is direct camera input.
BasicCameraInputFilter cameraInput = new BasicCameraInputFilter();
CannyEdgeDetectionFilter cannyEdgeDetectionFilter = new CannyEdgeDetectionFilter(1.0f,0.3f,0.6f);
SobelEdgeDetectionFilter sobelEdgeDetectionFilter = new SobelEdgeDetectionFilter();
CombinationFilter combinationFilter = new CombinationFilter();
cameraInput.addTarget(combinationFilter);
cannyEdgeDetectionFilter.addTarget(combinationFilter);
sobelEdgeDetectionFilter.addTarget(combinationFilter);
combinationFilter.registerFilterLocation(cameraInput,0);
combinationFilter.registerFilterLocation(cannyEdgeDetectionFilter,1);
combinationFilter.registerFilterLocation(sobelEdgeDetectionFilter,2);
combinationFilter.addTarget(this);
registerInitialFilter(cameraInput);
registerFilter(cannyEdgeDetectionFilter);
registerFilter(sobelEdgeDetectionFilter);
registerTerminalFilter(combinationFilter);
Here is my fragment shader for my CombinationFilter
"precision mediump float;\n"
+"uniform sampler2D " + UNIFORM_TEXTURE0 + ";\n"
+"uniform sampler2D " + UNIFORM_TEXTUREBASE + 1 + ";\n"
+"uniform sampler2D " + UNIFORM_TEXTUREBASE + 2 + ";\n"
+"varying vec2 " + VARYING_TEXCOORD + ";\n"
+"void main(){\n"
+" vec4 color1 = texture2D(" + UNIFORM_TEXTURE0 + ", " + VARYING_TEXCOORD + ");\n"
+" vec4 color2 = texture2D(" + UNIFORM_TEXTUREBASE + 1 + ", " + VARYING_TEXCOORD + ");\n"
+" vec4 color3 = texture2D(" + UNIFORM_TEXTUREBASE + 2 + ", " + VARYING_TEXCOORD + ");\n"
+" vec4 whiteColor = vec4(1.0);\n"
+" whiteColor.r = color1.r * color2.r * color3.r;\n"
+" whiteColor.g = color1.g * color2.g * color3.g;\n"
+" whiteColor.b = color1.b * color2.b * color3.b;\n"
+" gl_FragColor = whiteColor;\n"
+"}\n";
The library you're using is out dated and I don't think its being maintained as its author has not been active since 2015. If you're trying to manipulate images on android, then I'll using opencv. Here is how you'd combine the Canny and Sobel filters.
public class ImageManipulationsActivity extends Activity implements CvCameraViewListener2 {
private static final String TAG = "OCVSample::Activity";
private CameraBridgeViewBase mOpenCvCameraView;
private Mat mIntermediateMat;
public static int viewMode = VIEW_MODE_RGBA;
private BaseLoaderCallback mLoaderCallback = new BaseLoaderCallback(this) {
@Override
public void onManagerConnected(int status) {
switch (status) {
case LoaderCallbackInterface.SUCCESS:
{
Log.i(TAG, "OpenCV loaded successfully");
mOpenCvCameraView.enableView();
} break;
default:
{
super.onManagerConnected(status);
} break;
}
}
};
public ImageManipulationsActivity() {
Log.i(TAG, "Instantiated new " + this.getClass());
}
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
Log.i(TAG, "called onCreate");
super.onCreate(savedInstanceState);
getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
mOpenCvCameraView = new CameraBridgeViewBase(this);
mOpenCvCameraView.setCvCameraViewListener(this);
setContentView(mOpenCvCameraView);
}
@Override
public void onPause()
{
super.onPause();
if (mOpenCvCameraView != null)
mOpenCvCameraView.disableView();
}
@Override
public void onResume()
{
super.onResume();
if (!OpenCVLoader.initDebug()) {
Log.d(TAG, "Internal OpenCV library not found. Using OpenCV Manager for initialization");
OpenCVLoader.initAsync(OpenCVLoader.OPENCV_VERSION_3_0_0, this, mLoaderCallback);
} else {
Log.d(TAG, "OpenCV library found inside package. Using it!");
mLoaderCallback.onManagerConnected(LoaderCallbackInterface.SUCCESS);
}
}
public void onDestroy() {
super.onDestroy();
if (mOpenCvCameraView != null)
mOpenCvCameraView.disableView();
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
Log.i(TAG, "called onCreateOptionsMenu");
return false;
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
Log.i(TAG, "called onOptionsItemSelected; selected item: " + item);
return false;
}
public void onCameraViewStarted(int width, int height) {
mIntermediateMat = new Mat();
}
public void onCameraViewStopped() {
// Explicitly deallocate Mats
if (mIntermediateMat != null)
mIntermediateMat.release();
mIntermediateMat = null;
}
public Mat onCameraFrame(CvCameraViewFrame inputFrame) {
Mat rgba = inputFrame.rgba();
Size sizeRgba = rgba.size();
Mat rgbaInnerWindow;
rgbaInnerWindow = rgba.submat(top, top + height, left, left + width);
Imgproc.Canny(rgbaInnerWindow, mIntermediateMat, 80, 90);
Mat grayInnerWindow = gray.submat(top, top + height, left, left + width);
Imgproc.Sobel(mIntermediateMat, grayInnerWindow, CvType.CV_8U, 1, 1);
Core.convertScaleAbs(grayInnerWindow, mIntermediateMat, 10, 0);
Imgproc.cvtColor(mIntermediateMat, rgbaInnerWindow, Imgproc.COLOR_GRAY2BGRA, 4);
grayInnerWindow.release();
rgbaInnerWindow.release();
return rgba;
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With