c++ - 使用 OpenCV 库查找以英寸为单位的图像尺寸

标签 c++ opencv

通过我的代码,我想知道图像的尺寸(以英寸为单位)。通过 OpenCV,我可以使用以下代码找到图像像素数组的高度和宽度:

#include "stdafx.h"
#include <cv.h>
#include <cxcore.h>
#include <highgui.h>
#include <iostream>
using namespace std;
int _tmain(int argc, _TCHAR* argv[])
{
     IplImage *img = cvLoadImage("photo.jpg");
     if (!img) {
        printf("Error: Couldn't open the image file.\n");
        return 1;
     }
     cout<<"Number of pixels in width = "<<img->width<<endl<<"Number of pixels in height = "<<img->height;
      return(0);
}

请帮我找出以英寸为单位的图像尺寸。 提前致谢...

最佳答案

您需要知道显示器的 DPI。为此,您需要查看您平台的 SDK (Windows/Linux/Mac) 以了解如何检索此信息,因为 OpenCV 没有为此提供功能。

Image Size Calculator是执行此计算的 JavaScript 计算器。检查页面的源代码以获取代码。

关于c++ - 使用 OpenCV 库查找以英寸为单位的图像尺寸,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10846629/

相关文章:

c++ - 将 OpenGL 的 glRotated 转换为 Maya 的 cmds.rotate

python - OpenCV:自适应阈值错误(错误 -215)

c++ - 在 C++ 中计算单 channel 直方图的均值和标准差

python - 在 OpenCV Python 中打开 DivX/XVID 视频

c++ - 接口(interface)集合相互依赖

c++ - 吉尔提升 : convert rgb8_image_t to rgba8_image_t

c++ - 线程的子线程?

c++ - Unixtime 转换为可比时间

c++ - OpenCV 2.4.1 undefined reference

java - OpenCV HoughLines 只返回一行