Ask Your Question

baharsan's profile - activity

2020-09-16 11:37:58 -0600 received badge  Popular Question (source)
2017-11-24 13:59:22 -0600 received badge  Famous Question (source)
2017-08-12 02:30:52 -0600 received badge  Notable Question (source)
2017-03-29 16:24:59 -0600 received badge  Famous Question (source)
2015-11-13 12:30:18 -0600 received badge  Popular Question (source)
2015-10-13 14:26:51 -0600 received badge  Notable Question (source)
2015-10-12 02:21:04 -0600 received badge  Famous Question (source)
2015-01-18 07:22:31 -0600 received badge  Notable Question (source)
2014-09-10 17:43:31 -0600 received badge  Notable Question (source)
2014-08-06 10:29:54 -0600 received badge  Popular Question (source)
2014-05-14 19:44:41 -0600 received badge  Popular Question (source)
2014-04-28 06:46:49 -0600 received badge  Popular Question (source)
2013-05-24 09:35:32 -0600 asked a question Core.inrange OpenCV 2.31 (Android)

I use core.inrange to skin detection but the problem is when app running about 1 minutes, it will turn off without returning any error. is this bug in opencv android ?

this my code :

       case ImageManipulationsActivity.VIEW_MODE_SKIN:
        capture.retrieve(mRgba, Highgui.CV_CAP_ANDROID_COLOR_FRAME_RGBA);
        Mat HSV = new Mat();
        Imgproc.cvtColor(mRgba, HSV, Imgproc.COLOR_RGB2HSV, 3);
        Core.inRange(HSV,  new Scalar(0, 100, 30), new Scalar(5, 255, 255), mRgba);
        Imgproc.cvtColor(mRgba, mRgba, Imgproc.COLOR_GRAY2BGRA, 4); 
        break;
    }
    Bitmap bmp = Bitmap.createBitmap(mRgba.cols(), mRgba.rows(), Bitmap.Config.ARGB_8888);
    if (Utils.matToBitmap(mRgba, bmp))
        return bmp;
    bmp.recycle();
    return null;

if i remove core.inrange, the app just running smoothly. i accept any suggestion about this, thanks.

2013-05-20 20:57:06 -0600 asked a question Memory Leaks opencv 2.3

I'am trying to use drawLargestContour mehthod to my program, but unfortunately my program suddenly turns off after about 1 minutes. I don't know why ? please some body help me :

this is my code (i use this for online capture) :

Mat HSV = new Mat();
    Imgproc.cvtColor(image, HSV, Imgproc.COLOR_RGB2HSV, 3);

    Mat mHSVThreshed = new Mat();
    //skin color detection
    Core.inRange(HSV,  new Scalar(0, 58, 89), new Scalar(25, 173, 229), mHSVThreshed);

    Mat hierarchy = new Mat(mHSVThreshed.rows(), mHSVThreshed.cols(), CvType.CV_8UC1, new Scalar(0));
    List<Mat> contours =new ArrayList<Mat>(100);

    Imgproc.findContours(mHSVThreshed, contours, hierarchy, Imgproc.RETR_EXTERNAL, Imgproc.CHAIN_APPROX_NONE);

    Mat Mask = new Mat();
    Mask = Mat.zeros(mHSVThreshed.rows(), mHSVThreshed.cols(), CvType.CV_8UC1);

    Imgproc.drawContours(Mask, contours, -1, new Scalar(255), Core.FILLED);

    Mat crop = new Mat(image.rows(), image.cols(), CvType.CV_8UC3);

    crop.setTo(new Scalar(0,255,0));

    image.copyTo(crop, Mask);

    Core.normalize(Mask.clone(), Mask, 0.0, 255.0, Core.NORM_MINMAX, CvType.CV_8UC1);

    Mat Biner = new Mat();
    Mask.convertTo(Biner, CvType.CV_8U);

    Imgproc.cvtColor(Biner, image, Imgproc.COLOR_GRAY2RGB, 0);
    Imgproc.cvtColor(image, image, Imgproc.COLOR_RGB2RGBA, 0);

    return image;
2013-04-28 15:14:00 -0600 received badge  Self-Learner (source)
2013-04-28 10:29:30 -0600 answered a question How Can I Implement cvSet2D in Android ?

you can look at this answer :

Link

2013-04-28 10:27:08 -0600 answered a question Displaying Mat Image in Android Screen

After some research and experiment, finally i find the light, here it is. you just need to get the image back to the default type. like this :

