OPENCV C 调整大小函数:新宽度应乘以3
Opencv c++ resize function: new Width should be multiplied by 3
我正在qt环境中编程,我有一个带有2592x2048的垫子图像,我想将其调整到我拥有的"标签"的大小。但是,当我想显示图像时,我必须将宽度乘以3,因此图像以正确的大小显示。有任何解释吗?
这是我的代码:
//Here I get image from the a buffer and save it into a Mat image.
//img_width is 2592 and img_height is 2048
Mat image = Mat(cv::Size(img_width, img_height), CV_8UC3, (uchar*)img, Mat::AUTO_STEP);
Mat cimg;
double r; int n_width, n_height;
//Get the width of label (lbl) into which I want to show the image
n_width = ui->lbl->width();
r = (double)(n_width)/img_width;
n_height = r*(img_height);
cv::resize(image, cimg, Size(n_width*3, n_height), INTER_AREA);
谢谢。
调整大小函数运行良好,因为如果您将调整大小的图像保存为文件,则将正确显示。由于您想在Qlabel上显示它,因此我假设您必须先将图像转换为Qimage,然后再转换为qpixMap。我相信问题在于步骤或图像格式。
如果我们确保通过
传递的图像数据Mat image = Mat(cv::Size(img_width, img_height), CV_8UC3, (uchar*)img, Mat::AUTO_STEP);
确实是RGB映像,那么下面的代码应起作用:
ui->lbl->setPixmap(QPixmap::fromImage(QImage(cimg.data, cimg.cols, cimg.rows, *cimg.step.p, QImage::Format_RGB888 )));
最后,您可以使用constructor
来构造一个QIMAGE对象,而不是使用OpenCVQImage((uchar*)img, img_width, img_height, QImage::Format_RGB888)
,然后使用scaledtowidth方法进行调整大小。(当心认为此方法返回缩放图像,并且不执行调整大小的操作到图像本身本身)
相关文章:
- 有没有比在库中添加一个并非由所有派生类实现的新虚拟函数更好的设计实践
- C++模板函数中的初始化 - 新的初始值设定项表达式列表被视为复合表达式
- 是什么让放置新调用对象的构造函数?
- 如果我真的真的想从 STL 容器继承,并且我继承构造函数并删除新运算符,会发生什么?
- 新分配指向函数的指针是否合法?
- 放置上的析构函数 - 新
- 如何访问子类的新成员函数?
- OPENCV C 调整大小函数:新宽度应乘以3
- 如何在C++中访问新主函数的参数
- 派生类的新构造函数未生成:"overloaded member function not found"
- 继承层次结构中级中的新虚函数
- 将类构造函数分配给具有参数的新构造函数C++
- 使用以前的函数参数声明新的函数参数是否合法
- 什么是(新类())->函数();意味 着?
- 使用新的函数声明语法进行重写
- 模板化函数和放置新构造函数参数
- 构造函数与新构造函数
- c++如何阅读这个创建新构造函数的代码
- c++ 11中有新的函数类型表达式格式吗?
- 初始化现有变量/对象的新构造函数