超越nb
2021-07-23 16:55
采纳率: 62.5%
浏览 39

C++图象识别 Mat rect opencv

if (llRealHandle_1 >= 0)
{
const char *img_path = "img1.bmp";
//获取图像原始数据并保存至数组
bool ret1 = NET_DVR_CapturePictureBlock(llRealHandle_1, img_path, 1);

    //识别并给出坐标偏差量
    //先截取图像有效探测区域
    if (ret1 == true)
    {
        Mat img_temp = imread(img_path, IMREAD_UNCHANGED);
        //………………

        Mat img_act = img_temp(rect);
        //识别并画出偏移结果
        Mat img_trans;
        cvtColor(img_act, img_trans, CV_BGR2GRAY);
        threshold(img_trans, img_trans, 150, threshold_value, CV_THRESH_OTSU);
        //Mat element_close = getStructuringElement(MORPH_RECT, Size(3, 3));
        Mat element = getStructuringElement(MORPH_RECT, Size(15, 15));
        Mat open;
        //顶帽操作  
        //morphologyEx(img_trans, close, MORPH_CLOSE, element_close);
        morphologyEx(img_trans, open, MORPH_OPEN, element);
        point1=Draw_Point(open, IDC_STATIC_PIC);
        //画背景坐标,PIC1
        Draw_Background(IDC_STATIC_PIC);
    }
    
}

为什么这个
Mat img_act = img_temp(rect);,去掉了(rect),Mat img_act = img_temp;就能识别

  • 收藏

2条回答 默认 最新

  • bostonAlen 2021-07-23 17:07
    已采纳

    rect是什么,你这段代码没定义这个变量,而且mat没有直接用rect构造的构造函数吧。

    (1) Mat::Mat() (2) Mat::Mat(int rows, int cols, int type)
    (3) Mat::Mat(Size size, int type)
    (4) Mat::Mat(int rows, int cols, int type, constScalar& s)
    (5) Mat::Mat(Size size, int type, constScalar& s)
    (6) Mat::Mat(const Mat& m)
    (7) Mat::Mat(int rows, int cols, int type, void* data, size_t step=AUTO_STEP)
    (8) Mat::Mat(Size size, int type, void* data, size_t step=AUTO_STEP)
    (9) Mat::Mat(const Mat& m, const Range& rowRange, const Range& colRange)
    (10) Mat::Mat(const Mat& m, const Rect& roi)
    (11) Mat::Mat(const CvMat* m, bool copyData=false)
    (12) Mat::Mat(const IplImage* img, bool copyData=false)
    (13) template<typename T, int n> explicit Mat::Mat(const Vec<T, n>& vec, bool copyData=true)
    (14) template<typename T, int m, int n> explicit Mat::Mat(const Matx<T, m, n>& vec, bool copyData=true)
    (15) template<typename T> explicit Mat::Mat(const vector<T>& vec, bool copyData=false)
    (16) Mat::Mat(const MatExpr& expr)
    (17) Mat::Mat(int ndims, const int* sizes, int type)
    (18) Mat::Mat(int ndims, const int* sizes, int type, constScalar& s)
    (19) Mat::Mat(int ndims, const int* sizes, int type, void* data, const size_t* steps=0)
    (20) Mat::Mat(const Mat& m, const Range* ranges)
    
    已采纳该答案
    打赏 评论
  • 超越nb 2021-07-25 10:50

    void CwebCamCheckDlg::Find_Circle_bias()
    {
    POINT bias_cor = { 0,0 };
    POINT point1 = { Img_Width_act / 2,Img_Height_act / 2 };
    POINT point2 = { Img_Width_act / 2,Img_Height_act / 2 };
    POINT point3 = { Img_Width_act / 2,Img_Height_act / 2 };

        Rect rect(Img_Width_bias, Img_Height_bias, Img_Width_act, Img_Height_act);
        //识别处理部分,第一幅图像
        if (llRealHandle_1 >= 0)
        {
            const char *img_path = "img1.bmp";
        //获取图像原始数据并保存至数组
        bool ret1 = NET_DVR_CapturePictureBlock(llRealHandle_1, img_path, 1);
    
        //识别并给出坐标偏差量
        //先截取图像有效探测区域
        if (ret1 == true)
        {
            Mat img_temp = imread(img_path, IMREAD_UNCHANGED);
            //………………
    
            Mat img_act = img_temp(rect);
            //识别并画出偏移结果
            Mat img_trans;
            cvtColor(img_act, img_trans, CV_BGR2GRAY);
            threshold(img_trans, img_trans, 150, threshold_value, CV_THRESH_OTSU);
            //Mat element_close = getStructuringElement(MORPH_RECT, Size(3, 3));
            Mat element = getStructuringElement(MORPH_RECT, Size(15, 15));
            Mat open;
            //顶帽操作  
            //morphologyEx(img_trans, close, MORPH_CLOSE, element_close);
            morphologyEx(img_trans, open, MORPH_OPEN, element);
            point1=Draw_Point(open, IDC_STATIC_PIC);
            //画背景坐标,PIC1
            Draw_Background(IDC_STATIC_PIC);
        }
        
    }
        这个函数原来是这样的,定义了rect,你说的是不是这个 Mat img_act = img_temp(rect);这个语句是错的,或者这个用法是错的,我是刚学,不太懂,我把(rect)去掉了就可以出现识别图像的界面了,不知道会不会对图像识别有问题,或者有其他影响
    
    打赏 评论

相关推荐 更多相似问题