Ask Your Question

jiarongkoh's profile - activity

2020-03-04 09:43:22 -0500 received badge  Famous Question (source)
2017-07-04 10:07:18 -0500 received badge  Notable Question (source)
2016-06-18 03:19:21 -0500 received badge  Notable Question (source)
2016-05-31 16:35:47 -0500 received badge  Popular Question (source)
2015-12-23 04:54:29 -0500 received badge  Popular Question (source)
2015-01-18 02:49:37 -0500 received badge  Scholar (source)
2015-01-15 21:35:13 -0500 commented answer [Debugging] Provided data element number (1) should be multiple of the Mat channels count (4)

Hi @berak, thanks so much for your input. If I can't perform that threshold-ing with ROI, then how can I perform the thresholding of an roi on an image? It has been a problem I'm facing for quite some time and has yet to find a good solution. I thought working with pixels would be the best bet.

2015-01-14 08:35:08 -0500 asked a question [Debugging] Provided data element number (1) should be multiple of the Mat channels count (4)

Hi there, I am attempting to threshold a ROI of an image which contains a specific color yellow. So my objective is to threshold that specific ROI and then lay it back to the original image and then display the new image again. This new image will thus be the original image with that little ROI threshold-ed. I am trying out this this set of code which I have no idea if it will work yet. The idea is to set the ROI region in the original image with the threshold-ed colors at its corresponding pixel coordinates:

            Mat source = new Mat();     
    Utils.bitmapToMat(drawnBitmap, source);

    Mat roi = source.submat(100, 700, 100, 700);
    Log.w("roi type", String.valueOf(roi.type()));
    Mat mBGR= new Mat();
    Mat mBGRThres = new Mat();
    Imgproc.cvtColor(roi, mBGR, Imgproc.COLOR_RGBA2BGR,0);
    Core.inRange(mBGR, new Scalar(0, 255, 255), new Scalar(0, 255, 255), mBGRThres); 

    Mat thresholded= source.clone();
    for(int j=0; j<thresholded.rows(); j++)  { 
        for(int i=0;i<thresholded.cols(); i++) {
            if(i>=100 && i<=700 && j>=100 && j<=700){                   
                thresholded.put(j, i,mBGRThres.get(j-100, i-700) );
            }
        }

        }
    double color[]= source.get(300, 300); // rgb at the coordinate of the image 300, 300
    Log.w("RGB", String.valueOf(color[0]) + String.valueOf(color[1]) +String.valueOf(color[2]));

    Highgui.imwrite("Threshold.jpg", thresholded);

    Bitmap bmp = Bitmap.createBitmap(thresholded.rows(),
            thresholded.cols(), Config.ARGB_8888);
    Utils.matToBitmap(thresholded, bmp);

I tried compiling but the logcat throws me the following set of errors:

01-14 22:20:33.340: E/AndroidRuntime(6722): java.lang.UnsupportedOperationException: Provided data element number (1) should be multiple of the Mat channels count (4) 01-14 22:20:33.340: E/AndroidRuntime(6722): at org.opencv.core.Mat.put(Mat.java:2496)

So what I gather from this set of error is that the channels are different, the mBGRThres has (1) channel and thresholded has (4) channels. Is there any way to perform cvtColor or any other methods to align their channels? Correct me if my understanding of the error msg is warped. Thanks!

I develop on the Android platform in Eclipse using OpenCV249

2015-01-14 07:21:58 -0500 commented answer Obtaining coordinates of pixels lighted at specific color

@FooBar Thanks for your reply. I'm experimenting on the Core.inRange() but am having a little difficulty understanding it. I'm employing this: Core.inRange(image, new Scalar(0, 0, 0), new Scalar(0, 0, 0), displayimage); then <display the="" displayimage="">

What I understand from the docs is that the inRange() method displays any pixel within the range of the upperbound and lowerbound to be white. So for my case, any pixel with the BGR of 0,0,0 (which is black) will be displayed as white. Am I right to say that? If so, this method isn't giving me what it should be. In fact, it lights every pixel in image to black. Any idea where have I gone wrong?

2015-01-09 01:30:29 -0500 commented answer Thresholding on a specific area of an image

Is anyone able to help? I tried the code above, basically thresholds the submat and imwrite as an isolated image itself. I need the complete image with that little portion threshold-ed only. Can anyone please advise?

2015-01-08 00:31:40 -0500 commented answer Thresholding on a specific area of an image

