openCV4android检测形状和颜色(HSV)

Ike*_*ker 8 android opencv

我是openCV4android的初学者,如果可能,我想得到一些帮助.我正在尝试使用我的Android手机相机检测彩色三角形,正方形或圆形,但我不知道从哪里开始.我一直在阅读OReilly Learning OpenCV一书,我对OpenCV有了一些了解.

这是我想要做的:

1-通过触摸屏幕获取对象的跟踪颜色(只是颜色HSV) - 我已经通过使用OpenCV4android示例中的颜色blob示例完成了此操作

2-根据之前选择的颜色查找相机形状,如三角形,正方形或圆形.

我刚刚找到了在图像中查找形状的示例.我想要的是实时使用相机.

任何帮助,将不胜感激.

最好的问候,祝你有个愉快的一天.

Dar*_*han 6

如果您计划为opencv实现NDK,那么您可以使用他们在OpenCV教程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);
Run Code Online (Sandbox Code Playgroud)

在本土方面

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  

}
Run Code Online (Sandbox Code Playgroud)

因为所有操作都是使用指针完成的,所以你必须小心处理它们.希望这可以帮助