0

I use the camera functionality of android and capture the image in the form of a bitmap. I tried to extract an area of a certain color(RED, PINK, BLUE, YELLOW) from the captured image using the following method but was not successful:

for(int i=0;i<bitmap.getWidth();i++){
for(int j=0;j<bitmap.getHeigth();j++){
    int pixel = bitmap.getPixel(i,j);
    if(pixel == Color.RED){
        //create new image
    }
}
 }

I got to know openCV can be used in this matter. If someone can show me the way it would be greatly appreciated.

TharakaNirmana
  • 10,237
  • 8
  • 50
  • 69

2 Answers2

1

I think, this task can be solved with some blob library e.g. cvBlob there is android version too cvBlobAndroid.

And when you trying to do it from scratch, it's better to covert image to some more convenient color space e.g. HSV, CIELab, etc.

Also, do not use precise color component values comparsion in condition (A==colorValue), use values range comparsion instead (A>minColorValue && A<maxColorValue).

Andrey Smorodov
  • 10,649
  • 2
  • 35
  • 42
  • will I be able to extract the smaller square from the larger square (lottery) in this link using the solution that you provided?: http://stackoverflow.com/questions/16663504/extract-text-from-a-captured-image?noredirect=1#comment23973954_16663504 – TharakaNirmana Sep 06 '13 at 03:51
  • The link you provide was deleted. But if I understand you correct, you can find larger region, then set ROI on this region, and then extract smaller region/regions. cvBlob allows you get multiple color regions. – Andrey Smorodov Sep 06 '13 at 05:43
  • could you provide an answer for this :http://stackoverflow.com/questions/18650155/extract-a-rectangular-area-from-a-bitmap-in-android-using-opencv – TharakaNirmana Sep 06 '13 at 05:54
  • The sample project that is available with openCV SDK named "OpenCV Sample - color-blob-detection" identifies the area according to the color. But it is not possible to extract that area. Will you be able to direct me? – TharakaNirmana Sep 20 '13 at 06:04
  • What kind of problem with extraction do you have? – Andrey Smorodov Sep 20 '13 at 07:15
  • This project: "OpenCV Sample - color-blob-detection" that comes with the openCV samples can be used perfectly to draw a border kind of thing around a particular region according to the color I select. But I do not know how to extract that area which is covered by the border. I tried saving every mat object to sdcard in the code by converting them to bitmap but all I managed to get was a black color bitmap with no information on it. I am requesting help to capture the area identified by the border. – TharakaNirmana Sep 20 '13 at 07:51
  • I think this should help: http://stackoverflow.com/questions/10917480/opencv-android-java-matrix-submatrix-roi-region-of-interest – Andrey Smorodov Sep 20 '13 at 08:03
  • I am still unable to use your solution. My problem is this: http://stackoverflow.com/questions/18650155/extract-a-rectangular-area-from-a-bitmap-in-android-using-opencv , would be a great help if you could direct me to correct track. – TharakaNirmana Sep 20 '13 at 14:35
  • Sorry I can't direct you in this issue, I have some knolledge in machine vision, but I'm not an experienced Android programmer, my native language is C++. – Andrey Smorodov Sep 20 '13 at 14:41
1

To detect a region in in a specific color you should use the Core.inRange function of opencv.

You can see a code sample here: ANDROID - color detection using openCV - how to?

Community
  • 1
  • 1
Ran Wakshlak
  • 1,734
  • 1
  • 13
  • 9