Ask Your Question

Mytheral's profile - activity

2017-11-21 02:41:07 -0600 received badge  Popular Question (source)
2016-07-27 09:15:49 -0600 asked a question JavaCV - LogPolar or LinearPolar

Is logPolar or linearPolar in the Opencv Java API? I've looked but I can't seem to find it.

2016-07-13 15:27:43 -0600 asked a question Looking for a way to turn a circle (unfilled) into a line.

So I have a bunch of data on an image that is condensed into an outer ring around a picture.

It looks something like this.

image description

What I want to do is take the segmented circle and unwrap it so it's a segmented line.

2016-05-31 16:16:51 -0600 asked a question OpenCV4Android - Resize a Contour but retain center?

So let's say that I have the contour of an object but I want to shave off the outer 5 pixels from the contour what would be the best way to do that?

Is there a way to scale a contour? Some form of erosion? A distance transform? or would it have to be done more manually?

I've seen this: http://answers.opencv.org/question/44...

The problem with the above approach is that it does not retain it's center and I would then have to run another contour to "get" the inner segment I want.

2016-03-03 04:07:15 -0600 received badge  Student (source)
2016-02-26 08:15:23 -0600 received badge  Scholar (source)
2016-02-26 08:08:24 -0600 asked a question OpenCV4Android - Extracting the outer edge of a circle.

So I have a set of images with a single circle on them in roughly the same location. On the edges of those circles I have various colors.

What I need to do is extract outer 100px of that circle and then take that extracted component and morph it into bar for evaluation.

A Hough Circle detection will let me easily grab the circle but what I don't know is how to access the parameter of that found circle and then extract a non-square segment. I guess I could go around it and extract slices but I'm hoping someone knows of something more elegant than that.

2015-04-08 14:59:56 -0600 answered a question How to determine the number of Chessboard corners found in CameraCalibration

The OpenCV4Android SDK contains a sample project covering camera calibration.

2015-04-08 14:57:58 -0600 commented answer How to determine the number of Chessboard corners found in CameraCalibration

He's asking for a OpenCV4Android solution that the linked book does not cover.

2015-04-08 14:57:25 -0600 received badge  Critic (source)
2015-04-01 09:52:31 -0600 asked a question OpenCV4Android - Alternative to vector<Vec3f>

So I found this example: https://github.com/Itseez/opencv/blob...

int main(int argc, char** argv)
{
    const char* filename = argc >= 2 ? argv[1] : "../data/board.jpg";

    Mat img = imread(filename, 0);
    if(img.empty())
    {
        help();
        cout << "can not open " << filename << endl;
        return -1;
    }

    Mat cimg;
    medianBlur(img, img, 5);
    cvtColor(img, cimg, COLOR_GRAY2BGR);

    vector<Vec3f> circles;
    HoughCircles(img, circles, HOUGH_GRADIENT, 1, 10,
                 100, 30, 1, 30 // change the last two parameters
                                // (min_radius & max_radius) to detect larger circles
                 );
    for( size_t i = 0; i < circles.size(); i++ )
    {
        Vec3i c = circles[i];
        circle( cimg, Point(c[0], c[1]), c[2], Scalar(0,0,255), 3, LINE_AA);
        circle( cimg, Point(c[0], c[1]), 2, Scalar(0,255,0), 3, LINE_AA);
    }

    imshow("detected circles", cimg);
    waitKey();

    return 0;
}

And the conversion is going fairly well but I don't know what to do with vector<Vec3f> circles; I've found other examples that convert it to a MatOfPoint but they tend not to use it for anything... MatOfPoint seems to be ideal but I'm assuming that it's a list of points which I can convert it to fairly easily but I'm afraid I'll loose some of the additional data that was in the vector.

Current Code:

