简体   繁体   English

在C ++中调用霍夫变换时出现OpenCV未指定错误

[英]OpenCV Unspecified error when calling Hough transform in c++

I'm working on a music recognition Android app, which should recognize music annotations in sheet in real time using camera. 我正在开发一个音乐识别Android应用,该应用应使用相机实时识别工作表中的音乐注释。

When I try to recognize lines or circles using Hough transform (either HoughCircles or HoughLinesP), I get the Unspecified error: 当我尝试使用霍夫变换(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)

I could try another version of OpenCV, but I don't have enough time to change everything. 我可以尝试其他版本的OpenCV,但是我没有足够的时间来更改所有内容。 I'm also not skilled with OpenCV, this is the first time I'm using it. 我也不熟悉OpenCV,这是我第一次使用它。 Maybe the problem is in c++ file or header. 也许问题出在c ++文件或标头中。

C++ file: 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;

}

Header file: 头文件:

#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

It's highly possible that there's something wrong with the code, since I'm not entirely sure how the Hough transform works, so I tried to use some implementations that I found online. 由于我不确定Hough转换的工作原理,因此代码很可能出了点问题,因此我尝试使用一些在网上找到的实现。

I'd really appreciated any help. 我真的很感谢您的帮助。

I found out that I'm stupid. 我发现自己很傻。 I didn't know that this implementation is for Desktop purposes, and I was trying to use it on Android. 我不知道此实现是否用于桌面,并且我试图在Android上使用它。 I should really read all the docs in the library I'm using. 我应该真正阅读正在使用的库中的所有文档。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM