机器人视觉项目:视觉检测识别+机器人跟随(12)

任务完成情况

opencv的数据格式转换,这次碰上了,主要就是cvMat,IplImage,cv::Mat,InputArray之间的格式转换,现在想要将提取的图像特征时,用一张灰度图传给surf特征检测器,计算出特征点,在这之前需要将图像的数据格式进行转换:

cv::xfeatures2d::SURF::detectAndCOmpute(InputArray image, InputArray mask, std::vector<std::vector<KeyPoint>>&keypoints, OutputArray descriptors, bool useProvideKeyPoints=false)

数据格式需转换成功,否则detectAndCompute()会提示错误信息:no matching function...

detectAndCompute()要求输入的image要求格式是InputArray类型的形参,但是一般都是使用Mat类型的实参直接传递。

使用

CvMat *img02 = cvCreateMat(img2->height, img2->width, CV_64FC3);
cvConvert(img02, img2);//将 IplImage格式img2转换cvMat格式img02

将将 IplImage格式img2转换cvMat格式img02,然后转为灰度图,对img_1传入到detectAndCompute(),这应该是没有问题的,但是仍然提示

invalid initialization of type 'cv::InputArray {aka const cv""InputArray&}' from expression of type 'cv::mat () {aka cv::mat () (iplimage)}'

意思是输入cv::mat()格式与InputArray格式不符

直接定义一个Mat类矩阵,强制将括号内的IplImage*类型的图像转换为Mat:

Mat img01(IplImage* img1);//直接定义Mat类型矩阵
cvtColor(img01, img_1, COLOR_RGB2GRAY);

 

找到的解释

InputArray这个接口类可以是Mat、Mat<T>、Mat<T, m, n>、vector<T>、vector<vector<T>>、vector<Mat>。也就意味着当你看refman或者源代码时,如果看见函数的参数类型是InputArray型时,把上诉几种类型作为参数都是可以的。

有时候InputArray输入的矩阵是个空参数,你只需要用cv::noArray()作为参数即可,或者很多代码里都用cv::Mat()作为空参。

这个类只能作为函数的形参参数使用,不要试图声明一个InputArray类型的变量

如果在你自己编写的函数中形参也想用InputArray,可以传递多类型的参数,在函数的内部可以使用InputArray::getMat()函数将传入的参数转换为Mat的结构,方便你函数内的操作;必要的时候,可能还需要InputArray::kind()用来区分Mat结构或者vector<>结构,但通常是不需要的。

这样怎么会还出现问题呢,不讲道理啊,

上最新代码tracking_node_8_12.cpp

/******************************************************************************
*
* The MIT License (MIT)
*
* Copyright (c) 2018 Bluewhale Robot
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 
  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值