文章目录
- 1. python openCv含中文路径的图像读写
- 2. [i for i in range(1,10)] (List Comprehensions)列表解析
- 3. void split(const Mat& src,Mat *mvBegin) 通道分离
- 4. 利用数组切片对图像进行分割
- 5. 报错:Traceback (most recent call last):......cv2.error: OpenCV(4.5.5) D:\a\opencv-python\opencv-python\opencv\modules\imgcodecs\src\loadsave.cpp:976: error: (-215:Assertion failed) !image.empty() in function 'cv::imencode'
- 6. 点云程序执行时间计算
- 7. QT警告QMetaObject::connectSlotsByName: No matching signal for on_actionOpen_triggered()
- 8. QTabWidget设置为透明且不影响控件的方法
- 9. switch 提示 控制传输跳过的实例化
- 10. CloudCompare打不开点云报错:An error occured while loading 'xxx':the third-party library in charge of saving/loading the file has failed to perform the operation
- 11. QT 程序异常结束 The process was ended forceully
- 12. 杂乱
1. python openCv含中文路径的图像读写
- 不能直接使用imread和imwrite,需要使用imdecode和imencode
# import numpy
img = cv2.imread(file_path)
img = cv2.imdecode(numpy.fromfile(file_path, dtype=numpy.uint8), -1)
cv2.imwrite(save_path, img)
cv2.imencode('.jpg', img)[1].tofile(file_path)
2. [i for i in range(1,10)] (List Comprehensions)列表解析
列表解析式是将一个列表(实际上适用于任何可迭代对象)转换成另一个列表的工具。在转换过程中,可以指定元素必须符合一定的条件,才能添加至新的列表中,这样每个元素都可以按需要进行转换。此外列表解析式还支持添加筛选条件,例如筛选出 i*2>10 的数:
>>> li = [i*2 for i in range(1, 11) if i*2 > 10]
>>> print(li)
[12, 14, 16, 18, 20]
3. void split(const Mat& src,Mat *mvBegin) 通道分离
4. 利用数组切片对图像进行分割
x0 = xmlbox.find('xmin').text
y0 = xmlbox.find('ymin').text
x1 = xmlbox.find('xmax').text
y1 = xmlbox.find('ymax').text
# cv2裁剪出目标框中的图片
obj_img = img_cv[int(y0):int(y1), int(x0):int(x1)]
5. 报错:Traceback (most recent call last):…cv2.error: OpenCV(4.5.5) D:\a\opencv-python\opencv-python\opencv\modules\imgcodecs\src\loadsave.cpp:976: error: (-215:Assertion failed) !image.empty() in function ‘cv::imencode’
- 出现这个报错通过打印图像信息发现是在裁剪某张图的标注框时报错的,查看标注信息发现存在负数,将该重新标注后就没报错了
6. 点云程序执行时间计算
//1.StopWatch
//getTime() 计算时间单位为毫秒
//getTimeSeconds() 单位为秒
pcl::StopWatch time;
//···第一个程序
cout << "第一个程序耗时: " << time.getTimeSeconds()<<endl;
time.reset();//重置时间
//···第二个程序
cout << "第二个程序耗时: " << time.getTimeSeconds()<<endl;
//2.ScopeTime
{
//计算的是ScopeTime类对象从构建到析构的时间,即创建对象后到外边这层{}代码运行结束的时间
pcl::ScopeTime scope_time("第三个程序耗时:");
//···第三个程序
}
//3.console time
# include <pcl/console/time.h>
pcl::console::Tictoc tt;
tt.tic();
//···第四个程序
std::cout << "第四个程序耗时:" << tt.toc() <<std::endl;
//4.ctime clock
# include<ctime>
time_t begin ,end;
begin = clock();
//···第五个程序
end = clock();
double Times = double(end-begin)/CLOCKS_PER_SEC;
std::cout<<"第五个程序耗时:"<< Times<<std::endl;
7. QT警告QMetaObject::connectSlotsByName: No matching signal for on_actionOpen_triggered()
- QMetaObject::connectSlotsByName: No matching signal for on_actionOpen_triggered()
- 产生原因:自己定义的槽函数以标准命名"on_xxx_xx",后面又用connect将信号和槽链接;其次纯代码产生的控件没有设置objectname也会有这个提示
- 解决方法:将槽函数中的“on_”删除,或者直接在ui界面右键控件转到槽将代码转移到新的槽函数中
8. QTabWidget设置为透明且不影响控件的方法
ui->tabWidget->setStyleSheet("QTabWidget:pane {border-top:0px solid #e8f3f9;background: transparent; }");
9. switch 提示 控制传输跳过的实例化
- 将case语句下的内容加上大括号{}
10. CloudCompare打不开点云报错:An error occured while loading ‘xxx’:the third-party library in charge of saving/loading the file has failed to perform the operation
- 点云文件和路径名称中存在中文,解决方法将路径中的中文改为英文
11. QT 程序异常结束 The process was ended forceully
- 这种情况大多是没找到动态链接库,一般解决方法有两种
-
- 将.dll文件所在目录设置为系统环境变量
-
- 将项目所需dll复制到.exe文件所在目录下
-
12. 杂乱
- //指针传递和引用传递
- 如果函数无须改变引用形参的值,最好将其声明为常量引用
- auto 类型说明符 在将表达式的值赋值给变量时,通过初始值来推算变量的类型
- os.listdir()方法用于返回指定的文件夹包含的文件或文件夹的名字的列表
- os.path.join 把目录和文件名合成一个路径
- for i in range () 就是给i赋值,range(start, stop[, step]),分别是起始、终止和步长
- range(3) 即:从0到3,不包含3,即0, 1, 2 ;
- i for i in range() 列表解析式,从旧列表中取出符合规定的值组成新列表
- np.random.randint 返回一个随机整型数,范围从低(包括)到高(不包括),即[low, high)。 如果没有写参数high的值,则返回[0,low)的值,直到index的长度达到 count。
- enumerate()函数用于将一个可遍历的数据对象(如列表、元组或字符串)组合为一个索引序列, 同时列出数据和数据下标,一般用在for 循环当中,返回 enumerate(枚举) 对象。