通过我的代码,我想知道图像的尺寸(以英寸为单位)。通过 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/