android - Failure on warpPerspective -


i comparing 2 images using findhomography(). have added modules opencv_contrib in opencv 3.1.0 use surf , sift algorithms , compile latest android architectures. can compile libraries using ndk-build.

problem:

while detecting object in scene , computing warpperspective, following exception thrown on images:

11-10 20:47:30.990 10503-11056/ e/cv::error(): opencv error: assertion failed ((m0.type() == cv_32f || m0.type() == cv_64f) && m0.rows == 3 && m0.cols == 3) in void cv::warpperspective(cv::inputarray, cv::outputarray, cv::inputarray, cv::size, int, int, const scalar&), file /volumes/linux/builds/master_pack-android/opencv/modules/imgproc/src/imgwarp.cpp, line 6120     --------- beginning of crash     11-10 20:47:31.020 10503-11056/ a/libc: fatal signal 6 (sigabrt), code -6 in tid 11056 (thread-31509)     11-10 20:47:31.122 200-200/? a/debug: *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** ***     11-10 20:47:31.122 200-200/? a/debug: build fingerprint: 'google/hammerhead/hammerhead:6.0.1/m4b30x/3237893:user/release-keys'     11-10 20:47:31.122 200-200/? a/debug: revision: '11'     11-10 20:47:31.122 200-200/? a/debug: abi: 'arm'     11-10 20:47:31.122 200-200/? a/debug: pid: 10503, tid: 11056, name: thread-31509  >>>  <<<     11-10 20:47:31.122 200-200/? a/debug: signal 6 (sigabrt), code -6 (si_tkill), fault addr --------     11-10 20:47:31.149 200-200/? a/debug:     r0 00000000  r1 00002b30  r2 00000006  r3 926e0978     11-10 20:47:31.149 200-200/? a/debug:     r4 926e0980  r5 926e0930  r6 00000000  r7 0000010c     11-10 20:47:31.149 200-200/? a/debug:     r8 00000047  r9 00000001  sl 00000050  fp 00000001     11-10 20:47:31.149 200-200/? a/debug:     ip 00000006  sp 926cfc48  lr b6d4fb61  pc b6d51f50  cpsr 400f0010     11-10 20:47:31.174 200-200/? a/debug: backtrace:     11-10 20:47:31.174 200-200/? a/debug:     #00 pc 00041f50  /system/lib/libc.so (tgkill+12)     11-10 20:47:31.174 200-200/? a/debug:     #01 pc 0003fb5d  /system/lib/libc.so (pthread_kill+32)     11-10 20:47:31.174 200-200/? a/debug:     #02 pc 0001c30f  /system/lib/libc.so (raise+10)     11-10 20:47:31.174 200-200/? a/debug:     #03 pc 000194c1  /system/lib/libc.so (__libc_android_abort+34)     11-10 20:47:31.174 200-200/? a/debug:     #04 pc 000174ac  /system/lib/libc.so (abort+4)     11-10 20:47:31.174 200-200/? a/debug:     #05 pc 00666958  /data/app/-2/lib/arm/libopencv_java3.so (_zn9__gnu_cxx27__verbose_terminate_handlerev+344)     11-10 20:47:31.175 200-200/? a/debug:     #06 pc 0063d7b0  /data/app/-2/lib/arm/libopencv_java3.so (_zn10__cxxabiv111__terminateepfvve+4)     11-10 20:47:31.175 200-200/? a/debug:     #07 pc 0063d7f0  /data/app/-2/lib/arm/libopencv_java3.so (_zst9terminatev+16)     11-10 20:47:31.175 200-200/? a/debug:     #08 pc 0063d1cc  /data/app/-2/lib/arm/libopencv_java3.so (__cxa_throw+168)     11-10 20:47:31.175 200-200/? a/debug:     #09 pc 001e477d  /data/app/-2/lib/arm/libopencv_java3.so (_zn2cv5errorerkns_9exceptione+244)     11-10 20:47:31.175 200-200/? a/debug:     #10 pc 001e48bd  /data/app/-2/lib/arm/libopencv_java3.so (_zn2cv5erroreirkns_6stringepkcs4_i+108)     11-10 20:47:31.175 200-200/? a/debug:     #11 pc 002ca5fd  /data/app/-2/lib/arm/libopencv_java3.so (_zn2cv15warpperspectiveerkns_11_inputarrayerkns_12_outputarrayes2_ns_5size_iieeiirkns_7scalar_idee+356)     11-10 20:47:31.175 200-200/? a/debug:     #12 pc 00007375  /data/app/-2/lib/arm/libnonfree.so (_z15detect_featuresp7_jnienvp8_jstrings2_i+2844)     11-10 20:47:31.175 200-200/? a/debug:     #13 pc 022bfd23  /data/app/-2/oat/arm/base.odex (offset 0x13ce000) (boolean .nonfreejnilib.detectfeatures(java.lang.string, java.lang.string, int)+126)     11-10 20:47:31.176 200-200/? a/debug:     #14 pc 0258c149  /data/app/-2/oat/arm/base.odex (offset 0x13ce000) (void .tasks.addetectionasynctask$1.run()+292)     11-10 20:47:31.176 200-200/? a/debug:     #15 pc 71c99c67  /data/dalvik-cache/arm/system@framework@boot.oat (offset 0x1ed6000) 

code:

