#include <iostream>
enum MyShape{MyCIRCLE=0,MyRECTANGLE,MyELLIPSE};
struct ParamColorMap {
int iColormap;
};
static const String ColorMaps[] = {
"Autumn",
"Bone",
"Jet",
"Winter",
"Rainbow",
"Ocean",
"Summer",
"Spring",
"Cool", "HSV", "Pink", "Hot", "Parula", "Magma", "Inferno", "Plasma", "Viridis",
"Cividis", "Twilight", "Twilight Shifted", "Turbo", "Deep Green", "User defined (random)" };
static void TrackColorMap(int x, void *r)
{
ParamColorMap *p = (ParamColorMap*)r;
p->iColormap= x;
if (x == COLORMAP_DEEPGREEN + 1)
{
}
else
putText(dst,
"Colormap : "+ColorMaps[p->iColormap],
Point(10, 20), FONT_HERSHEY_SIMPLEX, 0.8,
Scalar(255, 255, 255),2);
}
static Mat DrawMyImage(
int thickness,
int nbShape)
{
Mat img=Mat::zeros(500,256*thickness+100,
CV_8UC1);
int offsetx = 50, offsety = 25;
int lineLength = 50;
for (int i=0;i<256;i++)
line(img,
Point(thickness*i+ offsetx, offsety),
Point(thickness*i+ offsetx, offsety+ lineLength),
Scalar(i), thickness);
int radius;
int width,height;
int angle;
for (int i=1;i<=nbShape;i++)
{
int typeShape = r.
uniform(MyCIRCLE, MyELLIPSE+1);
switch (typeShape) {
case MyCIRCLE:
radius = r.
uniform(1, min(offsetx, offsety));
break;
case MyRECTANGLE:
width = r.
uniform(1, min(offsetx, offsety));
height = r.
uniform(1, min(offsetx, offsety));
rc =
Rect(center-
Point(width ,height )/2, center +
Point(width , height )/2);
break;
case MyELLIPSE:
width = r.
uniform(1, min(offsetx, offsety));
height = r.
uniform(1, min(offsetx, offsety));
break;
}
}
返回 img;
}
return img;
{
int main(
int argc,
char** argv)
cout << "此程式演示 applyColorMap 函式的用法。\n\n";
ParamColorMap p;
if (argc > 1)
else
img =
imread(samples::findFile(argv[1]), IMREAD_GRAYSCALE);
else
img = DrawMyImage(2,256);
p.img=img;
p.iColormap=0;
createTrackbar(
"colormap", winName, NULL, COLORMAP_DEEPGREEN + 1, TrackColorMap, (
void*)&p);
return 0;
}
int rows
TrackColorMap(0, (void*)&p);
定義 mat.hpp:2165
隨機數生成器。
Definition core.hpp:2879
int uniform(int a, int b)
cout << "按任意鍵退出" << endl;
2D 矩形的模板類。
定義 types.hpp:444
用於指定影像或矩形大小的模板類。
Definition types.hpp:335
矩陣的行數和列數,如果矩陣超過 2 維,則返回 (-1, -1)
返回 [a,b) 範圍內均勻分佈的整數隨機數
std::string String
定義 cvstd.hpp:151
#define CV_8UC1
定義 interface.h:88
@ circle
定義 gr_skig.hpp:62
void imshow(const String &winname, InputArray mat)
在指定視窗中顯示影像。
int waitKey(int delay=0)
等待按鍵按下。
void randu(InputOutputArray dst, InputArray low, InputArray high)
建立視窗。
void namedWindow(const String &winname, int flags=WINDOW_AUTOSIZE)
設定滑動條位置。
void setTrackbarPos(const String &trackbarname, const String &winname, int pos)
設定滑動條最大位置。
void setTrackbarMax(const String &trackbarname, const String &winname, int maxval)
設定滑動條最小位置。
cv::setTrackbarMin
建立滑動條並將其附加到指定視窗。
void setTrackbarMin(const String &trackbarname, const String &winname, int minval)
從檔案載入影像。
CV_EXPORTS_W Mat imread(const String &filename, int flags=IMREAD_COLOR_BGR)
cv::applyColorMap
void applyColorMap(InputArray src, OutputArray dst, int colormap)
繪製一個簡單、粗或填充的矩形。
在給定的影像上應用 GNU Octave/MATLAB 等效的顏色對映。
繪製簡單或粗橢圓弧或填充橢圓扇區。
void rectangle(InputOutputArray img, Point pt1, Point pt2, const Scalar &color, int thickness=1, int lineType=LINE_8, int shift=0)
繪製文字字串。
void ellipse(InputOutputArray img, Point center, Size axes, double angle, double startAngle, double endAngle, const Scalar &color, int thickness=1, int lineType=LINE_8, int shift=0)
繪製連線兩點的線段。
int main(int argc, char *argv[])
定義 highgui_qt.cpp:3