private void getHoughCirclesTwo(Mat initPassed)
    {
        Mat workingInit = initPassed.clone();

        Mat greyInit = new Mat();
        Imgproc.medianBlur(workingInit, workingInit, 5);
        Imgproc.cvtColor(workingInit, greyInit, Imgproc.COLOR_BGR2GRAY);

        MatOfPoint circles;
        Imgproc.HoughCircles(workingInit, circles, Imgproc.CV_HOUGH_GRADIENT, 1, 10, 100, 30, 1, 30);
        // change the last two parameters 
        // (min_radius & max_radius) to detect larger circles

        //Convert MatOfPoint to point List

        List<Point> pointList = new ArrayList<Point>();
        pointList = circles.toList();

        for(int i = 0; i < pointList.size(); i++)
        {
            Point c = pointList.get(i);
            circle( greyInit, Point(c[0], c[1]), c[2], Scalar(0,0,255), 3, LINE_AA);
            circle( greyInit, Point(c[0], c[1]), 2, Scalar(0,255,0), 3, LINE_AA);
        }
    }

Is there a better object than MatOfPoint or should I be casting the list to something other than Points?

I'm using OpenCV4Android 2.4.11

Thanks in advance.

2015-03-27 09:33:06 -0600 commented answer OpenCV - Computing a best fit grid

I'm attempting this method currently, only downside is it's detecting the full ticket at the moment instead the various circles.

2015-03-27 07:01:45 -0600 commented question OpenCV4Android - find/drawContour error

@matman the threshold image is CV_8UC1

2015-03-26 15:31:05 -0600 commented question OpenCV4Android - find/drawContour error

@matman mHierarchy is a global in the app. I don't believe the OpenCV4Android actually has the other findContours methods... I know it errors out when I remove mHierarchy.

2015-03-26 13:44:45 -0600 asked a question OpenCV4Android - find/drawContour error

What I'm attempting to do is take a thresholded image and perform findContours on it then draw it out to a rotation corrected image. The rotation corrected image and the thresholded image work as expected so I'm at a bit of a loss figuring out why this would crash. The thersholded image is a grey version of the rotation corrected image that has had a binary threshold applied to it.

public void findImageContours(Mat passedThreshInt, Mat passedRotatedInit) 
    {
    /* Get Thresholded input image */
    Mat initThresh = passedThreshInt.clone();

    /* Get image to draw Contours on */
    Mat initRotated = passedRotatedInit.clone();

    /* Get contours from threshold image */
    List<MatOfPoint> contours = new ArrayList<MatOfPoint>();
    Imgproc.findContours(initThresh, contours, mHierarchy, Imgproc.RETR_EXTERNAL, Imgproc.CHAIN_APPROX_SIMPLE); //mHierarchy is a Global

    /* Draw Contours */
    Scalar CONTOUR_COLOR = new Scalar(255,0,0,255);

    Log.e(TAG, "Contours count: " + contours.size());
    Imgproc.drawContours(initRotated, contours, -1, CONTOUR_COLOR);

    /* Save Output */
    contouredInit = initRotated.clone(); //ContouredInit is Global
    Utils.matToBitmap(contouredInit, contouredBitmapInit); // contouredBitmapInit is Global
    }

Error:

Contours count: 1
OpenCV Error: Assertion failed (src.dims == 2 && info.height == (uint32_t)src.rows && info.width == (uint32_t)src.cols) in void Java_org_opencv_android_Utils_nMatToBitmap2(JNIEnv*, jclass, jlong, jobject, jboolean), file /hdd2/buildbot/slaves/slave_ardbeg1/50-SDK/opencv/modules/java/generator/src/cpp/utils.cpp, line 97
nMatToBitmap catched cv::Exception: /hdd2/buildbot/slaves/slave_ardbeg1/50-SDK/opencv/modules/java/generator/src/cpp/utils.cpp:97: error: (-215) src.dims == 2 && info.height == (uint32_t)src.rows && info.width == (uint32_t)src.cols in function void Java_org_opencv_android_Utils_nMatToBitmap2(JNIEnv*, jclass, jlong, jobject, jboolean)

And after that a JDI Dispatch Error.

2015-03-24 09:35:32 -0600 asked a question OpenCV4Android - findContours resize error?

So I'm attempting to use the findCountours method but I keep getting a resize error even though I have the sizes of the images staying consistent. I could be off my rocker but I'm guessing the contour is drawing off of the image but is there anyway I can check or protect against it?

