我正在尝试为我的android项目使用生猪功能,其中包括使用以下代码使用来自android手机的图像进行人员检测:
hog = new HOGDescriptor();
hog.setSVMDetector(HOGDescriptor.getDefaultPeopleDetector());
img = new Mat();
Utils.bitmapToMat(bitmap32, img);
img2 = new Mat();
img2.convertTo(img, CvType.CV_8U);
MatOfRect found = new MatOfRect();
MatOfDouble foundDouble = new MatOfDouble();
//this line returns the error
hog.detectMultiScale(img2, found, foundDouble, 0, new Size(8,8), new Size(32,32), 1.05, 2 );
这些行给了我这些错误:
java.lang.RuntimeException: Failure delivering result ResultInfo{who=null, request=65536, result=-1, data=Intent { act=inline-data (has extras) }} to activity {com.example.han.xvit/com.example.han.xvit.home_activity}: CvException [org.opencv.core.CvException: cv::Exception: OpenCV(4.1.0) /build/master_pack-android/opencv/modules/objdetect/src/hog.cpp:243: error: (-215:Assertion failed) !img.empty() in function 'computeGradient'
]
at android.app.ActivityThread.deliverResults(ActivityThread.java:4179)
at android.app.ActivityThread.handleSendResult(ActivityThread.java:4222)
at android.app.ActivityThread.-wrap20(ActivityThread.java)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1581)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:163)
at android.app.ActivityThread.main(ActivityThread.java:6238)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:904)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:794)
Caused by: CvException [org.opencv.core.CvException: cv::Exception: OpenCV(4.1.0) /build/master_pack-android/opencv/modules/objdetect/src/hog.cpp:243: error: (-215:Assertion failed) !img.empty() in function 'computeGradient'
]
at org.opencv.objdetect.HOGDescriptor.detectMultiScale_1(Native Method)
at org.opencv.objdetect.HOGDescriptor.detectMultiScale(HOGDescriptor.java:393)
at com.example.han.xvit.HomeFragment.onActivityResult(HomeFragment.java:156)
at android.support.v4.app.FragmentActivity.onActivityResult(FragmentActivity.java:160)
at android.app.Activity.dispatchActivityResult(Activity.java:7132)
at android.app.ActivityThread.deliverResults(ActivityThread.java:4175)
... 9 more
如您所见,应用程序返回-1结果,并且错误-215断言失败,可能是由于未找到图像数据所致。
NB:
位图图像数据应该没有问题,因为我可以在另一个代码中使用的imageView中显示它
感谢您的帮助!
编辑:我正在使用这些作为参考 peopledetection1