Ask Your Question

SumeetB's profile - activity

2018-05-05 11:38:18 -0500 received badge  Famous Question (source)
2017-09-25 06:19:30 -0500 received badge  Notable Question (source)
2017-06-08 04:47:51 -0500 received badge  Popular Question (source)
2016-08-10 11:52:11 -0500 asked a question OpenCV4Android Lower Screen Resolution While Maintaining Fullscreen

I am making an OpenCV app on android that needs a lowered resolution of 640x480 to compensate for the heavy image processing I am doing. I do this in the main activity like so:

mOpenCvCameraView.setMaxFrameSize(640, 480);

Where mOpenCvCameraView is of type JavaCameraView. The problem with this is that it shrinks the dimensions of the actual frame so that the camera preview is not fullscreen. Is there a way to stretch the small frame to fit my phone screen's dimensions, or is there a better way of going about this? Thanks in advance!

2016-07-13 15:03:00 -0500 commented question OpenCV C++ Problem Connecting to IP Camera

That did it. Thanks :)

2016-07-13 14:46:52 -0500 asked a question OpenCV C++ Problem Connecting to IP Camera

I have an IP Camera (Android Camera) that my pc is successfully connected to. I want to grab frames from the camera and process them with opencv. However, my program is unable to display the frames from the camera. Here is the code I am using:

