- c - 在位数组中找到第一个零
- linux - Unix 显示有关匹配两种模式之一的文件的信息
- 正则表达式替换多个文件
- linux - 隐藏来自 xtrace 的命令
我一直在尝试编译this Android Studio 2.2 中的源代码,使用 Android NDK、OpenCV-2.4.10 和 OpenCV-2.4.10-android-sdk 。我已经能够使用这个编译库 thread使用 Android NDK 但问题是,当我运行应用程序时它崩溃并出现以下异常:
10-19 13:16:52.401 27219-27219/? W/System.err: Native code library failed to load.
10-19 13:16:52.401 27219-27219/? W/System.err: java.lang.UnsatisfiedLinkError: com.android.tools.fd.runtime.IncrementalClassLoader$DelegateClassLoader[DexPathList[[dex file "/data/data/com.example.shahzeb.testingndk/files/instant-run/dex/slice-support-annotations-24.2.1_fed5c262a94aefc942781eb9d084010e5bac6a17-classes.dex", dex file "/data/data/com.example.shahzeb.testingndk/files/instant-run/dex/slice-slice_9-classes.dex", dex file "/data/data/com.example.shahzeb.testingndk/files/instant-run/dex/slice-slice_8-classes.dex", dex file "/data/data/com.example.shahzeb.testingndk/files/instant-run/dex/slice-slice_7-classes.dex", dex file "/data/data/com.example.shahzeb.testingndk/files/instant-run/dex/slice-slice_6-classes.dex", dex file "/data/data/com.example.shahzeb.testingndk/files/instant-run/dex/slice-slice_5-classes.dex", dex file "/data/data/com.example.shahzeb.testingndk/files/instant-run/dex/slice-slice_4-classes.dex", dex file "/data/data/com.example.shahzeb.testingndk/files/instant-run/dex/slice-slice_3-classes.dex", dex file "/data/data/com.example.shahzeb.testingndk/files/instant-run/dex/slice-slice_2-classes.dex", dex file "/data/data/com.example.shahzeb.testingndk/files/instant-run/dex/slice-slice_1-classes.dex", dex file "/data/data/com.example.shahzeb.testingndk/files/instant-run/dex/slice-slice_0-classes.dex", dex file "/data/data/com.example.shahzeb.testingndk/files/instant-run/dex/slice-internal_impl-24.2.1_c5ce2ccc24f48fdeeaa83795c4a9965b3b0000bd-classes.dex", dex file "/data/data/com.example.shahzeb.testingndk/files/instant-run/dex/slice-internal_impl-24.2.1_9180b436d4d87e2a23c5c519d7114d01fff80862-classes.dex", dex file "/data/data/com.example.shahzeb.testingndk/files/instant-run/dex/slice-internal_impl-24.2.1_758040e3c9887b663eba33123666f0d3d8eb7843-classes.dex", dex file "/data/data/com.example.shahzeb.testingndk/files/instant-run/dex/slice-internal_impl-24.2.1_756c53f48345dbb2e71bd2438ac9f2c3ae9d1134-classes.dex", dex file "/data/data/com.example.shahzeb.testingndk/files/instant-run/dex/slice-internal_impl-24.2.1_62ee59c260ed6ea416c5d3215fa59796bfc5182d-classes.dex", dex file "/data/data/com.example.shahzeb.testingndk/files/instant-run/dex/slice-com.android.support-support-vector-drawable-24.2.1_d52f38f279dcae00c9d3cbbeafe8ac633a0ecca4-classes.dex", dex file "/data/data/com.example.shahzeb.testingndk/files/instant-run/dex/slice-com.android.support-support-v4-24.2.1_d95c4ed9fe44ddeb9a8a8aae5e16887920d4daf8-classes.dex", dex file "/data/data/com.example.shahzeb.testingndk/files/instant-run/dex/slice-com.android.support-support-media-compat-24.2.1_9fa2c3bc1a23639dc03b19b5edb12c0d69de4a65-classes.dex", dex file "/data/data/com.example.shahzeb.testingndk/files/instant-run/dex/slice-com.android.support-support-fragment-24.2.1_5761e83f1e521bc942c5fda0d5d1732e153d7fc2-classes.dex", dex file "/data/data/com.example.shahzeb.testingndk/files/instant-run/dex/slice-com.android.support-support-core-utils-24.2.1_a2346acb90d9291006f5de9a4c03663e9a37e36b-classes.dex", dex file "/data/data/com.example.shahzeb.testingndk/files/instant-run/dex/slice-com.android.support-support-core-ui-24.2.1_fb6dfb901874f3fff658664f859ae460d253e846-classes.dex", dex file "/data/data/com.example.shahzeb.testingndk/files/instant-run/dex/slice-com.android.support-support-compat-24.2.1_b0964989f1de3db4f3e423aa1bea8410573c9efe-classes.dex", dex file "/data/data/com.example.shahzeb.testingndk/files/instant-run/dex/slice-com.android.support-appcompat-v7-24.2.1_4842b08591f3514a767dfa2e4af7ee994ac6115e-classes.dex", dex file "/data/data/com.example.shahzeb.testingndk/files/instant-run/dex/slice-com.android.support-animated-vector-drawable-24.2.1_889e0b48597230c226324f209f1b26d855496bb4-classes.dex"],nativeLibraryDirectories=[/data/app/com.example.shahzeb.testingndk-2/lib/arm, /vendor/lib, /system/lib]]] couldn't find "libhomography.so"
java.lang.UnsatisfiedLinkError: No implementation found for void com.example.testingndk.MainActivity.runDemo() (tried Java_com_example_testingndk_MainActivity_runDemo and Java_com_example_testingndk_MainActivity_runDemo__)
at com.example.testingndk.MainActivity.runDemo(Native Method)
at com.example.testingndk.MainActivity.onCreate(MainActivity.java:34)
at android.app.Activity.performCreate(Activity.java:6251)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1107)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2369)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2476)
at android.app.ActivityThread.-wrap11(ActivityThread.java)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1344)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:148)
at android.app.ActivityThread.main(ActivityThread.java:5417)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)
我已经检查了我的包和方法名称,它们是相同的。 Android.mk 中一定有我遗漏的东西。完整的源代码如下。
Android.mk
LOCAL_PATH := $(call my-dir)
OPENCV_PATH := C:/OpenCV-2.4.10-android-sdk/sdk/native/jni
include $(CLEAR_VARS)
OPENCV_INSTALL_MODULES := on
OPENCV_CAMERA_MODULES := off
include $(OPENCV_PATH)/OpenCV.mk
LOCAL_C_INCLUDES := \
$(LOCAL_PATH) \
$(OPENCV_PATH)/include
LOCAL_SRC_FILES := \
demo.cpp \
nonfree_init.cpp \
sift.cpp \
surf.cpp
LOCAL_MODULE := homography
LOCAL_CFLAGS := -Werror -O3 -ffast-math
LOCAL_LDLIBS := -llog -ldl
include $(BUILD_SHARED_LIBRARY)
演示.cpp
#include <jni.h>
#include <string.h>
#include <stdio.h>
#include <android/log.h>
#include "opencv2/core/core.hpp"
#include "opencv2/features2d/features2d.hpp"
#include "opencv2/highgui/highgui.hpp"
#include "opencv2/calib3d/calib3d.hpp"
#include "opencv2/nonfree/nonfree.hpp"
using namespace cv;
#define LOG_TAG "nonfree_jni_demo"
#define LOGI(...) __android_log_print(ANDROID_LOG_INFO,LOG_TAG,__VA_ARGS__)
typedef unsigned char uchar;
void run_demo();
void run_demo()
{
Mat img_object = imread( "/sdcard/DCIM/Camera/test1.jpg", CV_LOAD_IMAGE_GRAYSCALE );
Mat img_scene = imread( "/sdcard/DCIM/Camera/test2.jpg", CV_LOAD_IMAGE_GRAYSCALE );
if( !img_object.data || !img_scene.data ) {
// std::cout<< " --(!) Error reading images " << std::endl;
LOGI("Could not open or find the image!\n");
}
//-- Step 1: Detect the keypoints using SURF Detector
int minHessian = 400;
SurfFeatureDetector detector( minHessian );
std::vector<KeyPoint> keypoints_object, keypoints_scene;
detector.detect( img_object, keypoints_object );
detector.detect( img_scene, keypoints_scene );
//-- Step 2: Calculate descriptors (feature vectors)
SurfDescriptorExtractor extractor;
Mat descriptors_object, descriptors_scene;
extractor.compute( img_object, keypoints_object, descriptors_object );
extractor.compute( img_scene, keypoints_scene, descriptors_scene );
//-- Step 3: Matching descriptor vectors using FLANN matcher
FlannBasedMatcher matcher;
std::vector< DMatch > matches;
matcher.match( descriptors_object, descriptors_scene, matches );
double max_dist = 0; double min_dist = 100;
//-- Quick calculation of max and min distances between keypoints
for( int i = 0; i < descriptors_object.rows; i++ )
{ double dist = matches[i].distance;
if( dist < min_dist ) min_dist = dist;
if( dist > max_dist ) max_dist = dist;
}
// printf("-- Max dist : %f \n", max_dist );
// printf("-- Min dist : %f \n", min_dist );
//-- Draw only "good" matches (i.e. whose distance is less than 3*min_dist )
std::vector< DMatch > good_matches;
for( int i = 0; i < descriptors_object.rows; i++ )
{ if( matches[i].distance < 3*min_dist )
{ good_matches.push_back( matches[i]); }
}
Mat img_matches;
drawMatches( img_object, keypoints_object, img_scene, keypoints_scene,
good_matches, img_matches, Scalar::all(-1), Scalar::all(-1),
vector<char>(), DrawMatchesFlags::NOT_DRAW_SINGLE_POINTS );
//-- Localize the object
std::vector<Point2f> obj;
std::vector<Point2f> scene;
for( int i = 0; i < good_matches.size(); i++ )
{
//-- Get the keypoints from the good matches
obj.push_back( keypoints_object[ good_matches[i].queryIdx ].pt );
scene.push_back( keypoints_scene[ good_matches[i].trainIdx ].pt );
}
Mat H = findHomography( obj, scene, CV_RANSAC );
//-- Get the corners from the image_1 ( the object to be "detected" )
std::vector<Point2f> obj_corners(4);
obj_corners[0] = cvPoint(0,0); obj_corners[1] = cvPoint( img_object.cols, 0 );
obj_corners[2] = cvPoint( img_object.cols, img_object.rows ); obj_corners[3] = cvPoint( 0, img_object.rows );
std::vector<Point2f> scene_corners(4);
perspectiveTransform( obj_corners, scene_corners, H);
//-- Draw lines between the corners (the mapped object in the scene - image_2 )
line( img_matches, scene_corners[0] + Point2f( img_object.cols, 0), scene_corners[1] + Point2f( img_object.cols, 0), Scalar(0, 255, 0), 4 );
line( img_matches, scene_corners[1] + Point2f( img_object.cols, 0), scene_corners[2] + Point2f( img_object.cols, 0), Scalar( 0, 255, 0), 4 );
line( img_matches, scene_corners[2] + Point2f( img_object.cols, 0), scene_corners[3] + Point2f( img_object.cols, 0), Scalar( 0, 255, 0), 4 );
line( img_matches, scene_corners[3] + Point2f( img_object.cols, 0), scene_corners[0] + Point2f( img_object.cols, 0), Scalar( 0, 255, 0), 4 );
//-- Show detected matches
imshow( "Good Matches & Object detection", img_matches );
waitKey(0);
}
void readme();
/** @function readme */
void readme(){
// std::cout << " Usage: ./SURF_descriptor <img1> <img2>" << std::endl;
LOGI(" Usage: ./SURF_descriptor <img1> <img2>\n");
}
extern "C" {
JNIEXPORT void JNICALL Java_com_example_testingndk_MainActivity_runDemo(JNIEnv * env, jobject obj);
};
JNIEXPORT void JNICALL Java_com_example_testingndk_MainActivity_runDemo(JNIEnv * env, jobject obj)
{
LOGI( "Start run_demo! \n");
run_demo();
LOGI( "End run_demo!\n");
}
MainActivity.java
package com.example.testingndk;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.util.Log;
public class MainActivity extends AppCompatActivity {
static
{
try
{
// Load necessary libraries.
System.loadLibrary("homography");
}
catch( UnsatisfiedLinkError e )
{
System.err.println("Native code library failed to load.\n" + e);
}
}
public static native void runDemo();
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Log.v("nonfree_jni_demo", "start runDemo");
// Call the JNI interface
runDemo();
}
}
最佳答案
@uelordi 感谢您的支持。
我把jni文件夹放在项目目录的根目录下,所以在用ndk-build
编译后,我复制了生成的*.so
libs 文件夹中的文件(在同一目录中编译后生成)到 myapp/src/main/jniLibs,我现在可以运行 OpenCV 代码。我希望它可以帮助某人。
关于android - Features2D + Homography OpenCV 链接错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40124649/
我想问一个我已经在 OpenCV 板上问过但没有得到答案的问题:http://answers.opencv.org/question/189206/questions-about-the-fundam
我正在使用OpenCV在Android上创建应用程序,并且需要Feature2d和Homography的Java代码。我需要像视频一样连续处理。我不是C++专家,所以无法移植。因此,如果可以的话,请提
我有两张相同的图片,但第二张变形了并且尺寸不同。我希望能够在第一张图片上选择一个点并在第二张图片上找到完全相同的点。图片的同步将在每张图片上进行4个点。 例子: 正常图片 图片失真 结果将是一个函数,
我正在尝试使用 SurfFeatureDetect 和 FLANN 匹配器检测对象。但是,代码无法准确检测图像。我还以图片格式发布了结果。 这是我在 opencv 教程中的代码 website int
我尝试做 this ,我发现 this 。他的问题不是我想问的,但我想做同样的事情。我可以在图像上找到特征并绘制特征描述符,但是对象周围的边界框很奇怪。抱歉,我不能在这里发布我的结果,出来的线不是矩形
引用this回答this question : What is happening is that you're considering all the keypoints detected in t
当我使用函数 cvFindHomograhpy() 获取结果时遇到问题。 它给出负坐标的结果,我现在将解释我在做什么。 我正在使用光流法进行视频稳定。我已经估计了第一帧和第二帧中特征的位置。现在,我的
我正在处理由 OpenCV 计算的单应性。我目前使用这个单应性来使用下面的函数来转换点。此函数执行我需要的任务,但我不知道它实际上是如何工作的。 谁能逐行准确地解释最后 3 行代码背后的逻辑/理论,我
我正在尝试计算视频的两个连续帧之间的比例、旋转和平移。所以基本上我匹配了关键点,然后使用 opencv 函数 findHomography() 来计算单应矩阵。 homography = findHo
我在将检测到的对象的轮廓放在正确位置时遇到了一些问题,就好像坐标在错误的位置一样。我将 hessian 设置为 2000,并且过滤了小于最小距离 3 倍的匹配项。任何帮助,将不胜感激。 运行匹配和单应
我一直在尝试编译this Android Studio 2.2 中的源代码,使用 Android NDK、OpenCV-2.4.10 和 OpenCV-2.4.10-android-sdk。我已经能够
在我的 Python/OpenCV 代码中,我使用随机单应性来模拟视点变化(我正在评估兴趣点检测器并希望避免搜索图像对)。 是否可以计算对极线和一幅图像及其扭曲版本之间的基本矩阵?我拥有的唯一信息是我
对不起,如果这听起来很愚蠢,但我真的需要问这个问题。 一旦计算出单应性,我能否使用它来将在一台相机中检测到的物体中心的二维坐标作为二维坐标投影到另一台立体相机? 最佳答案 一旦您拥有映射两个相机之间转
我有两张图片(A 和 B),一张与另一张略有扭曲,它们之间存在平移、旋转和比例差异(例如,这些图片:) Ssoooooooo 我需要在图片 B 中应用一种变换,以便补偿存在的失真/平移/旋转,使两张图
我正在使用光流来跟踪一些功能,我是初学者,必须遵循这些步骤 匹配良好的特征进行跟踪 对它们进行 Lucas-Kanade 算法 查找第一帧和当前帧之间的单应性 进行相机校准 分解单应图 现在我不明白的
我正在使用光流来跟踪一些功能,我是初学者,必须遵循这些步骤 匹配良好的特征进行跟踪 对它们进行 Lucas-Kanade 算法 查找第一帧和当前帧之间的单应性 进行相机校准 分解单应图 现在我不明白的
库:OpenCV目标:Android (OpenCV4Android) 我尝试计算世界平面(例如监视器屏幕)的单应性以获得相机姿势,对其进行变换并将点重新投影回以用于跟踪任务。我正在使用 OpenCV
使用 JavaCV。我在 ArrayList 中有 2 组 CvPoint2D32f 点,一组来自手机的图像采集器,另一组来自恒定的已知图像源。 我想应用 cvFindHomogrpahy() 方法,
我正在尝试通过 python 使用 opencv 在火车图像中查找多个对象,并将其与从查询图像中检测到的关键点进行匹配。对于我的情况,我正在尝试检测下面提供的图像中的网球场.我看了网上的教程,发现只能
我正在使用 Opencv python 接口(interface)并获得了单应矩阵 H。它似乎工作正常,因为我可以使用扭曲透视从源图像中获取扭曲图像。我现在尝试使用 H 和 Inverse H 在两个
我是一名优秀的程序员,十分优秀!