gpt4 book ai didi

c++ - 错误信息 : no match for call to ‘(cv::Rect) (cv::Mat&, cv::Point_, cv::Point, cv::Scalar, int)’

转载 作者:太空宇宙 更新时间:2023-11-03 22:12:28 29 4
gpt4 key购买 nike

我到处都找了很多,找不到我的问题的答案。我试图从这个线程复制一个文本检测软件(Extracting text OpenCV)但是在代码的末尾有一条消息错误说没有匹配的矩形,即使我已经在上面绘制了一个并且我们进入了循环。我已经测试了所有我能想到的值,一切似乎都是正确的。

这是完整的代码;

#include <opencv2/core/core.hpp>
#include <opencv2/highgui/highgui.hpp>
#include <iostream>
#include <opencv2/imgproc/imgproc.hpp>
#include <stdio.h>
#include <stdlib.h>
#include <math.h>


using namespace cv;
using namespace std;





int main( int argc, char** argv )
{

namedWindow("source_window2",WINDOW_AUTOSIZE);
namedWindow("source_window3",WINDOW_AUTOSIZE);
Mat input = imread(argv[1], CV_LOAD_IMAGE_COLOR);
Mat in_gray = imread(argv[1],CV_LOAD_IMAGE_GRAYSCALE);
Mat gradient;

Mat Kernelellipse = getStructuringElement(MORPH_ELLIPSE, Size(3,3));
morphologyEx(in_gray, gradient, MORPH_GRADIENT, Kernelellipse);
Mat thresh;
//on convertit en binaire
threshold(gradient, thresh, 0.0, 255.0, THRESH_BINARY | THRESH_OTSU);
rectangle(input,Point(0,0),Point(50,50),Scalar(255,255,255),2);
Mat Kernelrectangle = getStructuringElement(MORPH_RECT, Size(9,1));
Mat fermee;
morphologyEx(thresh, fermee, MORPH_CLOSE, Kernelrectangle);
imshow("source_window3", fermee);

Mat noire = Mat::zeros(thresh.size(), CV_8UC1);
//on cheche les contours
vector<vector<Point> > contours;
vector<Vec4i> hierarchy;
findContours(fermee, contours, hierarchy, CV_RETR_CCOMP, CV_CHAIN_APPROX_SIMPLE, Point(0, 0));
for (int i = 0; i < contours.size(); ++i)
{
Rect rectangle = boundingRect(contours[i]);
Mat noirerectangle(noire, rectangle);
noirerectangle = Scalar(0, 0, 0);
//on les dessine
drawContours(noire, contours, i, Scalar(255, 255, 255), CV_FILLED);
double proportion_de_blanc = (double)countNonZero(noirerectangle)/(rectangle.width*rectangle.height);

if (proportion_de_blanc > 0.45 && (rectangle.height > 8 && rectangle.width > 8))
{
rectangle(input,rectangle.tl(),rectangle.br(),Scalar(0,255,0),2);
}


}
imshow("source_window2",input);





waitKey(0);
return(0);

我的问题在最后一个循环中:

    if (proportion_de_blanc > 0.45 && (rectangle.height > 8 && rectangle.width > 8))
{
rectangle(input,rectangle.tl(),rectangle.br(),Scalar(0,255,0),2);
}

最佳答案

您将其中一个矩形定义为:

Rect rectangle = boundingRect(contours[i]);

名称​​rectanglerectangle 绘图函数冲突。所以要么:

  1. 用另一个名称重命名 rectangle,例如 Rectangle rect = boundingRect(contours[i]);

  2. 调用矩形绘制方法为 cv::rectangle(input,rectangle.tl(),rectangle.br(),Scalar(0,255,0),2);

关于c++ - 错误信息 : no match for call to ‘(cv::Rect) (cv::Mat&, cv::Point_<int>, cv::Point, cv::Scalar, int)’ ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31812020/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com