【发布时间】:2012-10-01 13:16:02
【问题描述】:
我是 C++ 新手,我正在尝试创建一个 500x500 像素的 RGB 图像。图像应该由四种颜色的线性插值填充,每种颜色都定义为一个角,所以我应该有类似的东西:
Vec3b ul( 255, 0, 0 ); //upper left corner
Vec3b ur( 0, 255, 0 ); //upper right corner
Vec3b bl( 0, 0, 255 ); //bottom left corner
Vec3b br( 255, 0, 255 ); //bottom right corner
最终结果应该是这样的:
然后程序会在窗口等中显示图像……我可以做这些,但我只需要弄清楚如何将颜色放入图像中。到目前为止我的代码是这样的:
#include <QtCore/QCoreApplication>
#include <opencv/cv.h>
#include <opencv/highgui.h>
#include <iostream>
#include <string>
#include <sys/stat.h>
using namespace cv;
int main()
{
Mat image;
image.create( 500, 500, CV_8UC3);
//upper left corner
Vec3b ul( 255, 0, 0 );
//upper right corner
Vec3b ur( 0, 255, 0 );
//bottom left corner
Vec3b bl( 0, 0, 255 );
//bottom right corner
Vec3b br( 255, 0, 255 );
namedWindow("Colored Pixels");
imshow("Colored Pixels", image);
// shows image for 5 seconds
waitKey(5000);
return 0;
}
输出是
很高兴听到您的建议!
【问题讨论】:
-
我看不出这与 C++ 本身有什么关系..
标签: c++ colors interpolation pixels