超越nb 2021-07-23 16:55 采纳率: 57.1%
浏览 76
已结题

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)
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

问题事件

  • 系统已结题 9月17日
  • 已采纳回答 9月9日
  • 创建了问题 7月23日

悬赏问题

  • ¥15 有了解d3和topogram.js库的吗?有偿请教
  • ¥100 任意维数的K均值聚类
  • ¥15 stamps做sbas-insar,时序沉降图怎么画
  • ¥15 unity第一人称射击小游戏,有demo,在原脚本的基础上进行修改以达到要求
  • ¥15 买了个传感器,根据商家发的代码和步骤使用但是代码报错了不会改,有没有人可以看看
  • ¥15 关于#Java#的问题,如何解决?
  • ¥15 加热介质是液体,换热器壳侧导热系数和总的导热系数怎么算
  • ¥100 嵌入式系统基于PIC16F882和热敏电阻的数字温度计
  • ¥15 cmd cl 0x000007b
  • ¥20 BAPI_PR_CHANGE how to add account assignment information for service line