![](/img/trans.png)
[英]OpenCV android : Hough transform rectangle recognition with image with multiple different sized rectangles
[英]OpenCV Unspecified error when calling Hough transform in c++
我正在開發一個音樂識別Android應用,該應用應使用相機實時識別工作表中的音樂注釋。
當我嘗試使用霍夫變換(HoughCircles或HoughLinesP)識別直線或圓時,出現未指定的錯誤:
E/cv::error(): OpenCV Error: Unspecified error (The function is not implemented. Rebuild the library with Windows, GTK+ 2.x or Carbon support. If you are on Ubuntu or Debian, install libgtk2.0-dev and pkg-config, then re-run cmake or configure script) in cvWaitKey, file /hdd2/buildbot/slaves/slave_ardbeg1/50-SDK/opencv/modules/highgui/src/window.cpp, line 567
A/libc: Fatal signal 6 (SIGABRT), code -6 in tid 7772 (Thread-411)
我可以嘗試其他版本的OpenCV,但是我沒有足夠的時間來更改所有內容。 我也不熟悉OpenCV,這是我第一次使用它。 也許問題出在c ++文件或標頭中。
C ++文件:
#include "com_ryu_musicreader_OpencvClass.h"
JNIEXPORT void JNICALL Java_com_ryu_musicreader_OpencvClass_musicDetection
(JNIEnv *, jclass, jlong addrRgba){
Mat& frame = *(Mat*)addrRgba;
find_lines(frame);
find_circles(frame);
}
void find_lines(Mat& src){
Mat dst, cdst;
Canny(src, dst, 50, 200, 3);
cvtColor(dst, cdst, COLOR_GRAY2BGR);
vector<Vec4i> lines;
HoughLinesP(dst, lines, 1, CV_PI/180, 50, 50, 10 );
for( size_t i = 0; i < lines.size(); i++ )
{
Vec4i l = lines[i];
line( cdst, Point(l[0], l[1]), Point(l[2], l[3]), Scalar(0,0,255), 3, 0);
}
imshow("detected lines", cdst);
}
int find_circles(Mat& src){
Mat src_gray;
cvtColor(src, src_gray, COLOR_BGR2GRAY);
GaussianBlur( src_gray, src_gray, Size(9, 9), 2, 2 );
vector<Vec3f> circles;
HoughCircles( src_gray, circles, CV_HOUGH_GRADIENT, 1, src_gray.rows/8, 200, 100, 0, 0 );
for( size_t i = 0; i < circles.size(); i++ )
{
Point center(cvRound(circles[i][0]), cvRound(circles[i][1]));
int radius = cvRound(circles[i][2]);
circle( src, center, 3, Scalar(0,255,0), -1, 8, 0 );
circle( src, center, radius, Scalar(0,0,255), 3, 8, 0 );
}
namedWindow( "Hough Circle Transform Demo", CV_WINDOW_AUTOSIZE );
imshow( "Hough Circle Transform Demo", src );
waitKey(0);
return 0;
}
頭文件:
#include <jni.h>
#include "opencv2/opencv.hpp"
#include "opencv2/highgui/highgui.hpp"
#include "opencv2/imgproc/imgproc.hpp"
#include <iostream>
using namespace cv;
#ifndef _Included_com_ryu_musicreader_OpencvClass
#define _Included_com_ryu_musicreader_OpencvClass
#ifdef __cplusplus
extern "C" {
#endif
void detect(Mat& frame);
void find_lines(Mat& frame);
int find_circles(Mat& frame);
JNIEXPORT void JNICALL Java_com_ryu_musicreader_OpencvClass_musicDetection
(JNIEnv *, jclass, jlong);
#ifdef __cplusplus
}
#endif
#endif
由於我不確定Hough轉換的工作原理,因此代碼很可能出了點問題,因此我嘗試使用一些在網上找到的實現。
我真的很感謝您的幫助。
我發現自己很傻。 我不知道此實現是否用於桌面,並且我試圖在Android上使用它。 我應該真正閱讀正在使用的庫中的所有文檔。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.