This repository was archived by the owner on Sep 7, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 338
Expand file tree
/
Copy pathcreateColoredImage.cpp
More file actions
48 lines (40 loc) · 1.52 KB
/
createColoredImage.cpp
File metadata and controls
48 lines (40 loc) · 1.52 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
// Create a coloured image in C++ using OpenCV.
#include "opencv2/highgui/highgui.hpp"
using namespace cv;
using namespace std;
int main()
{
// To create an image
// CV_8UC3 depicts : (3 channels,8 bit image depth
// Height = 500 pixels, Width = 1000 pixels
// (0, 0, 100) assigned for Blue, Green and Red
// plane respectively.
// So the image will appear red as the red
// component is set to 100.
Mat img(500, 1000, CV_8UC3, Scalar(0,0, 100));
// check whether the image is loaded or not
if (img.empty())
{
cout << "\n Image not created. You"
" have done something wrong. \n";
return -1; // Unsuccessful.
}
// first argument: name of the window
// second argument: flag- types:
// WINDOW_NORMAL If this is set, the user can
// resize the window.
// WINDOW_AUTOSIZE If this is set, the window size
// is automatically adjusted to fit
// the displayed image, and you cannot
// change the window size manually.
// WINDOW_OPENGL If this is set, the window will be
// created with OpenGL support.
namedWindow("A_good_name", CV_WINDOW_AUTOSIZE);
// first argument: name of the window
// second argument: image to be shown(Mat object)
imshow("A_good_name", img);
waitKey(0); //wait infinite time for a keypress
// destroy the window with the name, "MyWindow"
destroyWindow("A_good_name");
return 0;
}