Ask Your Question
1

why is this circle only black?

asked 2017-01-17 18:11:42 -0600

j0h gravatar image

updated 2017-01-17 19:32:47 -0600

Im trying out the drawing functions, but having difficulty getting the colour I want. The circle appears, on some values, but not others, for color, but only ever shows up as black. What am I doing wrong? I have read the the documentation for the circle function.

I am using opencv 3.2, have tried Scalar(255,255,0) in lieu of a Hex Value. The circle is being drawn, but only in black, or white. When I switch to the all zeros Matrix, i can see a white circle on a black background.

#include <opencv2/highgui/highgui.hpp>
#include <opencv2/imgproc/imgproc.hpp>
#include <iostream>
using namespace std;
using namespace cv;
int main(int argc, char ** argv){

    Mat md0, md1, md2, md3;
    md0 = Mat::zeros(100,200,CV_32F);
    md1 = Mat::ones(100,200,CV_32F);

    pyrUp(md1,md2);

//drawing function
    Point2f p(77, 100);
    circle( md2, p,50,0xFFFF00,2,8,0);

    imshow("Double Ones", md2);

    waitKey(0);
    return 0;
    }
edit retag flag offensive close merge delete

1 answer

Sort by ยป oldest newest most voted
2

answered 2017-01-17 19:23:16 -0600

Tetragramm gravatar image

So, you should type out the Scalar value. I have no idea how it interprets a hex value, but it's almost certainly not what you want.

circle(md2, p, 50, Scalar(255,255,0), 2, 8, 0);

This makes it easier to see why. Your images only have one channel. So only the value in the first parameter of Scalar shows up. So if it's a zero, then the circle is black.

edit flag offensive delete link more

Comments

The same problem occurs when i use Scalar(255,255,0)

j0h gravatar imagej0h ( 2017-01-17 19:27:36 -0600 )edit

@j0h, a single channel image can only hold intensity values, black, gray, white.

to draw something in color, you need a 3 channel image, like:

Mat img = Mat::zeros(500,500,CV_8UC3);
berak gravatar imageberak ( 2017-01-17 19:49:36 -0600 )edit

Second step is also that when using CV_32F, the display shows between 0 and 1. So try filling md1 with 0s and then drawing the circle with 1s.

Tetragramm gravatar imageTetragramm ( 2017-01-17 23:36:24 -0600 )edit

Question Tools

1 follower

Stats

Asked: 2017-01-17 18:11:42 -0600

Seen: 3,221 times

Last updated: Jan 17 '17