当前位置: 首页 > news >正文

opencv依据图像类型读取图像像素点

Mat数据类型和通道对应的type():

库类型C1C2C3C4
CV_8U081624
CV_8S191725
CV_16U2101826
CV_16S3111927
CV_32S4122028
CV_32F5132129
CV_64F6142230

通过c++程序查看类型并读取图像像素点:

switch (im->type()){case 0:std::cout << "at (" << x << ", " << y << " ) value is: " << static_cast<int>(im->at<uchar>(cv::Point(x, y))) << std::endl; break;case 1:std::cout << "at (" << x << ", " << y << " ) value is: " << static_cast<int>(im->at<char>(cv::Point(x, y))) << std::endl; break;case 2:std::cout << "at (" << x << ", " << y << " ) value is: " << static_cast<int>(im->at<ushort>(cv::Point(x, y))) << std::endl; break;case 3:std::cout << "at (" << x << ", " << y << " ) value is: " << static_cast<int>(im->at<short>(cv::Point(x, y))) << std::endl; break;case 4:std::cout << "at (" << x << ", " << y << " ) value is: " << static_cast<int>(im->at<int>(cv::Point(x, y))) << std::endl; break;case 5:std::cout << "at (" << x << ", " << y << " ) value is: " << static_cast<int>(im->at<float>(cv::Point(x, y))) << std::endl; break;case 6:std::cout << "at (" << x << ", " << y << " ) value is: " << static_cast<int>(im->at<double>(cv::Point(x, y))) << std::endl; break;case 16:std::cout << "at (" << x << ", " << y << " ) value is: " << static_cast<int>(im->ptr<uchar>(y)[x * 3]) << "," << static_cast<int>(im->ptr<uchar>(y)[x * 3 + 1]) << "," << static_cast<int>(im->ptr<uchar>(y)[x * 3 + 2]) << std::endl; break;case 17:std::cout << "at (" << x << ", " << y << " ) value is: " << static_cast<int>(im->ptr<char>(y)[x * 3]) << "," << static_cast<int>(im->ptr<char>(y)[x * 3 + 1]) << "," << static_cast<int>(im->ptr<char>(y)[x * 3 + 2]) << std::endl; break;case 18:std::cout << "at (" << x << ", " << y << " ) value is: " << static_cast<int>(im->ptr<ushort>(y)[x * 3]) << "," << static_cast<int>(im->ptr<ushort>(y)[x * 3 + 1]) << "," << static_cast<int>(im->ptr<ushort>(y)[x * 3 + 2]) << std::endl; break;case 19:std::cout << "at (" << x << ", " << y << " ) value is: " << static_cast<int>(im->ptr<short>(y)[x * 3]) << "," << static_cast<int>(im->ptr<short>(y)[x * 3 + 1]) << "," << static_cast<int>(im->ptr<short>(y)[x * 3 + 2]) << std::endl; break;case 20:std::cout << "at (" << x << ", " << y << " ) value is: " << static_cast<int>(im->ptr<int>(y)[x * 3]) << "," << static_cast<int>(im->ptr<int>(y)[x * 3 + 1]) << "," << static_cast<int>(im->ptr<int>(y)[x * 3 + 2]) << std::endl; break;case 21:std::cout << "at (" << x << ", " << y << " ) value is: " << static_cast<int>(im->ptr<float>(y)[x * 3]) << "," << static_cast<int>(im->ptr<float>(y)[x * 3 + 1]) << "," << static_cast<int>(im->ptr<float>(y)[x * 3 + 2]) << std::endl; break;case 22:std::cout << "at (" << x << ", " << y << " ) value is: " << static_cast<int>(im->ptr<double>(y)[x * 3]) << "," << static_cast<int>(im->ptr<double>(y)[x * 3 + 1]) << "," << static_cast<int>(im->ptr<double>(y)[x * 3 + 2]) << std::endl; break;}break;
http://www.lqws.cn/news/452431.html

相关文章:

  • 【PyTorch】请问,Reproducibility中的‘:4096:8‘是什么呀?
  • 20250620-Pandas.cut
  • aws(学习笔记第四十五课) route53-failover
  • 文件夹美化工具推荐,打造个性化电脑界面
  • 【网工】华为配置专题进阶篇④
  • 学习华为 ensp 的学习心得体会
  • 10分钟撸出高性能网络服务:吃透高性能优化:缓存_锁_系统调用_编译
  • 汽车整车厂如何用数字孪生系统打造“透明车间”
  • 【React】React CSS 样式设置全攻略
  • DAY 37 早停策略和模型权重的保存
  • RPGMZ游戏引擎 如何手动控制文字显示速度
  • 机器翻译与跨语言学习数据集综述
  • 情感大模型
  • “地标界爱马仕”再拓疆域:世酒中菜联袂赤水金钗石斛定义中国GI
  • vue3 reactive重新赋值
  • QEMU学习之路(10)— RISCV64 virt 使用Ubuntu启动
  • Linux故障排查与性能优化实战经验
  • AI浪潮下的自媒体革命:智能体崛起与人类价值的重构
  • Qi无线充电:车载充电的便捷与安全之选
  • servlet前后端交互
  • C++设计模式
  • 在VTK中捕捉体绘制图像并实时图像处理
  • uniapp开发小程序,导出文件打开并保存,实现过程downloadFile下载,openDocument打开
  • 【Python】Excel表格操作:ISBN转条形码
  • React Native【实战范例】弹跳动画菜单导航
  • 学习threejs,三维汽车模拟器,场景有树、云、山等
  • Nginx-Ingress-Controller自定义端口实现TCP/UDP转发
  • 大数据系统架构实践(一):Zookeeper集群部署
  • 局域网投屏工具(将任何设备转换为计算机的辅助屏幕)Deskreen
  • LVS负载均衡群集:Nginx+Tomcat负载均衡群集