for (Rect r : faces){
        Core.rectangle(mRgba, r.tl(), r.br(), new Scalar(0, 255, 0, 255), 3);
        Mat roi = new Mat();
        roi = mRgba.submat(r);

        Mat gray = new Mat();
        Imgproc.cvtColor(roi, gray, Imgproc.COLOR_RGB2GRAY,1);

        Mat gray_f = new Mat();
        gray.convertTo(gray_f, CvType.CV_32F, 1.0/255, 0);

        Mat final = new Mat();
        gray_f.convertTo(final, CvType.CV_8U, 255, 0);

        Imgproc.cvtColor(final, roi, Imgproc.COLOR_GRAY2RGB,0);
        Imgproc.cvtColor(roi, roi, Imgproc.COLOR_RGB2RGBA,0);
        Mat kotak = new Mat();
        kotak = mRgba.colRange(r.x, r.x+r.width).rowRange(r.y, r.y+r.height);
        roi.copyTo(kotak);
    }     }

This is the Queen of This Answer :

        Mat final = new Mat();
        gray_f.convertTo(final, CvType.CV_8U, 255, 0);
2013-04-15 08:36:36 -0600 commented answer Displaying Mat Image in Android Screen

i already use COLOR_RGB2GRAY and it run smoothly , i can deal with that, what i am still confusing is when i was trying to convert gray image to different mat of type, in this case CV_32F, then display it in android screen, it will no result, but NOT forceclose. I still cannot Convert. may be you can help me buddy.

2013-04-15 07:36:21 -0600 commented answer Displaying Mat Image in Android Screen

Hi Steven, thank you for your updated answer. In fact, i was actually can do cvtcolor using opencv 2.3.1 in Android to convert RGB to GRAY and display it in Android Screen it's no problem for me. my problem is when i try to convert gray image from default type of mat (i don't know what the default type of mat) to CV_32F and display it on the screen, the result is RGB image. in the other hand, i try do same thing in opencv C++ and the result is gray image with type of mat CV_32F. i Think, there is something wrong when i try to convert, but why ? i don't know, i am really confused with this. i hope you can help me out from my problem.

i don't know why this happen, do you have a friend or someone who expert ... (more)

2013-04-14 21:21:32 -0600 commented question Skin Color Detection on ROI Image on Android
2013-04-14 21:04:23 -0600 marked best answer opencv4android - hand detection using viola jones (haar cascade)

i want to make a simple hand detection using OpenCV Android (haar classifier, viola jones) which can running in my android device. somebody can help me tutorial? i am newbie in opencv. please support me to finish this project. thanks for your attention. thanks in advances

Best Regards baharsan

2013-04-14 21:03:59 -0600 commented answer opencv4android - hand detection using viola jones (haar cascade)

thanks, it help me a lot, i have found sample android application to detect hand using haar classification

2013-04-14 16:24:17 -0600 received badge  Scholar (source)
2013-04-14 16:24:11 -0600 commented answer Convert cv::Mat::at to Android

many thanks dude, it help me a lot.

2013-04-13 17:55:20 -0600 received badge  Autobiographer
2013-04-13 16:52:06 -0600 asked a question Convert cv::Mat::at to Android

Hey There, please help me to figure it out : I have a opencv C++ code like :

 cv::Mat kernel(ks,ks, CV_32F);
    for (int y=-hks; y<=hks; y++)
    {
        for (int x=-hks; x<=hks; x++)
        {
            x_theta = x*del*cos(theta)+y*del*sin(theta);
            y_theta = -x*del*sin(theta)+y*del*cos(theta);
            kernel.at<float>(hks+y,hks+x) = (float)exp(-0.5*(pow(x_theta,2)+pow(y_theta,2))/pow(sigma,2))* cos(2*CV_PI*x_theta/lmbd + psi);
        }
    }

I want to convert below code to android

kernel.at<float>(hks+y,hks+x) = (float)exp(-0.5*(pow(x_theta,2)+pow(y_theta,2))/pow(sigma,2))* cos(2*CV_PI*x_theta/lmbd + psi);

can you help me please, thanks in advance :)

2013-04-13 16:32:28 -0600 commented answer Displaying Mat Image in Android Screen

please check my edited code above, i hope you can help me out from this. i just wanna know why these code run smoothly in opencv c++ and can't run in opencv4android. thank you steven for quick answer. and how to implement rightly convertTo in android.

2013-04-13 09:41:53 -0600 received badge  Student (source)
2013-04-13 01:21:28 -0600 commented question convert cv::Mat (C++, native Code) to Bitmap (Android, Java)

