Very basic question coming from a newbie in OpenCV. I just want to create an image with every pixel set to 0
(black). I have used the following code in the main() function:
IplImage* imgScribble = cvCreateImage(cvSize(320, 240), 8, 3);
And what I get is a solid gray image, instead of the black one.
Thanks in advance !
We can use the zeros() function of NumPy to create a black image in Python. The zeros() function makes a matrix containing only zeros given the matrix's number of rows and columns.
Step 1: Import OpenCV. Step 2: Read the original image using imread(). Step 3: Convert to grayscale using cv2. cvtcolor() function.
What version of opencv you are using? For Mat,
#include <opencv2/opencv.hpp>
cv::Mat image(320, 240, CV_8UC3, cv::Scalar(0, 0, 0));
I can suggest two more altrnatives:
IplImage* imgScribble = cvCreateImage(cvSize(320, 240), 8, 3);
// Here you can set any color
cvSet(imgScribble, cvScalar(0,0,0));
// Here only black
cvZero(imgScribble);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With