Mat frame;"http://{ipadress}:8080/videofeed?x.mjpeg");
while(true) {
  stream1 >> frame; 
  imshow("cam", frame);

This successfully compiles and on the IP Camera app on my phone the number of connections increases by 1, but imshow() just displays a gray screen and the cursor changes to a loading animation indefinitely. Any help with this problem would be greatly appreciated!

2016-07-11 10:00:30 -0500 asked a question OpenCV Android Set Camera Exposure?

I have made an OpenCV project for android that tracks certain objects that emit very bright, colored light. I want to set the exposure of my camera instead of it adjusting automatically, otherwise the color gets washed out and the camera only picks up white light from the objects. Is it possible to do this using CameraBridgeViewBase or JavaCameraView? If not, are there any alternatives such that the color information of the objects I am trying to detect are not lost?

Thanks in advance for your help!

2016-07-10 13:56:07 -0500 received badge  Supporter (source)
2016-07-08 13:36:30 -0500 asked a question Android Native Opencv Unresolved Inclusions After Import

I exported an opencv/android project in eclipse to a different workspace because the previous workspace path was preventing ndk-build from working. After importing the project and the opencv library to the new workspace, I get unresolved inclusion errors for all opencv imports only. Ex:

#include <jni.h>
#include <opencv2/imgproc/imgproc.hpp>
#include <vector>
#include "DropletsDetector.h"

using namespace std;
using namespace cv;

int GRAY_MIN = 220, GRAY_MAX = 254;

extern "C" {
JNIEXPORT void JNICALL     Java_com_urop_chemistrydropletsar_MainActivity_TrackDroplets(JNIEnv*, jobject, jlong addrRgba);

JNIEXPORT void JNICALL     Java_com_urop_chemistrydropletsar_MainActivity_TrackDroplets(JNIEnv*, jobject, jlong addrRgba)
    Mat& mCameraFrame = *(Mat*)addrRgba;
    Mat mGrayBinary;
    Mat mGrayFrame;
    DropletsDetector detector;

    cvtColor(mCameraFrame, mGrayFrame, CV_BGR2GRAY);
    inRange(mGrayFrame, GRAY_MIN, GRAY_MAX, mGrayBinary);
    detector.trackDropletsGrayScale(mCameraFrame, mGrayBinary);

jni.h and opencv2/imgproc/imgproc.hpp give unresolved inclusion errors and all code in "extern C" is underlined orange and says "syntax error"

I have done the following to try to resolve the errors:

Under C++ General paths and symbols, I have the following lines:





Also under project Properties->Android->Library I have OpenCV Library - 3.1.0 added.

I had fixed these errors when they were in the previous workspace, but exporting the project seems to have brought the errors back. Can anyone help me with this issue? Thanks in advance!

2016-07-01 14:23:53 -0500 commented answer OpenCV4Android Unsatisfied Linker Error Moments

My main need is to extract information from contours such as xy position and area. Is there also a way to get xy position without moments? Sorry I did not include that in my original post, I did not think it would be relevant.

Note: I hesitated moving away from moments because it easily gets this information in 3 lines of code. I submitted the issue to itseez github, so hopefully they can come up with a solution soon.

2016-07-01 13:24:32 -0500 commented answer OpenCV4Android Unsatisfied Linker Error Moments

Just checked the OpenCV Library manifest. I am using 3.1.0 and I have Moments imported.

2016-07-01 13:08:06 -0500 commented answer OpenCV4Android Unsatisfied Linker Error Moments

ok. I am using opencv 3.1.0, but I will try re-downloading the latest version from github.

2016-07-01 12:15:28 -0500 commented answer OpenCV4Android Unsatisfied Linker Error Moments

Tried it. Program does not reach the print statement. Problem is with the line "Moments moment = Imgproc.moments(contour);"

2016-06-30 13:27:27 -0500 asked a question OpenCV4Android Unsatisfied Linker Error Moments

I am getting the following error when I try to run my android application:

java.lang.UnsatisfiedLinkError: No implementation found for double[] org.opencv.imgproc.Imgproc.moments_1(long) (tried Java_org_opencv_imgproc_Imgproc_moments_11 and Java_org_opencv_imgproc_Imgproc_moments_11__J)

Here is the code where the problem is occurring:

Imgproc.findContours(temp, contours, hierarchy, Imgproc.RETR_EXTERNAL, Imgproc.CHAIN_APPROX_SIMPLE);

if(contours.size() > 0) {
    int numObjects = contours.size();

    if (numObjects < MAX_OBJECTS) {

        for (int i = 0; i < contours.size(); i++) {
            //moments causing unsatisfied linker error
            Moments moment = Imgproc.moments((Mat)contours.get(i));
            double area = moment.m00;

Can anyone help me with this problem? Thanks in advance!

2016-06-29 00:35:21 -0500 commented question OpenCV Convert C++ to Java

ok. Thanks!

2016-06-29 00:05:26 -0500 commented question OpenCV Convert C++ to Java

I am detecting objects who appear as halos in a binary matrix, so I thought RETR_EXTERNAL would be good to get the outer contours only. I want to traverse the hierarchy to get the area of each contour and filter out bad candidates based on a min_area threshold. I also use this later on in my program to get a rotated rect so I can draw ellipses around good candidates.

2016-06-28 17:47:29 -0500 received badge  Editor (source)
2016-06-28 11:28:24 -0500 asked a question OpenCV Convert C++ to Java

Hi all,

I have the following code written in c++:

vector<Vec4i> hierarchy;
vector<vector<Point>> contours;
findContours(temp, contours, hierarchy, RETR_EXTERNAL, CHAIN_APPROX_SIMPLE);
double refArea = 0;
if(hierarchy.size() > 0) {
     int numObjects = hierarchy.size();
    //do stuff
 for(int i = 0; i >= 0; i = hierarchy[i][0]) {
       Moments moment = moments((Mat)contours[i]);
       double area = moment.m00;
       //do more stuff

I want to convert this to java for opencv android programming, but am unsure how. If anyone can help, that would be much appreciated!

2016-06-27 23:32:12 -0500 commented question OpenCV C++ Multithreading

@berak I was trying to implement something like this:

Except in c++ which I don't know how to do since I am new to opencv and multithreading. Also, if you would like to be helpful and show me how I can fix my mistakes, that would be much appreciated.

2016-06-27 11:22:51 -0500 asked a question OpenCV C++ Multithreading

I made a opencv c++ program that does a lot of image processing on frames from a video feed and as such decided to implement multithreading to speed things up. However, because I am new to opencv and multithreading, my implementation has caused my image processing functions to produce erroneous results. My guess is that the thread in which image processing occurs cannot keep up with the thread that reads in each frame. Here is my code:

void CaptureFrames() {
  VideoCapture capture(0);
  if (!capture.isOpened()) {
    cout << "cannot open camera" << endl;

  while (true) {
    //CAMERAFRAME is a global Mat defined at the top of my program;

void ProcessFrames() {

  while (true) {

  Mat hsvFrame;
  Mat binMat;
  Mat grayFrame;
  Mat grayBinMat;

  if (!CAMERAFRAME.empty()) {
    //do image processing functions (these worked before implementing threads and are not causing errors)

    imshow("gray binary", grayBinMat);
    imshow("multithread test", CAMERAFRAME);

if (waitKey(1) >= 0) { break; }

int main(int argc, char** argv[]) {
  thread t1(CaptureFrames);
  thread t2(ProcessFrames);

  while(true) {
    if(waitKey(1) >= 0) {break;}

  return 0;

Any ideas on what I am doing wrong?

2016-02-07 17:39:39 -0500 asked a question OpenCV4Android Circular Object Tracking

I am new to OpenCV and trying to track a circular object using find contours on Android using 3.1.0. I am following the sample color blob detector to write the code, but the drawContours() function never draws anything when I run the application. Here is the onCameraFrame() function, which is doing all the processing. Can you tell me what I am doing wrong?

  public Mat onCameraFrame(CvCameraViewFrame inputFrame) {
    Mat rgba = inputFrame.rgba();
    List<MatOfPoint> contours = new ArrayList<MatOfPoint>();
    Mat hierarchy = new Mat();
    Mat grayMat = new Mat();
    Imgproc.cvtColor(rgba, grayMat, Imgproc.COLOR_RGBA2GRAY);
    Imgproc.findContours(grayMat, contours, hierarchy, Imgproc.RETR_EXTERNAL, Imgproc.CHAIN_APPROX_SIMPLE);
    double maxArea = 0;
    Iterator<MatOfPoint> each = contours.iterator();
        MatOfPoint wrapper =;
        double area = Imgproc.contourArea(wrapper);
        if(area > maxArea){
            maxArea = area; 

    List<MatOfPoint> matchedContours = new ArrayList<MatOfPoint>();
        MatOfPoint contour =;
        if(Imgproc.contourArea(contour) > .1*maxArea){
            Core.multiply(contour, new Scalar(4,4), contour);

    Imgproc.drawContours(rgba, matchedContours, -1, new Scalar(0,255,0));

    return rgba; 
2016-01-23 13:55:09 -0500 received badge  Enthusiast
2016-01-22 15:02:08 -0500 asked a question Android Round Object Tracking with OpenCV

Hi all. I have been following a tutorial on tracking circular/elliptical objects with OpenCV 3.1.0 on Android and I need some help with code optimization and improving the recognition accuracy. Currently, the code tries to find all circles in each frame and draw an outline around it. Since I am very new to OpenCV, I was hoping someone could help me with the following issues:

  • When the camera recognizes a circular object and draws an outline, the framerate drops to 1-2fps. Otherwise, the framerate is decent. How can I optimize my code to remedy this?

  • I want to track a very specific object which also happens to be an imperfect circle. By that, I mean there are indents around the circumference of the circle. Also, if possible, I want to be able to track the object from the side (the object is cylindrical), which means smooth transitions between drawing circles (top view) and drawing ellipses/rectangles with rounded corners (angled/side view).

  • I get a lot of false positives as well as recognition of other circular objects. I have considered thresholding the frames based on the specific color of the object I want to track (white), but I am unsure how to implement this. Any tutorials/other resources on doing this would be greatly appreciated!

public class MainActivity extends Activity implements CvCameraViewListener2 { private static final String TAG = "OCVSample::Activity";

private CameraBridgeViewBase mOpenCvCameraView;
private boolean              mIsJavaCamera = true;
private MenuItem             mItemSwitchCamera = null;

private BaseLoaderCallback mLoaderCallback = new BaseLoaderCallback(this) {
    public void onManagerConnected(int status) {
        switch (status) {
            case LoaderCallbackInterface.SUCCESS:
                Log.i(TAG, "OpenCV loaded successfully");
            } break;
            } break;

public MainActivity() {
    Log.i(TAG, "Instantiated new " + this.getClass());

/** Called when the activity is first created. */
public void onCreate(Bundle savedInstanceState) {
    Log.i(TAG, "called onCreate");


    mOpenCvCameraView = (CameraBridgeViewBase) findViewById(;



public void onPause()
    if (mOpenCvCameraView != null)

public void 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!");

public void onDestroy() {
    if (mOpenCvCameraView != null)

public void onCameraViewStarted(int width, int height) {

public void onCameraViewStopped() {

public Mat onCameraFrame(CvCameraViewFrame inputFrame) {
    Mat rgba = inputFrame.rgba();
    Core.flip(rgba, rgba, 1);
    Mat greyMat = new Mat(); 
    Imgproc.cvtColor(rgba, greyMat,Imgproc.COLOR_RGBA2GRAY , 0);
    Imgproc.GaussianBlur(greyMat, greyMat, new Size(9, 9), 2,2);
    double dp = 1.2d;
    double minDist = 100; 
    int minRadius = 0;
    int maxRadius = 0; 
    double param1 = 70, param2 = 72;
    Mat circles = new Mat();

    Imgproc.HoughCircles(greyMat, circles, Imgproc.HOUGH_GRADIENT, dp, minDist, param1, param2, minRadius, maxRadius);
    int numCircles = (circles.rows()==0) ? 0: circles.cols();
    for (int i = 0; i < numCircles; i++) {
        double[] circleCoordinates = circles.get(0, i);
        int x = (int) circleCoordinates[0], y ...
2016-01-05 21:41:52 -0500 asked a question OpenCV Android Color Blob Detection Build Error

I am trying to run the sample project color blob detection and I get the following error: "Errors occurred during the build. Errors running builder 'CDT Builder' on project 'OpenCV Sample - color-blob-detection'. java.lang.NullPointerException "

Full error report:


pluginId org.eclipse.core.resources pluginVersion 3.10.1.v20150725-1910 code 2 severity 4 message Problems occurred when invoking code from plug-in: "org.eclipse.core.resources". fingerprint 76c9ec0d

Exception:java.lang.NullPointerException: null at org.eclipse.cdt.managedbuilder.internal.core.Tool.getOutputExtension( at org.eclipse.cdt.managedbuilder.makegen.gnu.GnuMakefileGenerator.addRuleForSource( at org.eclipse.cdt.managedbuilder.makegen.gnu.GnuMakefileGenerator.addFragmentMakefileEntriesForSource( at org.eclipse.cdt.managedbuilder.makegen.gnu.GnuMakefileGenerator.addSources( at org.eclipse.cdt.managedbuilder.makegen.gnu.GnuMakefileGenerator.populateFragmentMakefile( at org.eclipse.cdt.managedbuilder.makegen.gnu.GnuMakefileGenerator.regenerateMakefiles( at org.eclipse.cdt.managedbuilder.internal.core.CommonBuilder.performMakefileGeneration( at org.eclipse.cdt.managedbuilder.internal.core.CommonBuilder.performPrebuildGeneration( at at at at$ at at at at$ at at at at at org.eclipse.core.internal.resources.Project$ at at org.eclipse.core.internal.resources.Project.internalBuild( at at HIDDEN.HIDDEN(HIDDEN:-1) at