【发布时间】:2013-04-01 18:10:38
【问题描述】:
在图像框架上,我使用
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
我也尝试了 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
但显示的颜色是白色 [RGB 值 (255, 255, 255) ],而不是所需的绿色。
此时我错过了什么?请有任何建议。谢谢。
编辑:
让我把整个相关代码放在这里。根据OpenCV iOS - Video Processing,这是- (void)viewDidLoad;中的CvVideoCamera配置:
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];
然后在调用[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 );
}
最终,椭圆仍然是白色的,而不是想要的绿色。
【问题讨论】:
-
检查代码的其余部分并确保您没有在其他地方更改颜色值。您提供的部分在我的机器中完美显示了预期的绿色。
-
也许你有浮动类型的图像?哪些有 [0 1] 值范围?
-
@Barshan Das 我已经检查并注释了其余代码,但颜色仍然相同。哪一个适合你?
-
@mrgloom 你所说的“图像”是什么意思?是图像作为方法
ellipse()中的参数吗?如果是,是Mat& image,我怎么知道它的类型是不是float? -
你可以使用 mat.type()
标签: c++ ios opencv colors drawellipse