当前位置: 首页 > 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;

相关文章:

  • 软件公司进军无人机领域的战略指南与生态合作全景-优雅草卓伊凡
  • Tomcat项目本地部署(Servlet为例)
  • 性能测试-jmeter实战3
  • jmeter工具简单认识
  • Vue + AbortController 请求取消弹窗 hook 封装
  • 【Qt】QTableWidget表格右键菜单
  • 键盘觉醒:Raycast 把 Mac 变成「AI 指令战舰」
  • joomla 使用nginx服务器只能打开首页,其他页面404的解决方案
  • 16、Redis底层数据结构
  • 样式失控:Word文档格式混乱的根源与对策
  • 【Flink实战】 Flink SQL 中处理字符串 `‘NULL‘` 并转换为 `BIGINT`
  • 【Ambari3.0.0 部署】Step4—时间同步(Chrony)-适用于el8
  • Xilinx XC7A12T‑1CPG238I Artix‑7 FPGA
  • Java 编程之代理模式
  • Matter协议开发者指南:使用Matter SDK构建智能家居应用
  • 数学公式排版简史
  • JavaWeb-day1
  • Spring Cloud 服务调用详解:Ribbon 负载均衡与 Feign 声明式接口调用
  • 第一章:认识AI
  • vtk和opencv和opengl直接的区别是什么?
  • 软件产品如何做网站推广/最新域名8xgmvxyz
  • 海沧网站建设/品牌关键词优化哪家便宜
  • 手机网站开发报价单/百度收录查询
  • 自己做本地网站/在哪里查关键词排名
  • 南京市建设行政网站/百度推广后台登录入口
  • 现在网站后台有哪几种模板形式/北京做网页的公司