热门标签 | HotTags
当前位置:  开发笔记 > 编程语言 > 正文

AndroidJNI开发通过C++实现眼睑标注

C代码:#include#include#include#include

C++代码:


#include
#include
#include
#include
#include
#include #define LOGD(...) __android_log_print(ANDROID_LOG_DEBUG, "keymatch", __VA_ARGS__)
extern "C"{using namespace cv;using namespace std;void printMAtMessage(Mat &mat);JNIEXPORT jintArray JNICALL
Java_com_findai_xkk_myopencv_MainActivity_stringFromJNI(JNIEnv *env,jobject /* this */,jintArray pixels_, jint w, jint h) {jint* pixels = env->GetIntArrayElements(pixels_, NULL);if (pixels==NULL){return 0;}//图片一进来时是ARGB 通过mat转换BGRAMat img(h,w,CV_8UC4,(uchar *)pixels); //pixels 操作的是同一份数据h = h/2,w = w/2;resize(img,img,Size(w,h));printMAtMessage(img);Mat temp;
//转化为单通道灰度图,并打印信息cvtColor(img,temp,COLOR_RGBA2GRAY);
// printMAtMessage(temp);int summat[h][w] ;// Mat cal_mat = temp.clone();int max_cha = 0;
// LOGD("rows: %d",temp.rows);
// LOGD("cols: %d",temp.cols);
// LOGD("w: %d",w);
// LOGD("h: %d",h);
// int kk=0;for(int i =6 ;i// int sum_d = 0;for(int j =6;j// LOGD("DDD %d",temp.at(i,j));int sum_s = temp.at(i-1,j)+temp.at(i-2,j)+temp.at(i-3,j)+temp.at(i-4,j)+temp.at(i-5,j);
// LOGD("------================211111111111111111111111111===------------ %d %s",i,j);int sum_x = temp.at(i+1,j)+temp.at(i+2,j)+temp.at(i+3,j)+temp.at(i+4,j)+temp.at(i+5,j);
// LOGD("------==============22222222222222222222=====------------");int cha = sum_s - sum_x;
// LOGD("------===============3333333333333333333333333====------------");summat[i][j] = abs(cha);
// LOGD("------===============33333333333 %d 33333333333333====------------",summat[i][j]);
// temp.at(i,j)=255;
// kk++;
// LOGD("i: %d",i);
// LOGD("j: %d",j);
// LOGD("------==============444444444444444444444444=====------------");if(max_cha// LOGD("max %d",max_cha);
// LOGD("------============44666666666666666666666666666666666=======------------");}
// sum_d = sum_d + ;}}int std_max = max_cha*0.4;
// LOGD("------=========== %d ========------------",max_cha);for(int i =6 ;i// int max_col = 0;
// int max_i = 0;
// int max_j = 0;for(int j =6;j// LOGD("DDD %d",temp.at(i,j));
// int sum_s = temp.at(i-1,j)+temp.at(i-2,j)+temp.at(i-3,j)+temp.at(i-4,j)+temp.at(i-5,j);
// int sum_x = temp.at(i+1,j)+temp.at(i+2,j)+temp.at(i+3,j)+temp.at(i+4,j)+temp.at(i+5,j);
// int cha = sum_s - sum_x;
// int cur_gray = summat[i][j];
// LOGD("------=======cur_gray==== %d ========------------",cur_gray);if(summat[i][j] > std_max){// LOGD("------=======cur_gray==== %d ========------------",cal_mat.at(i,j));temp.at(i,j)=255;}
// if(max_cha// max_cha = cha;
// }
// sum_d = sum_d + ;}}//转化为四通道。特别注意:在调用ov图像处理函数时,一定要好好考虑一下图片的位数和通道.否则可能出现各种问题.cvtColor(temp,temp,COLOR_GRAY2BGRA);
// printMAtMessage(temp);uchar* tempData = temp.data;//对应数据指针int size = w*h;jintArray result = env->NewIntArray(size);
//env->SetIntArrayRegion(result,0,size,pixels);env->SetIntArrayRegion(result, 0, size, (const jint *) tempData);env->ReleaseIntArrayElements(pixels_, pixels, 0);return result;
}
void printMAtMessage(Mat &mat) {LOGD("***************************Mat信息开始************************");LOGD("mat.rows %d",mat.rows);LOGD("mat.cols %d",mat.cols);LOGD("mat.total %d",mat.total());LOGD("mat.channels %d",mat.channels());LOGD("mat.depth %d",mat.depth());LOGD("mat.type %d",mat.type());LOGD("mat.flags %d",mat.flags);LOGD("mat.elemSize %d",mat.elemSize());LOGD("mat.elemSize1 %d",mat.elemSize1());LOGD("***************************Mat信息结束************************");
}}

 



JAVA代码:

package com.findai.xkk.myopencv;import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.util.Log;
import android.widget.ImageView;
import android.widget.TextView;import org.opencv.android.OpenCVLoader;
import org.opencv.android.Utils;
import org.opencv.core.Mat;public class MainActivity extends AppCompatActivity {// Used to load the 'native-lib' library on application startup.static {System.loadLibrary("native-lib");}@Overrideprotected void onCreate(Bundle savedInstanceState) {super.onCreate(savedInstanceState);//非常重要,启动opencv,必须写在最前面OpenCVLoader.initDebug();setContentView(R.layout.activity_main);Bitmap bmp = BitmapFactory.decodeResource(getResources(),R.mipmap.eye);ImageView imageView = findViewById(R.id.iv_pro_img);int w = bmp.getWidth();int h = bmp.getHeight();
// System.out.println(w);
// System.out.println(h);int[] pixels = new int[w*h];bmp.getPixels(pixels, 0, w, 0, 0, w, h);long startTime = System.currentTimeMillis();int[] resultInt = stringFromJNI(pixels, w, h);long endTime = System.currentTimeMillis();Log.e("JNITime",""+(endTime-startTime));Bitmap resultImg = Bitmap.createBitmap(w/2,h/2, Bitmap.Config.ARGB_8888);//(@ColorInt int[] pixels, int offset, int stride,int x, int y, int width, int height)
// System.out.println(w/2);
// System.out.println(h/2);resultImg.setPixels(resultInt, 0, w/2, 0, 0, w/2,h/2);imageView.setImageBitmap(resultImg);}/*** A native method that is implemented by the 'native-lib' native library,* which is packaged with this application.*/public native int[] stringFromJNI(int[] pixels, int w, int h);
}

 核心思路:


