超越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 metadata提取的PDF元数据,如何转换为一个Excel
  • ¥15 关于arduino编程toCharArray()函数的使用
  • ¥100 vc++混合CEF采用CLR方式编译报错
  • ¥15 coze 的插件输入飞书多维表格 app_token 后一直显示错误,如何解决?
  • ¥15 vite+vue3+plyr播放本地public文件夹下视频无法加载
  • ¥15 c#逐行读取txt文本,但是每一行里面数据之间空格数量不同
  • ¥50 如何openEuler 22.03上安装配置drbd
  • ¥20 ING91680C BLE5.3 芯片怎么实现串口收发数据
  • ¥15 无线连接树莓派,无法执行update,如何解决?(相关搜索:软件下载)
  • ¥15 Windows11, backspace, enter, space键失灵