Home > DeveloperSection > Forums > openCV4android detect Shape and Color (HSV)
monica frank
monica frank

Total Post:10

Posted on    November-24-2015 3:19 AM

 Android Android 

 1 Reply(s)
 683  View(s)
Rate this:
I'm a beginner in openCV4android and I would like to get some help if possible . I'm trying to detect colored triangles,squares or circles using my Android phone camera but I don't know where to start. I have been reading OReilly Learning OpenCV book and I got some knowledge about OpenCV.

Here is what I want to make:

1- Get the tracking color (just the color HSV) of the object by touching the screen - I have already done this by using the color blob example from the OpenCV4android example

2- Find on the camera shapes like triangles, squares or circles based on the color choosed before.

I have just found examples of finding shapes within an image. What I would like to make is finding using the camera on real time.

Any help would be appreciated.

Best regards and have a nice day.

Mayank Tripathi
Mayank Tripathi

Total Post:397

Posted on    November-24-2015 4:41 AM

If you plan to implement NDK for your opencv stuff then you can use the same idea they are using in OpenCV tutorial 2-Mixedprocessing.

  // on camera frames call your native method
public Mat onCameraFrame(CvCameraViewFrame inputFrame)
mRgba = inputFrame.rgba();
Nativecleshpdetect(mRgba.getNativeObjAddr()); // native method call to perform color and object detection
// the method getNativeObjAddr gets the address of the Mat object(camera frame) and passes it to native side as long object so that you dont have to create and destroy Mat object on each frame
public native void Nativecleshpdetect(long matAddrRgba);

In Native side

JNIEXPORT void JNICALL Java_org_opencv_samples_tutorial2_Tutorial2Activity_Nativecleshpdetect(JNIEnv*, jobject,jlong addrRgba1)
    Mat& mRgb1 = *(Mat*)addrRgba1;
// mRgb1 is a mat object which points to the address of the input camera frame, so all the manipulations you do here will reflect on the live camera frame  
 //once you have your mat object(i.e mRgb1 ) you can implement all the colour and shape detection algorithm you have learnt in opencv book  

since all manipulations are done using pointers you have to be bit careful handling them. hope this helps

Don't want to miss updates? Please click the below button!

Follow MindStick