@Vit thanks for your reply, but I don quite get it. I did this:

source= Utils.loadResource(this.getApplicationContext(), R.drawable.tread);
destination = new Mat(source.rows(), source.cols(), source.type());
Mat roi = source.submat(10, 100, 10, 100);  
Imgproc.threshold(roi, destination, 50, 255, Imgproc.THRESH_BINARY_INV);
Highgui.imwrite("ThreshZero.jpg", destination);

But it shows me a blank image. I'm guessing that when I perform the thresholding on the Mat roi, it is defining the roi as one isolated complete image itself. How can I modify my code, any advise?

2015-01-07 06:39:53 -0500 commented question Obtaining coordinates of pixels lighted at specific color

Hi @thdrksdfthmn thanks for replying. Pls pardon me I don quite get what you said. I drew it using the android's Canvas and Drawables method with the finger as the input. So you can imagine it as a doodling app. I can't seem to find methods on the java api that deals with HSV and moments, do you mind elaborating abit more on your approach?

2015-01-07 05:55:51 -0500 asked a question Obtaining coordinates of pixels lighted at specific color

Hi everyone, I am working on an app using OpenCV249 on android and would like to find means to obtain the coordinates of the pixels that are lighted at a specific color relative to the image. For instance if I draw a green dot using android's canvas and drawables on an image, is there a way to obtain the coordinates of that green dot relative to the image?

And if this process is extended to more complicated random sketches, ie circles or rectangles, is there a way to obtain those points as well? Do note that I am developing for android, thanks!

2015-01-07 05:47:09 -0500 asked a question Thresholding on a specific area of an image

Hi everyone, I am working on an app using OpenCV249 on android and would like to perform thresholding on a specific area of an image. This specific area is specified by the user by doodling a yellow rectangle on the image. Once he/she has selected this area, thresholding will be performed on that yellow rectangle window only and then output the entire image on a new ImageView.

I've went through the bulk of the java docs and I can't seem to find any suitable methods that allows me to define that thresholding window unfortunately. Anyone any advise please? Do note that I am developing for android.

2015-01-07 04:48:06 -0500 received badge  Enthusiast
2015-01-06 23:40:20 -0500 commented answer which class can show an image in java?

Hi berak, you mentioned that android is a total different story, could you care to share examples on performing the same operation on android? I am currently trying to do a simple thresholding on an image on android but like you said, this approach doesn't work.

2015-01-03 23:55:21 -0500 answered a question ndk-build not found in PATH

I manage to solve it. In fact both comments from Shirdutt and Mirza were the answers. I did not include the ndk path in my environment setting and included the .cmd behind ndk-build. The sample projects are all working fine after performing these actions.

2015-01-03 23:52:27 -0500 asked a question CvException error: ... in function void Java_org_opencv_android_Utils_nMatToBitmap2(JNIEnv*, jclass, jlong, jobject, jboolean)

Hi All, I am trying to perform a simple image thresholding activity but it throws the above errors. I can't seem to tell why is it throwing these errors. I am using OpenCV 249 and working on Eclipse IDE. My codes are:

public class mainactivity extends Activity {

private Mat destination, source;
private Bitmap image;

static {
    OpenCVLoader.initDebug();
}

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);

    Mat source = Highgui.imread(Environment.getExternalStorageDirectory()
            .getAbsolutePath() + "/CT Image/10006.bmp");

    destination = new Mat(source.rows(), source.cols(), source.type());

    Log.w("source type", String.valueOf(source.type()));
    Log.w("source rows", String.valueOf(source.rows()));
    Log.w("source columns", String.valueOf(source.cols()));
    Log.w("source width", String.valueOf(source.width()));
    Log.w("source height", String.valueOf(source.height()));
    Log.w("source size", String.valueOf(source.size()));

    destination = source;
    Imgproc.threshold(source, destination, 127, 255, Imgproc.THRESH_TOZERO);

    Log.w("destination type", String.valueOf(destination.type()));
    Log.w("destination rows", String.valueOf(destination.rows()));
    Log.w("destination columns", String.valueOf(destination.cols()));
    Log.w("destination width", String.valueOf(destination.width()));
    Log.w("destination height", String.valueOf(destination.height()));

    Highgui.imwrite("ThreshZero.jpg", destination);

    Bitmap bmp = Bitmap.createBitmap(1920, 1080, Config.ARGB_8888);
    Utils.matToBitmap(destination, bmp);
    ImageView photo = (ImageView) findViewById(R.id.imageView1);
    photo.setImageBitmap(bmp);
}

}

