Ask Your Question

JustMyName's profile - activity

2020-11-13 14:14:28 -0600 received badge  Popular Question (source)
2019-05-30 23:18:46 -0600 received badge  Popular Question (source)
2018-04-13 07:38:01 -0600 received badge  Student (source)
2018-03-26 05:56:33 -0600 commented question Get the vertices of card

Actually I have tried this method too. But as u see in the last image the card edge is not only consists of one straight

2018-03-25 22:18:04 -0600 asked a question Get the vertices of card

Get the vertices of card I am trying to detect a card and do warpperspective on the image. I have successfully get the c

2015-12-09 05:15:24 -0600 received badge  Enthusiast
2015-12-05 06:22:55 -0600 asked a question Mat hierarchy in Java vs vector<cv::Vec4i> hierarchy in C++

I have a function in C++ as below.

void trackFilteredObject(int &x, int &y, cv::Mat threshold, cv::Mat cameraFeed){

    cv::Mat temp;
        threshold.copyTo(temp);
        vector< vector<cv::Point> > contours;
        vector<cv::Vec4i> hierarchy;
        findContours(temp, contours, hierarchy, CV_RETR_CCOMP, CV_CHAIN_APPROX_SIMPLE);
        double refArea = 0;
        bool objectFound = false;

        if (hierarchy.size() > 0) {
            vector< vector<cv::Point> > largestContourVec;
            largestContourVec.push_back(contours.at(contours.size() - 1));
            Eco_Rect = boundingRect(largestContourVec.at(0));
            int numObjects = hierarchy.size();
            if (numObjects<100){
                for (int index = 0; index >= 0; index = hierarchy[index][0]){
                    cv::Moments moment = moments((cv::Mat)contours[index]);
                    double area = moment.m00;
                    if (area>0 && area>refArea){
                        x = moment.m10 / area;
                        y = moment.m01 / area;
                        objectFound = true;
                        refArea = area;
                    }
                }

                if (objectFound == true){
                    cv::circle(cameraFeed, cv::Point(x, y), 10, cv::Scalar(0, 255, 0), 2);
                    line(cameraFeed, cv::Point(roi_rect.width / 2, 0), cv::Point(roi_rect.width / 2, roi_rect.height), 2, 2);
                    line(cameraFeed, cv::Point(0, roi_rect.height / 2), cv::Point(roi_rect.width,roi_rect.height / 2), 2, 2);
                }
            }
            else cv::putText(cameraFeed, "TOO MUCH NOISE! ADJUST FILTER", cv::Point(0, 50), 1, 2, cv::Scalar(0, 0, 255), 2);
        }

}

Then I want to convert it to Java to use in android.

void trackFilteredObject(int x, int y, Mat threshold, Mat cameraFeed){

    Mat temp = new Mat();
    threshold.copyTo(temp);
    List<MatOfPoint> contours = new ArrayList<MatOfPoint>();
    Mat hierarchy = new Mat();
    findContours(temp, contours, hierarchy, 2, 2);
    double refArea = 0;
    boolean objectFound = false;

    if (hierarchy.size() > 0) {
        List<MatOfPoint> largestContourVec = new ArrayList<MatOfPoint>();
        largestContourVec.add(contours.get(contours.size() - 1));
        Eco_Rect = boundingRect(largestContourVec.get(0));
        int numObjects = hierarchy.size();
        if (numObjects<100){
            for (int index = 0; index >= 0; index = hierarchy[index][0]){
                Moments moment = moments((Mat)contours.get(index));
                double area = moment.get_m00();
                if (area>0 && area>refArea){
                    x = (int) (moment.get_m10() / area);
                    y = (int) (moment.get_m01() / area);
                    objectFound = true;
                    refArea = area;
                }
            }

            if (objectFound == true){
                circle(cameraFeed, new Point(x, y), 10, new Scalar(0, 255, 0), 2);
                line(cameraFeed, new Point(roi_rect.width / 2, 0), new Point(roi_rect.width / 2, roi_rect.height),new Scalar(0,0,255), 2, 2);
                line(cameraFeed, new Point(0, roi_rect.height / 2), new Point(roi_rect.width,roi_rect.height / 2),new Scalar(0,0,255), 2, 2);
            }
        }
        else putText(cameraFeed, "TOO MUCH NOISE! ADJUST FILTER", new Point(0, 50), 1, 2, new Scalar(0, 0, 255), 2);
    }

}

However, i do not how to convert 3 lines coding that i commented due to different type of hierarchy in C++ and Java.

hierarchy.size() > 0 Error: cant compare org.opencv.core.Size with int. This one maybe can replace by hierarchy != null.

int numObjects = hierarchy.size(); Error: Basically same as above but i have no idea how to change it. I need to know the size.

for (int index = 0; index >= 0; index = hierarchy[index][0]) Error: In c++ hierarchy is vector type but in Java is Mat type.

Anyone can help me?

2015-11-23 09:05:36 -0600 asked a question Access data from MatofPoint

I am using opencv in android. I run the following coding.

Imgproc.findContours(canny_output,contours,hierarchy,3,2);
Log.i("CS","Contour: "+ contours);

I try to print the value of contours and get the results as below.

