cv :: Scalar不显示预期的颜色

Pro*_*ole 7 c++ opencv colors ios drawellipse

在图像框架上,我使用

void ellipse(Mat& img, Point center, Size axes, double angle, double startAngle, double endAngle, const Scalar& color, int thickness=1, int lineType=8, int shift=0)

绘制一个椭圆,我想将椭圆颜色设置为绿色 在此输入图像描述[RGB值:(165,206,94)].所以我将参数设置const Scalar& color

cv::Scalar(94.0, 206.0, 165.0, 0.0); // as BGR order, suppose the value is 0.0 - 255.0
cv::Scalar(94.0/255.0, 206.0/255.0, 165.0/255.0, 0.0); // suppose the value is 0.0 - 1.0
Run Code Online (Sandbox Code Playgroud)

我也试过RGB替代品.

CV_RGB(165.0, 206.0, 94.0); // as RGB order, suppose the value is 0.0 - 255.0
CV_RGB(165.0/255.0, 206.0/255.0, 94.0/255.0); // suppose the value is 0.0 - 1.0
Run Code Online (Sandbox Code Playgroud)

但显示的颜色是白色 在此输入图像描述 [RGB值(255,255,255)],而不是所需的绿色值.

我在这一点上错过了什么?有任何建议请.谢谢.

编辑:

让我把完整的相关代码放在这里.根据OpenCV iOS - 视频处理,这是CvVideoCamera配置- (void)viewDidLoad;:

self.videoCamera = [[CvVideoCamera alloc] initWithParentView:imgView];
[self.videoCamera setDelegate:self];
self.videoCamera.defaultAVCaptureDevicePosition = AVCaptureDevicePositionFront;
self.videoCamera.defaultAVCaptureSessionPreset = AVCaptureSessionPreset352x288;
self.videoCamera.defaultAVCaptureVideoOrientation = AVCaptureVideoOrientationPortrait;
self.videoCamera.defaultFPS = 30;
self.videoCamera.grayscaleMode = NO;
[self.videoCamera adjustLayoutToInterfaceOrientation:UIInterfaceOrientationPortrait];
Run Code Online (Sandbox Code Playgroud)

然后在[self.videoCamera start];调用之后,(Mat&)image将捕获并可以在CvVideoCameraDelegate方法中处理- (void)processImage:(Mat&)image;,这里是绘制椭圆的代码:

- (void)processImage:(Mat&)image {

NSLog(@"image.type(): %d", image.type()); // got 24

// image.convertTo(image, CV_8UC3); // try to convert image type, but with or without this line result the same

NSLog(@"image.type(): %d", image.type()); // also 24

cv::Scalar colorScalar = cv::Scalar( 94, 206, 165 );
cv::Point center( image.size().width*0.5, image.size().height*0.5 );
cv::Size size( 100, 100 );
cv::ellipse( image, center, size, 0, 0, 360, colorScalar, 4, 8, 0 );
Run Code Online (Sandbox Code Playgroud)

}

最终,椭圆仍然是白色,而不是所需的绿色.

Pow*_*wHu 13

将alpha设置为255可以解决此问题.标量(94206165255)


Bar*_*Das 3

由于 mrgloom 在评论中正确指出,这可能是因为您的图像类型 [您想要绘制的 Mat 对象,即 ellipse() 函数中的 Mat &img]。cv::Scalar(94, 206, 165) 是 8UC3 类型图像所需的绿色。在 32FC3 图像中设置这些值将产生白色。