我正在制作一个使用openframeworks和opencv的ios应用程序 . 我目前正在尝试使用此功能:

void HoughCircles(InputArray image,OutputArray circles,int method,double dp,double minDist,double param1 = 100,double param2 = 100,int minRadius = 0,int maxRadius = 0),其中:

  • src_gray:输入图像(灰度),8位,单通道,灰度输入图像 .

  • circles:存储3个值集的向量:x_ ,y_ ,r表示每个检测到的圆 .

  • CV_HOUGH_GRADIENT:定义检测方法 . 目前这是OpenCV中唯一可用的

  • dp = 1:分辨率的反比

  • min_dist = src_gray.rows / 8:检测到的中心之间的最小距离

  • param_1 = 200:内部Canny边缘检测器的上限阈值

  • param_2 = 100 *:中心检测的阈值 .

  • min_radius = 0:要检测的最小无线电 . 如果未知,则默认为零 .

  • max_radius = 0:要检测的最大半径 . 如果未知,则默认为零

我无法将图像格式更改为该函数可接受的像素数组 . grayImage的类型为xCvGrayscaleImage

这是我目前的代码

//prepare image
grayImage.blurGaussian();

//detect circles in image
ofPixels pixels;
pixels = grayImage.getPixels();
cv::Mat imageMat(grayImage.width, grayImage.height, CV_8UC3);
for(int i = 0; i < pixels.size(); i++){
    imageMat.push_back(pixels[i]);
    }
cv::HoughCircles(imageMat, circles, CV_HOUGH_GRADIENT, 1, grayImage.height/8, 200, 100, 5, 30);

程序构建正常,但是当我运行该页面时,它崩溃并返回以下错误:OpenCV错误:断言失败(DataType <_Tp> :: type == type()&& cols == 1)在push_back,file .. /../../addons/ofxOpenCv/libs/opencv/include/opencv2/core/mat.hpp,第690行libc abi.dylib:以类型cv :: Exception:../../的未捕获异常终止 . ./addons/ofxOpenCv/libs/opencv/include/opencv2/core/mat.hpp:690:错误:(-215)DataType <_Tp> :: type == type()&& cols == 1 in function push_back

有关如何处理ofxCvGrayscaleImage的任何建议?

UPDATE: the answer was just cv::Mat imgMat = grayImage.getCvImage()