上的圖像幀,我用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