public Mat findContours(Mat image) 
{
    /* NOTE: Using namespace cv & std */

    /* Get input image */
    Mat origImg = image;

    /* Threshold input image */
    Mat threshImg = origImg.clone();
    threshImg = convertToThreshold(origImg);

    /* Get contours from threshold image */
    Mat copyThres = threshImg.clone();
    List<MatOfPoint> contours = new ArrayList<MatOfPoint>();
    Imgproc.findContours(copyThres, contours, mHierarchy, Imgproc.RETR_EXTERNAL, Imgproc.CHAIN_APPROX_SIMPLE);

    Scalar CONTOUR_COLOR = new Scalar(255,0,0,255);

    Log.e(TAG, "Contours count: " + contours.size());
    Imgproc.drawContours(origImg, contours, -1, CONTOUR_COLOR);

    return origImg;
}

private Mat convertToThreshold(Mat image)
{
    if (image.type() == CvType.CV_8UC1)
    {
        Imgproc.threshold(image, image, 0, 255, Imgproc.THRESH_BINARY);

        return image;
    }
    else
    {
        Log.v(TAG, "Cannot Threshold: Wrong Image Type: " + image.type() + " Converting to CV_8UC1");

        Mat convertedTo8UC1 = new Mat(); 

        Imgproc.cvtColor(image, image, Imgproc.COLOR_BGR2GRAY);

        image.convertTo(convertedTo8UC1, CvType.CV_8UC1);

        Imgproc.threshold(convertedTo8UC1, convertedTo8UC1, 0, 255, Imgproc.THRESH_BINARY);

        return convertedTo8UC1;
    }
}

Error:

Contours count: 1
OpenCV Error: Assertion failed (src.dims == 2 && info.height == (uint32_t)src.rows && info.width == (uint32_t)src.cols) in void Java_org_opencv_android_Utils_nMatToBitmap2(JNIEnv*, jclass, jlong, jobject, jboolean), file /hdd2/buildbot/slaves/slave_ardbeg1/50-SDK/opencv/modules/java/generator/src/cpp/utils.cpp, line 97
nMatToBitmap catched cv::Exception: /hdd2/buildbot/slaves/slave_ardbeg1/50-SDK/opencv/modules/java/generator/src/cpp/utils.cpp:97: error: (-215) src.dims == 2 && info.height == (uint32_t)src.rows && info.width == (uint32_t)src.cols in function void Java_org_opencv_android_Utils_nMatToBitmap2(JNIEnv*, jclass, jlong, jobject, jboolean)
2015-03-18 12:18:51 -0600 commented question Android - OpenCV Imgproc.matchTempate: Method not avaliable

@draculaxx There was an issue with my image like berak said I ended up just grabbing the image in android and passing over a bitmap for opencv to Convert with Utils.bitmapToMat(inputBitmap, outputMat)

2015-03-18 08:36:50 -0600 received badge  Enthusiast
2015-03-17 14:37:57 -0600 asked a question OpenCV - Computing a best fit grid

So I have an image which looks similar to this:

image description

And what I need to do if create a best fit grid. The circles in this image are circular but they can be oval, oblong or any random shape you can think of and while they will be in the same relative location they could be shifted around by several pixels or the dots could "run" like when using paint.

I believe I need the grid so I can get the inner 75% of these dots and average the color contained in that 75%.

I've looked at Calib3d.findCirclesGridDefault but I believe that just creates a grid based on the center points of found circles. There isn't much documentation on the java side so please correct me if I'm wrong.

Calib3d.findCirclesGridDefault: http://docs.opencv.org/java/org/openc...

Is there an OpenCV Method to do this or is there any prefered method of generating a best fit grid?

2015-03-17 09:20:59 -0600 commented question OpenCV4Android - Otsu's Method: Error

Sweet that did the trick.

2015-03-17 08:39:17 -0600 commented question OpenCV4Android - Otsu's Method: Error

Good catch. Oddly even when I'm attempting to convert it to 8UC1 it is converting it to 8UC4

2015-03-17 07:48:33 -0600 asked a question OpenCV4Android - Otsu's Method: Error

What I'm trying to do is this.

Imgproc.threshold(image, image, 0, 255, Imgproc.THRESH_BINARY+Imgproc.THRESH_OTSU);

I have been looking around and I see various recommendations on what to put in for the threshold and max value. I can do a standard Binary Threshold so I'm assuming it's something specific with Otsu's method that I've misunderstood.

Error