Contour: [Mat [ 11CV_32SC2, isCont=true, isSubmat=false, nativeObj=0x1fc4ec0, dataAddr=0x1fc3970 ]

I know in Visual Studio, contours contain Point. But in android, how can i get the Point? And can anyone tell what is exactly MatofPoint?

2015-11-20 06:49:39 -0600 asked a question Error when switch flash light on android javacameraview

I am using OpenCV4Android in my project and i am using JavaCameraView. I tried to switch my phone flash light but failed. Here is my attempt.

public class Camera_View extends JavaCameraView {

private static final String TAG = "Camera View";
public boolean isFlashOn = false;

public Camera_View(Context context, AttributeSet attrs) {
    super(context, attrs);
}

public List<String> getEffectList() {
    return mCamera.getParameters().getSupportedColorEffects();
}

public boolean isEffectSupported() {
    return (mCamera.getParameters().getColorEffect() != null);
}

public String getEffect() {
    return mCamera.getParameters().getColorEffect();
}

public void setEffect(String effect) {
    Camera.Parameters params = mCamera.getParameters();
    params.setColorEffect(effect);
    mCamera.setParameters(params);
}

public List<Size> getResolutionList() {
    return mCamera.getParameters().getSupportedPreviewSizes();
}

public void setResolution(Size resolution) {
    disconnectCamera();
    mMaxHeight = resolution.height;
    mMaxWidth = resolution.width;
    connectCamera(getWidth(), getHeight());
}

public Size getResolution() {
    return mCamera.getParameters().getPreviewSize();
}

public void switchFlash(boolean flash_on) {
    Parameters p = mCamera.getParameters();
    if (!flash_on)
        p.setFlashMode(Parameters.FLASH_MODE_OFF);
    else
        p.setFlashMode(Parameters.FLASH_MODE_TORCH);
    mCamera.setParameters(p);
}

public void switchFlash() {
    Camera  tcamera = null;
    tcamera = Camera.open();
    Parameters p = tcamera.getParameters();
    if (isFlashOn)
        p.setFlashMode(Parameters.FLASH_MODE_OFF);
    else
        p.setFlashMode(Parameters.FLASH_MODE_TORCH);
    isFlashOn = !isFlashOn;
    tcamera.setParameters(p);
}

public void setupCameraFlashLight(boolean flash_on) {
    Camera camera = mCamera;
    if (camera != null) {
        Parameters params = camera.getParameters();

        if (params != null) {
            if (!flash_on) {
                isFlashOn = false;
                params.setFlashMode(Parameters.FLASH_MODE_OFF);
                camera.setParameters(params);
                camera.startPreview();
            } else {
                isFlashOn = true;
                params.setFlashMode(Parameters.FLASH_MODE_TORCH);
                camera.setParameters(params);
                camera.startPreview();

            }
        }
    }
}

i tried three method but i got this error. java.lang.NullPointerException. Anyone please help me.

2015-10-06 06:46:53 -0600 commented question CvException on OpenCV4Android

i attached the full coding at last of my question

2015-10-04 09:04:06 -0600 asked a question CvException on OpenCV4Android

I try to get my ROI by touching on the screen and save ROI to a mat. This is the part where the error occur.

@Override
public Mat onCameraFrame(CvCameraViewFrame inputFrame) {
    Mat rgba = inputFrame.rgba();
    Mat roi_mat = new Mat();

    if (startX!=0 && endX!=0){
        //Toast.makeText(this, "start:"+start_point+"   end:"+end_point, Toast.LENGTH_SHORT).show();
        Core.rectangle(rgba,start_point,end_point,border_colour,0,8, 0 );
        roi_rect = new Rect(startX,startY,(endX-startX),(endY-startY));
        Mat roi_mat_ref = new Mat(rgba,roi_rect);
        roi_mat_ref.copyTo(roi_mat);
        //rgba.copyTo(roi_mat);

    }
    return rgba;
}

Everything is okay when running the application. But when i want to get the ROI, it show an error.

10-04 20:19:18.754 6794-6859/com.example.tew.roi E/cv::error()﹕ OpenCV Error: Assertion failed (0 <= _rowRange.start && _rowRange.start <= _rowRange.end && _rowRange.end <= m.rows) in cv::Mat::Mat(const cv::Mat&, const cv::Range&, const cv::Range&), file /home/reports/ci/slave_desktop/50-SDK/opencv/modules/core/src/matrix.cpp, line 284

10-04 20:19:18.755 6794-6859/com.example.tew.roi E/org.opencv.core.Mat﹕ Mat::n_1Mat__JIIII() caught cv::Exception: /home/reports/ci/slave_desktop/50-SDK/opencv/modules/core/src/matrix.cpp:284: error: (-215) 0 <= _rowRange.start && _rowRange.start <= _rowRange.end && _rowRange.end <= m.rows in function cv::Mat::Mat(const cv::Mat&, const cv::Range&, const cv::Range&)

10-04 20:19:18.755 6794-6859/com.example.tew.roi W/dalvikvm﹕ threadid=11: thread exiting with uncaught exception (group=0x40fbf258)

10-04 20:19:18.756 6794-6859/com.example.tew.roi E/AndroidRuntime﹕ FATAL EXCEPTION: Thread-3348

     CvException [org.opencv.core.CvException: cv::Exception: /home/reports/ci/slave_desktop/50-SDK/opencv/modules/core/src/matrix.cpp:284: error: (-215) 0 <= _rowRange.start && _rowRange.start <= _rowRange.end && _rowRange.end <= m.rows in function cv::Mat::Mat(const cv::Mat&, const cv::Range&, const cv::Range&)
]

        at org.opencv.core.Mat.n_Mat(Native Method)
        at org.opencv.core.Mat.<init>(Mat.java:676)
        at com.example.tew.roi.MainActivity.onCameraFrame(MainActivity.java:154)
        at org.opencv.android.CameraBridgeViewBase.deliverAndDrawFrame(CameraBridgeViewBase.java:387)
        at org.opencv.android.JavaCameraView$CameraWorker.run(JavaCameraView.java:346)
        at java.lang.Thread.run(Thread.java:856)

My full coding