在图像框架上,我使用
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,这是以下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];
然后在[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 );
}
最终,椭圆仍然是白色的,而不是所需的绿色。