OpenCV Error: Assertion failed (src.type() == CV_8UC1) in double cv::threshold(cv::InputArray, cv::OutputArray, double, double, int), file /hdd2/buildbot/slaves/slave_ardbeg1/50-SDK/opencv/modules/imgproc/src/thresh.cpp, line 719
imgproc::threshold_10() caught cv::Exception: /hdd2/buildbot/slaves/slave_ardbeg1/50-SDK/opencv/modules/imgproc/src/thresh.cpp:719: error: (-215) src.type() == CV_8UC1 in function double cv::threshold(cv::InputArray, cv::OutputArray, double, double, int)

EDIT: So I checked my image type and it's coming back with type 24. I attempt to convert it to 8UC1 and I still get the same error.

New Code.

if (image.type() == CvType.CV_8UC1)
        {
            Imgproc.threshold(image, image, 0, 255, Imgproc.THRESH_BINARY+Imgproc.THRESH_OTSU);

            return image;
        }
        else
        {
            Log.v(TAG, "Cannot Threshold: Wrong Image Type: " + image.type() + " Converting to CV_8UC1");

            Mat convertedTo8UC1 = new Mat(); 

            image.convertTo(convertedTo8UC1, CvType.CV_8UC1);

            Imgproc.threshold(convertedTo8UC1, convertedTo8UC1, 0, 255, Imgproc.THRESH_BINARY+Imgproc.THRESH_OTSU);

            return convertedTo8UC1;
        }
2015-03-12 08:16:52 -0600 asked a question OpenCV4Anroid - Resize Error

So I've been working on warpAffine but I've been having problems with it so I decided to keep the size of the image the same in the warpAffine and it works. But I still want the image resized to minimize distortion so I went to resize it and got the same error.

    private Mat rotate(Mat img, double angle)
    {
        double radians = Math.toRadians(angle);
        double sin = Math.abs(Math.sin(radians));
        double cos = Math.abs(Math.cos(radians));

        //double radian = Math.toRadians(waterMarkAngle);
        double newWidth = (img.width() * cos + img.height() * sin);
        double newHeight = (img.width() * sin + img.height() * cos);

        // rotating water image
        Point center = new Point(newWidth/2, newHeight/2);
        Mat rotMatrix = Imgproc.getRotationMatrix2D(center, angle, 1.0); 
        //1.0 means 100 % scale

        Size currentSize = new Size(img.width(), img.height());
        Size newSize = new Size(newWidth, newHeight);

        Mat temp = new Mat();

        Imgproc.warpAffine(img, img, rotMatrix, currentSize, Imgproc.INTER_LINEAR + Imgproc.CV_WARP_FILL_OUTLIERS); //Works if I keep it the same size

        Imgproc.resize(img, temp, newSize); //Fails here but same error

        return temp;
    }

Error:

OpenCV Error: Assertion failed (src.dims == 2 && info.height == (uint32_t)src.rows && info.width == (uint32_t)src.cols) in void Java_org_opencv_android_Utils_nMatToBitmap2(JNIEnv*, jclass, jlong, jobject, jboolean), file /hdd2/buildbot/slaves/slave_ardbeg1/50-SDK/opencv/modules/java/generator/src/cpp/utils.cpp, line 97

E/org.opencv.android.Utils(7530): nMatToBitmap catched cv::Exception: /hdd2/buildbot/slaves/slave_ardbeg1/50-SDK/opencv/modules/java/generator/src/cpp/utils.cpp:97: error: (-215) src.dims == 2 && info.height == (uint32_t)src.rows && info.width == (uint32_t)src.cols in function void Java_org_opencv_android_Utils_nMatToBitmap2(JNIEnv*, jclass, jlong, jobject, jboolean)
2015-03-12 08:16:51 -0600 asked a question OpenCV4Anroid - Resize Error

