在Android设备上使用CCV [英] Using CCV on Android Device

查看:106
本文介绍了在Android设备上使用CCV的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有人尝试过在Android上使用libccv吗?我在网上找不到任何示例代码,想知道如何使用CCV在Android应用中实现跟踪器。



这包括以下操作:
-从android设备相机
处理图像-在设备屏幕上显示CCV处理的图像

解决方案

I最近实施了类似的操作。为此,我使用OpenCV设置了一个Android JNI项目,并使用OpenCV相机读取功能来存储帧。然后可以将指向帧数据的指针传递到CCV图像包装器,以与CCV库函数一起使用。 CCV具有最小的依赖性,并且最简单的启动和运行方式是将所需模块的源代码包含在项目的JNI目录中。



进行设置使用OpenCV的项目,您可以遵循



此设置很有用,因为它使您可以使用OpenCV和CCV的功能。希望这会有所帮助。


Has anybody tried using libccv on Android? I can't find any example code online and would like to know how implement a tracker in an Android app using CCV.

This includes doing things like: -Processing an image from the android device camera -Displaying an image processed by CCV on the device screen

解决方案

I've recently implemented something similar. To achieve this, I set up an Android JNI project with OpenCV and use the OpenCV camera reading capability to store the frames. A pointer to the frame data can then be passed to the CCV Image wrapper for use with the CCV library functions. CCV has minimal dependencies and the easiest way to get up and running is to include the source code of the modules you require in your JNI directory of the project.

To set up a project with OpenCV you can follow this tutorial. The OpenCV SDK has a sample project for a simple camera reader. The Android GitHub page contains a sample HelloJNI project here which shows how to set up your Android project with both Java and C/C++ using JNI. The CCV source can then be added to the C/C++ source directory so that your C/C++ functions have access to the library.

Once you have the project set up with OpenCV libraries and JNI functionality, it is a matter of saving the frame data with OpenCV and passing a pointer of it to the C code. Store each frame as a Mat object, the Mat object can then be passed to your C/C++ code like this: (Note this is only an extract showing the key code segments required)

package your.namespace.here;

import org.opencv.core.Core;
import org.opencv.core.Mat;

public class MainActivity{

    // Store frames in this object for later processing
    Mat frame;

    static {
        // Load the c file name with JNI bindings, e.g. here we load test.c
        System.loadLibrary("test");
    }

    // Declare the JNI function wrapper
    public native int ccvTest( long input, long output);

    // OpenCV methods here to store the frame, see 
    // OpenCV4Android - tutorial-1-camerapreview for full 
    // code description.
    //...

    // This function to be called after each frame is stored.
    // output can then be converted to Bitmap and displayed in ImageView
    // or used for further processing with OpenCV.
    public Mat processFrame(){
        Mat output = new Mat();
        ccvTest(frame.getNativeObjAddr(), output.getNativeObjAddr());
        return output;
    }
}

Using the HelloJNI template, a sample C file (for this example we call it test.c) with a call to one of the CCV library functions would look like this:

#include <string.h>
#include <jni.h>

#ifdef __cplusplus
extern "C" {
#endif
// ccv files to include should be compiled using c compiler
#include "ccv/lib/ccv.h"
#ifdef __cplusplus
}
#endif

#ifdef __cplusplus
extern "C" {
#endif

JNIEXPORT void JNICALL
Java_your_namespace_here_MainActivity_ccvTest( JNIEnv* env,
                                              jobject thiz,
                                              jlong input, jlong output)
{

    Mat* in_p  = (Mat*)input;
    Mat* out_p  = (Mat*)output;
    Mat &rgb = *in_p;
    ccv_dense_matrix_t* image = 0;

    // Pass the Mat data to the CCV Image wrapper
    ccv_read(rgb.data, &image, CCV_IO_BGR_RAW | CCV_IO_ANY_RAW |     CCV_IO_GRAY, rgb.rows, rgb.cols, rgb.step[0]);

    // Now the Mat is in ccv image format, you can pass
    // the image pointer to any ccv function you like.

    //
    // Put your calls to CCV library here..
    //

}
#ifdef __cplusplus
}
#endif

The tree structure of the project may look similar to this, with all of the ccv source in the jni/ccv folder:

This set up is useful as it allows you to hook into the functionality of both OpenCV and CCV. Hope this helps.

这篇关于在Android设备上使用CCV的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