上的图像帧,我用CV ::标量不显示预期的颜色
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);
}
最终,椭圆仍处于白色,而不是所期望的绿色之一。
检查代码的其余部分,并确保不会在其他地方更改颜色值。您提供的部分完美地显示了我机器中的预期绿色。 – Barshan 2013-04-10 05:45:38
也许你有漂浮类型的图像?哪些值[0 1]的值范围? – mrgloom 2013-04-10 05:55:24
@Barshan Das我已经检查并评论了代码的其余部分,但颜色仍然相同。哪一个适合你? – Protocole 2013-04-10 06:19:11