Android 工程调用FastCV库

FastCV是高通专门定制的一个CV库,为了提高在ARM芯片乃至晓龙芯片的图像处理算法效率。网上有人专门对比过和opencv大部分算法的处理时间,接近十倍于opencv的速度。所以很值得尝试把原来OpenCV的接口改用FastCV来实现。

库有两个版本:

  • 一个运行在ARM处理器上被称为“FastCV for ARM”
  • 一个运行在高通Snapdragon芯片上被称为“FastCV for Snapdragon”

Github上面搜索到FastCV的demo,地址如下:
https://github.com/dongxiawu/FastcvDemo

拉下代码后,顺利编译,在Android7.1和8系统的设备上测试,发现由于Android相机接口的更改,在高版本系统上不兼容,导致程序相机回调无法正常运行,调用马上崩溃。于是决定新建个工程,自己调动fastcv的接口进行测试。

还没细看官方的文档,觉得github上的demo已经可以正常编译,直接把必要的代码抽离出来即可。

  1. 首先用AndroidStudio新建个支持C++开发的工程
    工程里面自动生成了CMakeLists.txt</code><code>`和</code><code>`native.cpp</code>

  2. 把FastCV Demo里的静态库和头文件加进工程
    拷贝libfastcv.a</code><code>`放置在工程</code><code>`jniLibs</code>目录下(可以根据不同芯片架构放置)
    拷贝fastcv.h</code><code>`放置在</code><code>`cpp</code>目录下

  3. 修改Cmake文件
    在工程src</code><code>`目录下的</code><code>`CMakeLists.txt</code>里添加以下代码

    
    # 添加 fastcv 静态库
    add_library(fastcv-lib STATIC IMPORTED)
    set_target_properties( fastcv-lib
                       PROPERTIES IMPORTED_LOCATION
                       &quot;${CMAKE_SOURCE_DIR}/src/main/jniLibs/libfastcv.a&quot;
                      )
    # 包含头文件目录
    include_directories(&quot;${CMAKE_SOURCE_DIR}/src/main/cpp/&quot;)

添加fastcv-lib引用

target_link_libraries( native-lib
fastcv-lib
${log-lib} )


4. **编写c++测试接口**
修改系统自动生成的<code>``native.cpp</code>``文件,在接口方法里添加测试代码

include "fastcv.h"

extern "C" JNIEXPORT jstring
JNICALL
Java_com_test_fastcv_MainActivity_stringFromJNI(
JNIEnv env,
jobject /
this */,
jbyteArray data) {
std::string hello = "Hello from C++";

char* szStr= new char[307200];
uint32_t corners[1000];
uint32_t numCorners;
fcvCornerFast9u8( (uint8_t*)szStr,
                  640,
                  480,
                  0,
                  0,
                  7,
                  corners,
                  300,
                  &amp;numCorners);
LOGI(&quot;get corners :%d&quot;,numCorners);
delete []szStr;
return env-&gt;NewStringUTF(hello.c_str());

}



5. **完成**
运行代码,能输出log <code>``“get corners :0”</code>``表示fastcv接口顺利调用

FastCV接口文档:
https://developer.qualcomm.com/docs/fastcv/api/index.html

16 评论

  1. really nice

    This is as a matter of fact established tidings my friend. you are a exceptionally good writer . i lust after to helping with you my website as well. tell me what do you deem fro it

    buy youtube views

    Thankyou again for posting such good content. Cheers

  2. I’m amazed, I have to admit. Seldom do I come across
    a blog that’s equally educative and interesting, and without a doubt, you have hit
    the nail on the head. The problem is something too few people are speaking
    intelligently about. I am very happy I stumbled across this in my search for something relating to this.

  3. hello there and thank you for your info – I’ve definitely picked up anything new
    from right here. I did however expertise some technical issues using this
    site, since I experienced to reload the site lots of times previous to I could get it to
    load properly. I had been wondering if your
    web hosting is OK? Not that I’m complaining, but slow loading instances times will sometimes affect your placement in google and can damage your quality score if advertising and marketing with Adwords.
    Anyway I’m adding this RSS to my e-mail and can look out for much more of
    your respective intriguing content. Make sure you update this again soon.

  4. I was wondering if you ever reasoned dynamical the system of your tract? Its real fountainhead statute; I like what youve got to say. But maybe you could a young author in the way of cognition so group could join with it outstrip. Youve got an awful lot of schoolbook for exclusive having one or 2 pictures. Maybe you could space it out meliorate?

发表评论

电子邮件地址不会被公开。