C++读取目录下所有文件名称
1、包含头文件`
#include <io.h>
#include <iostream>
2、命名空间
using namespace std;
3、封装函数
建立f的引用vector<String> &f
遍历得到的文件夹目录存放在f中
void GetAllFileName(vector<String> &f) {
_finddata_t file;
intptr_t lf;
if ((lf = _findfirst("miao-db\\labels\\train2017\\*.*", &file)) == -1)
cout << "Not Found!" << endl;
else {
while (_findnext(lf, &file) == 0)
f.push_back(file.name);
}
_findclose(lf);
}
4、调用并将结果输出到屏幕
int main(){
vector<String> f;
GetAllFileName(f);
for (int i = 0; i < f.size(); i++) {
cout << f[i] << endl;
}
}
5、结果(部分展示)
Mat类型的整体赋值
countA是Mat类型五行五列矩阵,aa是Mat类型五行一列矩阵。可以直接将aa赋值给countA,覆盖掉countA所有内容。
C++实现split函数
1、包含头文件
#include <iostream>
#include <sstream>
#include <vector>
#include <string>
2、命名空间
using namespace std;
3、封装函数
static void _split(const std::string &s, char delim,
std::vector<std::string> &elems) {
std::stringstream ss(s);
std::string item;
while (std::getline(ss, item, delim)) {
elems.push_back(item);
}
}
std::vector<std::string> split(const std::string &s, char delim) {
std::vector<std::string> elems;
_split(s, delim, elems);
return elems;
}
4、调用
std::vector<std::string> x = split("0000.txt", '.');
cout << x[0] << endl;
String splitf = x[0] + ".png";
cout << splitf << endl;
5、结果
坑坑坑!!!!OpenCV C++ 矩阵rectangle画矩形!
看了几篇博客,博主只介绍cv::rectangle
与cvRectangle
的区别,但是没有介绍二者头文件的区别!!!
在声明了using namespace cv;
空间后,调用cv::rectangle
一直显示没有此成员,根据博主介绍,头文件
#include <iostream>
#include <opencv2\highgui\highgui.hpp>
cv::rectangle(matImage,cvPoint(20,200),cvPoint(200,300),Scalar(255,0,0),1,1,0);
显示没有rectangle此成员,更不用提别的。。。。
无奈去官方文档看了一下,吃了个教训,以后就算英文看不懂也需要以官方文档为准
opencv英文官方文档
需要包含头文件是这个呀!
#include <opencv2/imgproc.hpp>
对于参数,很明确的讲了,需要时Point类型。。。。
步骤:
1、头文件
#include <opencv2/imgproc.hpp>
Point a(2,3), b(3,5);
cv::rectangle(img, a, b, (255, 255, 0), 3);
调整矩形框颜色和文字颜色
cv::rectangle(img, a, b, cv::Scalar(238, 134, 28), 3);
cv::putText(img, s, c, cv::FONT_HERSHEY_COMPLEX, 1.5, cv::Scalar(0,0,205), 2);
在调用这两个函数时,根据其参数向调整一个好看的颜色标注,使用cv::Scalar(a,b,c),没看具体定义,很坑,发现a,b,c参数是BGR形式,需要自己调整一下
另外,RGB色彩,参考RGB颜色取值
今日进度:搞定
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)