当前位置:网站首页>OpenCV中的带参数宏定义CV_Assert()的作用
OpenCV中的带参数宏定义CV_Assert()的作用
2022-06-09 17:17:00 【昊虹图像算法】
CV_Assert()是OpneCV中的带参数宏定义,它的作用是:
若括号中的表达式值为false,则返回一个错误信息,并终止程序执行。
它的定义如下:
#define CV_Assert( expr ) if(!!(expr)) ; else cv::error( cv::Error::StsAssert, #expr, CV_Func, __FILE__, __LINE__ )
使用示例如下:
#include <opencv2/opencv.hpp>
using namespace cv;
int main()
{
cv::Mat srcImage = cv::imread("F:/material/images/car_plate/car_plate_01.jpg");
if (!srcImage.data)
return 1;
CV_Assert(srcImage.channels() == 1);
cv::imshow("srcImage", srcImage);
return(0);
}
原图片car_plate_01.jpg是一个三通道的图像,不满足条件“srcImage.channels() == 1”,所以会中止程序执行,并返回错误信息。
运行结果如下:
根据宏定义,语句:
CV_Assert(srcImage.channels() == 1);
展开为:
if(!!(srcImage.channels() == 1)) ;
else
cv::error( cv::Error::StsAssert, #srcImage.channels() == 1, CV_Func, __FILE__, __LINE__ );
上面语句的意义并不难理解,就不多叙述了。
边栏推荐
- OpenCV的imshow()查看图片的像素值
- nlp网络中两种残差结构对网络的影响
- c语言解决爬楼梯问题
- Interview questions - Supplement of Huawei computer test knowledge points
- [blockbuster] the cloud store brand has been upgraded, and the surprise award is coming! Participate in interactive sampling of Huawei's latest folding mobile phones
- Use testeract to recognize text in pictures
- 大数据生态安全框架的实现原理与最佳实践(上篇)
- 主动预防-DWS关键工具安装确认
- pyepics --Auto-saving: simple save/restore PVs
- C language voter voting function
猜你喜欢

Leetcode 1957. Delete characters to make the string better (yes, one pass)

Unity-获取XML文件的内容信息

How to train your accuracy?

刷脸认证如何实现人脸又快又准完成校验?
![[East China Normal University] information sharing for the first and second examinations](/img/f9/68b5b5ce21f4f851439fa061b477c9.jpg)
[East China Normal University] information sharing for the first and second examinations

为什么 SQL 语句使用了索引,但却还是慢查询?

Sbio | Chenyun group of Zhejiang University Review on the interaction mechanism between bacteria and fungi in agriculture

Word 教程,如何在 Word 中更改行距?

Error occurred when pychart installs the scratch Library‘

Swagger login address (error may be reported when logging in for the first time)
随机推荐
Interview questions - Supplement of Huawei computer test knowledge points
iis怎么打开md文件(is无法打开md文件报错怎么解决)
Manjaro kconsole开启半透明
idea卸载教程
Leetcode 1957. 删除字符使字符串变好(可以,一次过)
Why do SQL statements use indexes but still slow queries?
Le langage C résout le problème de l'escalier
回家-的路
存储器概念
并行存储结构
Written test question Huawei computer test ~ to be continued
【长时间序列预测】Aotoformer 代码详解之[1]数据预处理及数据读取
Swagger login address (error may be reported when logging in for the first time)
文心 ERNIE 3.0加持!小样本也可实现全量数据99%的效果!
Parallel storage structure
原码、反码、补码、移码 终于搞懂了
刷脸认证如何实现人脸又快又准完成校验?
c語言解决爬樓梯問題
【重磅】云商店品牌全新升级,惊喜大奖来袭!参与互动抽华为最新折叠手机
一些有趣的B+树优化实验