And my logcat is:

01-04 13:42:17.210: E/AndroidRuntime(26055): Process: com.example.test1, PID: 26055

01-04 13:42:17.210: E/AndroidRuntime(26055): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.test1/com.examples.test.mainactivity}: CvException [org.opencv.core.CvException: /home/reports/ci/slave_desktop/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)

My understanding of this logcat message is that my destination Mat and Bitmap bmp are of different 'dimensions'. I included the Log messages in my code to observe what are those 'dimensions' and these dimensions are all zeros. Anyone pls assist? In this project I am not using any jni folder.

2015-01-03 02:59:31 -0500 asked a question java.lang.UnsatisfiedLinkError: dalvik.system.PathClassLoader...couldn't find "libopencv_java249.so"

Hi all, I am trying to write a short activity to try out thresholding an image using OpenCV on Android using Eclipse. I used a sample code from Tutorialspoint.com and my aim for this set of code is to read an image from my resource/drawable folder and output another image after performing thresholding onto an imageview. The code is as follows:

public class mainactivity extends Activity {

private Mat destination;
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);
    try {

        System.loadLibrary(Core.NATIVE_LIBRARY_NAME);
        Mat source = Highgui.imread(getResources().getDrawable(R.drawable.splashbackground).toString(),
                Highgui.CV_LOAD_IMAGE_COLOR);
        destination = new Mat(source.rows(), source.cols(),
                source.type());

        destination = source;
        Imgproc.threshold(source, destination, 127, 255,
                Imgproc.THRESH_TOZERO);
        Highgui.imwrite("ThreshZero.jpg", destination);

    Bitmap bmp = Bitmap.createBitmap(640, 480, Config.ARGB_8888);
    Utils.matToBitmap(destination, bmp);
    ImageView photo= (ImageView) findViewById(R.id.imageView1);
    photo.setImageBitmap(bmp);
}

}

After running this set of code, the compiler throws the following set of errors:

01-03 16:45:09.963: E/AndroidRuntime(16118): java.lang.UnsatisfiedLinkError: dalvik.system.PathClassLoader[DexPathList[[zip file "/data/app/com.example.test1-2/base.apk"],nativeLibraryDirectories=[/vendor/lib, /system/lib]]] couldn't find "libopencv_java249.so"

I tried really hard to search for a solution on this but I still don't quite understand how to solve it. I have already imported the relevant OpenCV libraries. Pls help!

2015-01-01 09:49:30 -0500 commented answer ndk-build not found in PATH

Hi Shirdutt, thanks for replying! I believe that OpenCV indicated to remove the .cmd from ndk-build but I did try your approach to include the .cmd. The application build successfully but it crashes throwing the following errors java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{org.opencv.samples.tutorial2/org.opencv.samples.tutorial2.Tutorial2Activity}: java.lang.ClassNotFoundException: Didn't find class "org.opencv.samples.tutorial2.Tutorial2Activity" on path: DexPathList[[zip file "/data/app/org.opencv.samples.tutorial2-2/base.apk"],nativeLibraryDirectories=[/data/app/org.opencv.samples.tutorial2-2/lib/arm, /vendor/lib, /system/lib]]

Any idea what might this mean?

2015-01-01 09:43:12 -0500 commented answer ndk-build not found in PATH

Hi Mirza, thanks for replying but I don't quite understand your approach. I believe I've did the required ndk path setting in environment variable. So you are saying that I should go into the cmd prompt and navigate to the sample application and type ndk-build to generate a .so file?

2015-01-01 09:41:16 -0500 received badge  Editor (source)
2015-01-01 03:40:54 -0500 received badge  Student (source)
2014-12-31 06:56:34 -0500 asked a question ndk-build not found in PATH

Hi all

I just got started with OpenCV and was trying to begin with the sample apps. For some reason I can't get three of the apps to work. The compilation throws the following errors:image description

I tried to search for solutions but non of the solutions seem to work. I've tried:

  • Reinstalling the android ndk
  • included NDKROOT in build environment which direct to my android ndk directory

Pls help, I have no idea what to do already.

EDIT I realised that the android-ndk needs to be placed in a directory without spaces as required by android and thus i moved those relevant files. But I am still getting the exact same errors. I did the set up in environment variable as stated in the docs to use ndk-build, instead of ndk-build.cmd. image description image description