So I've been working on warpAffine but I've been having problems with it so I decided to keep the size of the image the same in the warpAffine and it works. But I still want the image resized to minimize distortion so I went to resize it and got the same error.

    private Mat rotate(Mat img, double angle)
    {
        double radians = Math.toRadians(angle);
        double sin = Math.abs(Math.sin(radians));
        double cos = Math.abs(Math.cos(radians));

        //double radian = Math.toRadians(waterMarkAngle);
        double newWidth = (img.width() * cos + img.height() * sin);
        double newHeight = (img.width() * sin + img.height() * cos);

        // rotating water image
        Point center = new Point(newWidth/2, newHeight/2);
        Mat rotMatrix = Imgproc.getRotationMatrix2D(center, angle, 1.0); 
        //1.0 means 100 % scale

        Size currentSize = new Size(img.width(), img.height());
        Size newSize = new Size(newWidth, newHeight);

        Mat temp = new Mat();

        Imgproc.warpAffine(img, img, rotMatrix, currentSize, Imgproc.INTER_LINEAR + Imgproc.CV_WARP_FILL_OUTLIERS); //Works if I keep it the same size

        Imgproc.resize(img, temp, newSize); //Fails here but same error

        return temp;
    }

Error:

OpenCV Error: Assertion failed (src.dims == 2 && info.height == (uint32_t)src.rows && info.width == (uint32_t)src.cols) in void Java_org_opencv_android_Utils_nMatToBitmap2(JNIEnv*, jclass, jlong, jobject, jboolean), file /hdd2/buildbot/slaves/slave_ardbeg1/50-SDK/opencv/modules/java/generator/src/cpp/utils.cpp, line 97

E/org.opencv.android.Utils(7530): nMatToBitmap catched cv::Exception: /hdd2/buildbot/slaves/slave_ardbeg1/50-SDK/opencv/modules/java/generator/src/cpp/utils.cpp:97: error: (-215) src.dims == 2 && info.height == (uint32_t)src.rows && info.width == (uint32_t)src.cols in function void Java_org_opencv_android_Utils_nMatToBitmap2(JNIEnv*, jclass, jlong, jobject, jboolean)
2015-03-12 07:11:47 -0600 edited question Android - Rotating an Image

So I'm attempting to rotate an image with OpenCV but I'm getting an error I don't understand and hoping someone can shed some light on it.

private Bitmap doStuff(Bitmap image)
{
    Mat img = new Mat();

    Utils.BitmaptoMat(image, img);

    Points[] pointsArray = new Point[3];

    pointsArray = getPoints(img); //Standard Template Matching

    double xDiff = pointArray[1].x - pointArray[0].x;
    double yDiff = pointArray[1].y - pointArray[0].y;
    double angle = Math.toDegrees(Math.atan2(yDiff, xDiff); //Angle Returned is -178.43493091440774

    img = roatate(img, angle); //Method call

    Utils.matToBitmap(img, returnFile) //Error is thrown when it hits this line
}

private Mat rotate(Mat img, double angle)
{
    double radians = Math.toRadians(angle); //radians is -3.1142770450250317
    double sin = Math.abs(Math.sin(radians)); // sin is 0.027312211802207727
    double cos = Math.abs(Math.cos(radians)); //cos is 0.9996269519608159

    int newWidth = (int) (img.width() * cos + img.height() * sin); //newWidth is 652
    int newHeight = (int) (img.width() * sin + img.height() * cos); //newHeight is 497

    // rotating image
    Point center = new Point(newWidth/2, newHeight/2);
    Mat rotImage = Imgproc.getRotationMatrix2D(center, angle, 1.0); 
    //1.0 means 100 % scale
    Size size = new Size(newWidth, newHeight);
    Imgproc.warpAffine(img, img, rotImage, size, Imgproc.INTER_LINEAR + Imgproc.CV_WARP_FILL_OUTLIERS);

    return img;
}

Error:

OpenCV Error: Assertion failed (src.dims == 2 && info.height == (uint32_t)src.rows && info.width == (uint32_t)src.cols) in void Java_org_opencv_android_Utils_nMatToBitmap2(JNIEnv*, jclass, jlong, jobject, jboolean), file /hdd2/buildbot/slaves/slave_ardbeg1/50-SDK/opencv/modules/java/generator/src/cpp/utils.cpp, line 97
nMatToBitmap catched cv::Exception: /hdd2/buildbot/slaves/slave_ardbeg1/50-SDK/opencv/modules/java/generator/src/cpp/utils.cpp:97: error: (-215) src.dims == 2 && info.height == (uint32_t)src.rows && info.width == (uint32_t)src.cols in function void Java_org_opencv_android_Utils_nMatToBitmap2(JNIEnv*, jclass, jlong, jobject, jboolean)

Edit: Added more for clarity