#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/xfeatures2d/nonfree.hpp" #include "opencv2/opencv.hpp"  using namespace std; using namespace cv;  #define  log_tag    "nonfree_jni" #define  logi(...)  __android_log_print(android_log_info,log_tag,__va_args__)  jboolean detect_features(jnienv * env, jstring scenepath, jstring objectpath) {      const char *nativescenepath = (env)->getstringutfchars(scenepath, null);     const char *nativeobjectpath = (env)->getstringutfchars(objectpath, null);      nativescenepath = env->getstringutfchars(scenepath, 0);     nativeobjectpath = env->getstringutfchars(objectpath, 0);      (env)->releasestringutfchars(scenepath, nativescenepath);     (env)->releasestringutfchars(objectpath, nativeobjectpath);      __android_log_print(android_log_verbose, log_tag, "object path: ----- %s \n", nativeobjectpath);     __android_log_print(android_log_verbose, log_tag, "scene path: ----- %s \n", nativescenepath);      mat img_object = imread( nativeobjectpath, cv_load_image_grayscale );     mat img_scene = imread( nativescenepath, cv_load_image_grayscale );       if( !img_object.data || !img_scene.data){         logi(" --(!) error reading images ");         return false;     }          //-- step 1: detect keypoints using surf detector         int minhessian = 400;      __android_log_print(android_log_verbose, log_tag, "image comparison rows: ----- %d \n", img_object.rows);     __android_log_print(android_log_verbose, log_tag, "image comparison colums: ----- %d \n", img_object.cols);  //        cv::xfeatures2d::surffeaturedetector detector( minhessian );         ptr<cv::xfeatures2d::surffeaturedetector> detector = cv::xfeatures2d::surffeaturedetector::create(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) //        cv::xfeatures2d::surfdescriptorextractor extractor;         ptr<cv::xfeatures2d::surfdescriptorextractor> extractor = cv::xfeatures2d::surfdescriptorextractor::create();          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 , min distances between keypoints         for( int = 0; < descriptors_object.rows; i++ )         {             double dist = matches[i].distance;             if (dist == 0) continue;             if( dist < min_dist ) min_dist = dist;             if( dist > max_dist ) max_dist = dist;         }          __android_log_print(android_log_verbose, log_tag, "-- max dist : %f \n", max_dist);         __android_log_print(android_log_verbose, log_tag, "-- min dist : %f \n", min_dist);          //-- draw "good" matches (i.e. distance less 3*min_dist )         std::vector< dmatch > good_matches;          for( int = 0; < descriptors_object.rows; i++ )         {             if( matches[i].distance <= 0.1 ) //3*min_dist             {                 good_matches.push_back( matches[i]);             }         }          __android_log_print(android_log_verbose, log_tag, "flann total matches -----: %zu \n", matches.size());         __android_log_print(android_log_verbose, log_tag, "flann matches -----: %zu \n", good_matches.size());          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 object         std::vector<point2f> obj;         std::vector<point2f> scene;          for( int = 0; < good_matches.size(); i++ )         {             //-- keypoints matches             obj.push_back( keypoints_object[ good_matches[i].queryidx ].pt );             scene.push_back( keypoints_scene[ good_matches[i].trainidx ].pt );         }          if (good_matches.size() >= 5)         {             mat h = findhomography( obj, scene, cv_ransac );              //-- corners image_1 ( object "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);              mat output, matrix;              warpperspective(img_object, output, h, { img_scene.cols, img_scene.rows });              ////////////////////////////////////////////////////////////////////////////////              detector->detect( output, keypoints_object );              //-- step 2: calculate descriptors (feature vectors)             //cv::xfeatures2d::surfdescriptorextractor extractor;             ptr<cv::xfeatures2d::surfdescriptorextractor> extractor = cv::xfeatures2d::surfdescriptorextractor::create();              extractor->compute( output, keypoints_object, descriptors_object );             extractor->compute( img_scene, keypoints_scene, descriptors_scene );              std::vector<std::vector<cv::dmatch>> matches2;             bfmatcher matcher;             matcher.knnmatch(descriptors_object, descriptors_scene, matches2, 2);             vector<cv::dmatch> good_matches2;              (int = 0; < matches2.size(); ++i)             {                 const float ratio = 0.8; // in lowe's paper; can tuned                 if (matches2[i][0].distance < ratio * matches2[i][1].distance)                 {                     good_matches2.push_back(matches2[i][0]);                 }             }              if (matches2.size() == 0 || good_matches2.size() == 0) {             logi( "end run!\n");                 return false;             }              double ratioofsimilarity =  static_cast<double>(good_matches2.size()) / static_cast<double>(matches2.size());              __android_log_print(android_log_verbose, log_tag, "bruteforce total matches -----: %zu \n", matches2.size());             __android_log_print(android_log_verbose, log_tag, "bruteforce matches -----: %zu \n", good_matches2.size());             __android_log_print(android_log_verbose, log_tag, "bruteforce similarity ratio -----: %f \n", ratioofsimilarity);              if(ratioofsimilarity >= 0.3) {             logi( "end run!\n");                 return true;             }              logi( "end run!\n");             return false;          }         logi( "end run!\n");         return false; } 

what can issue?

well, kept me in pain many days , don't want others go through it.

here problem:

cv::findhomography() function return empty homography matrix (0 cols x 0 rows) starting approximately 2.4.5 release. according opinion seems happen when cv::ransac flag passed.

reference


Comments

Popular posts from this blog

aws api gateway - SerializationException in posting new Records via Dynamodb Proxy Service in API -

asp.net - Problems sending emails from forum -