眼睑处,灰度变化最大,所以上下采集一定空间范围的灰度值进行计算,同时减少噪声的干扰。算法实时性较高,能达到100FPS。

之前尝试过深度学习,MRCNN等方法,效果是不错,但是实时性跟不上,不适合在移动端部署。故采用传统图像处理方法,尝试过Sobel的梯度变化等等方法,最终本算法 简单有效实时性高。



效果图:


 

 

GitHUB:

https://github.com/xkkjiayou/MYOPencv_real

JNI C++参考:

https://blog.csdn.net/wulafly/article/details/71076594

https://blog.csdn.net/qq_29540745/article/details/52487832

https://blog.csdn.net/wjb820728252/article/details/78357269

https://blog.csdn.net/brcli/article/details/76407986


推荐阅读
  • Java太阳系小游戏分析和源码详解
    本文介绍了一个基于Java的太阳系小游戏的分析和源码详解。通过对面向对象的知识的学习和实践,作者实现了太阳系各行星绕太阳转的效果。文章详细介绍了游戏的设计思路和源码结构,包括工具类、常量、图片加载、面板等。通过这个小游戏的制作,读者可以巩固和应用所学的知识,如类的继承、方法的重载与重写、多态和封装等。 ... [详细]
  • Iamtryingtomakeaclassthatwillreadatextfileofnamesintoanarray,thenreturnthatarra ... [详细]
  • IhaveconfiguredanactionforaremotenotificationwhenitarrivestomyiOsapp.Iwanttwodiff ... [详细]
  • 阿,里,云,物,联网,net,core,客户端,czgl,aliiotclient, ... [详细]
  • 本文主要解析了Open judge C16H问题中涉及到的Magical Balls的快速幂和逆元算法,并给出了问题的解析和解决方法。详细介绍了问题的背景和规则,并给出了相应的算法解析和实现步骤。通过本文的解析,读者可以更好地理解和解决Open judge C16H问题中的Magical Balls部分。 ... [详细]
  • 本文讨论了使用差分约束系统求解House Man跳跃问题的思路与方法。给定一组不同高度,要求从最低点跳跃到最高点,每次跳跃的距离不超过D,并且不能改变给定的顺序。通过建立差分约束系统,将问题转化为图的建立和查询距离的问题。文章详细介绍了建立约束条件的方法,并使用SPFA算法判环并输出结果。同时还讨论了建边方向和跳跃顺序的关系。 ... [详细]
  • 本文讨论了一个关于cuowu类的问题,作者在使用cuowu类时遇到了错误提示和使用AdjustmentListener的问题。文章提供了16个解决方案,并给出了两个可能导致错误的原因。 ... [详细]
  • 本文介绍了UVALive6575题目Odd and Even Zeroes的解法,使用了数位dp和找规律的方法。阶乘的定义和性质被介绍,并给出了一些例子。其中,部分阶乘的尾零个数为奇数,部分为偶数。 ... [详细]
  • 如何自行分析定位SAP BSP错误
    The“BSPtag”Imentionedintheblogtitlemeansforexamplethetagchtmlb:configCelleratorbelowwhichi ... [详细]
  • 电话号码的字母组合解题思路和代码示例
    本文介绍了力扣题目《电话号码的字母组合》的解题思路和代码示例。通过使用哈希表和递归求解的方法,可以将给定的电话号码转换为对应的字母组合。详细的解题思路和代码示例可以帮助读者更好地理解和实现该题目。 ... [详细]
  • 在Android开发中,使用Picasso库可以实现对网络图片的等比例缩放。本文介绍了使用Picasso库进行图片缩放的方法,并提供了具体的代码实现。通过获取图片的宽高,计算目标宽度和高度,并创建新图实现等比例缩放。 ... [详细]
  • 向QTextEdit拖放文件的方法及实现步骤
    本文介绍了在使用QTextEdit时如何实现拖放文件的功能,包括相关的方法和实现步骤。通过重写dragEnterEvent和dropEvent函数,并结合QMimeData和QUrl等类,可以轻松实现向QTextEdit拖放文件的功能。详细的代码实现和说明可以参考本文提供的示例代码。 ... [详细]
  • 本文介绍了OC学习笔记中的@property和@synthesize,包括属性的定义和合成的使用方法。通过示例代码详细讲解了@property和@synthesize的作用和用法。 ... [详细]
  • 本文介绍了一种划分和计数油田地块的方法。根据给定的条件,通过遍历和DFS算法,将符合条件的地块标记为不符合条件的地块,并进行计数。同时,还介绍了如何判断点是否在给定范围内的方法。 ... [详细]
  • 本文介绍了P1651题目的描述和要求,以及计算能搭建的塔的最大高度的方法。通过动态规划和状压技术,将问题转化为求解差值的问题,并定义了相应的状态。最终得出了计算最大高度的解法。 ... [详细]
author-avatar
桔梗的坚守
这个家伙很懒,什么也没留下!
PHP1.CN | 中国最专业的PHP中文社区 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved | 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有