qq_41517828 2018-10-16 01:46 采纳率: 25.9%
浏览 337

opencv相关问题,这段简单代码为啥会报错啊?

代码如下:
#include
#include
using namespace std;
using namespace cv;
vector HoughCirlesSearch(Mat image);

int main() {
Mat A1 = imread("C://Users//颜俊毅//Desktop//答题卡填涂.jpg");
Mat A2(800, 800, A1.depth(),A1.channels());
resize(A1, A2,A2.size(),0,0);
imshow("归一化", A2);
cout<<HoughCirlesSearch(A2);
waitKey(0);
return 0;
}

vector HoughCirlesSearch(Mat image)
{
//找出图片的中心
Mat grayImage, dstImage, thresholdImage, GaussianImage;
int centerhingh = image.cols / 2;
int centerwidth = image.rows / 2;

cvtColor(image, grayImage, CV_BGR2GRAY);        //灰度化
threshold(grayImage, thresholdImage, 40, 255, THRESH_BINARY);   //二值化
GaussianBlur(grayImage, GaussianImage, Size(9, 9), 2, 2);       //高斯模糊使图像变平滑
                                                            //imshow("预处理", grayImage);

image.copyTo(dstImage);
//创建圆的集合
vector<Vec3f>circles;
//霍夫圆检测
HoughCircles(GaussianImage, circles, CV_HOUGH_GRADIENT, 1, 100, 100, 20, 10, 50);
vector<Point2f> top, bot, result;
for (size_t i = 0; i < circles.size(); i++)
{
    Point2f centerCircles(round(circles[i][0]), round(circles[i][1]));

    int radius = (int)round(circles[i][2]);

    circle(dstImage, centerCircles, 3, Scalar(0, 255, 0), -1, 4, 0);
    circle(dstImage, centerCircles, radius, Scalar(0, 0, 255), 3, 4, 0);

    if (centerCircles.y < centerhingh)
    {
        top.push_back(centerCircles);
    }
    else
    {
        bot.push_back(centerCircles);
    }
    //cout << centerCircles << endl << endl;

}

cout << top[0] << endl << endl;
cout << top[1] << endl << endl;
cout << bot[0] << endl << endl;
cout << bot[1] << endl << endl;
cout << "-------------" << endl << endl;

Point2f topleft = top[0].x > top[1].x ? top[1] : top[0];
Point2f topright = top[0].x > top[1].x ? top[0] : top[1];
Point2f botleft = bot[0].x > bot[1].x ? bot[1] : bot[0];
Point2f botright = bot[0].x > bot[1].x ? bot[0] : bot[1];

result.push_back(topleft);
result.push_back(topright);
result.push_back(botleft);
result.push_back(botright);

cout << topleft << endl << endl;
cout << topright << endl << endl;
cout << botleft << endl << endl;
cout << botright << endl << endl;
cout << "-------------" << endl << endl;

//imshow("检测后", dstImage);

return result;

}

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 #MATLAB仿真#车辆换道路径规划
    • ¥15 java 操作 elasticsearch 8.1 实现 索引的重建
    • ¥15 数据可视化Python
    • ¥15 要给毕业设计添加扫码登录的功能!!有偿
    • ¥15 kafka 分区副本增加会导致消息丢失或者不可用吗?
    • ¥15 微信公众号自制会员卡没有收款渠道啊
    • ¥100 Jenkins自动化部署—悬赏100元
    • ¥15 关于#python#的问题:求帮写python代码
    • ¥20 MATLAB画图图形出现上下震荡的线条
    • ¥15 关于#windows#的问题:怎么用WIN 11系统的电脑 克隆WIN NT3.51-4.0系统的硬盘