I Think this simple function code should help you much :

private void ExportMatToBitmap(Mat img_mat, String name) {
    Bitmap bmp = Bitmap.createBitmap(img_mat.cols(), img_mat.rows(),
            Bitmap.Config.ARGB_8888);
    Utils.matToBitmap(img_mat, bmp);
    try {
        FileOutputStream out = new FileOutputStream(name);
        bmp.compress(Bitmap.CompressFormat.JPEG, 90, out);
    } catch (Exception e) {
        e.printStackTrace();
    }
}
2013-04-13 01:19:08 -0600 asked a question Displaying Mat Image in Android Screen

Hei, I have a little problem when i try to convert opencv c++ to opencv4android. here it is :

Android Source Code -- Online Processing

    for (Rect r : faces){
            Core.rectangle(mRgba, r.tl(), r.br(), new Scalar(0, 255, 0, 255), 3);
            Mat roi = new Mat();
            roi = mRgba.submat(r);

            Mat gray = new Mat();
            Imgproc.cvtColor(roi, gray, Imgproc.COLOR_BGR2GRAY,1);

            Mat gray_f = new Mat();
            gray.convertTo(gray_f, CvType.CV_32F, 1.0/255, 0);

            Imgproc.cvtColor(gray_f, roi, Imgproc.COLOR_GRAY2BGR,0);
            Imgproc.cvtColor(roi, roi, Imgproc.COLOR_BGR2BGRA,0);
            Mat kotak = new Mat();
            kotak = mRgba.colRange(r.x, r.x+r.width).rowRange(r.y, r.y+r.height);
            roi.copyTo(kotak);
        }

C++ Source Code -- Offline Processing

 cv::Mat image = cv::imread("hand.jpg",1);
 cv::imshow("Src", image);
 cv::cvtColor(image, src, CV_BGR2GRAY);
 src.convertTo(src_f, CV_32F, 1.0/255, 0);
 cv::imshow("src", src);
 cv::imshow("src_f", src_f);

This the result of C++ :

image description

This the result of Android :

image description

I Think that's above code have the same result, but when i run above code in pc and in andrioid, they haven't same result. i don't know way, any body help me please to explain it. Thanks in Advance... your little help should make my life better.. :)

UPDATED

After some hard of research, i was find my final problem, i think i wrong to display Mat image, just look at this : http://stackoverflow.com/a/9471411/1593269, if i want to convert BGR to Gray image and then display it on the android screen i need this :

    Imgproc.cvtColor(image, dst4, Imgproc.COLOR_BGR2GRAY); //Convert BGR to GRAY
    Imgproc.cvtColor(dst4, image, Imgproc.COLOR_GRAY2BGR); **//Confuse with This**
    Imgproc.cvtColor(image, image, Imgproc.COLOR_BGR2BGRA); //To compate with default android standard (4 channel), so we need to change from 1 channel to 4 channel before we display

Somebody please help me to understand what the mean :

Imgproc.cvtColor(dst4, image, Imgproc.COLOR_GRAY2BGR); **//Confuse with This**

and For what this row of code ? if i don't write that's code, it will always force close. Once again, I am trying to convert mat of gray image to CV_32F, then i want to display it on the screen, and i am trying to figure it out by this :

Imgproc.cvtColor(imgmat, src, Imgproc.COLOR_RGB2GRAY,0);
src.convertTo(src_f, src_f.type(), 1.0/255, 0);
Imgproc.cvtColor(dest_mag, imgmat, Imgproc.COLOR_GRAY2RGB, 0);          
Imgproc.cvtColor(imgmat, imgmat, Imgproc.COLOR_RGB2RGBA, 0);

it will run smoothly on the screen but without desired result.(desired result : gray image with CV_32F (java primitive array))

2013-03-22 20:57:48 -0600 asked a question How Can I Implement cvSet2D in Android ?

Please Help me, i look arround over the internet and i cannot find how to implement cvSet2D in android, i use that function to gabor filtering, btw, anyone could help me how to implement gabor in android using OpenCV 2.3.1 for Android.

thanks alot

2013-02-26 19:38:59 -0600 received badge  Critic (source)
2013-02-26 19:38:52 -0600 received badge  Supporter (source)
2013-02-23 01:45:22 -0600 commented question Skin Color Detection on ROI Image on Android

Finally it's done, thank you so much all member here and stackoverflow forum. this reference to get it done :

http://stackoverflow.com/questions/9443377/android-color-detection-using-opencv-how-to