Can I get any useful information from the camera?
문제
I am using the AVCaptureVideoDataOutputSampleBufferDelegate
to display the video from an iPhones camera in a custom UIView
with the following delegate method.
- (void)captureOutput:(AVCaptureOutput *)captureOutput didOutputSampleBuffer:(CMSampleBufferRef)sampleBuffer fromConnection:(AVCaptureConnection *)connection
I would like to be able to pull out some useful information from the image such as Exposure, color, threshold.
What is the best way to access this sort of information?
해결책
Extract the metadata attachment from the sample buffer. You can find Exposure, color, etc. in it's metadata. something like this:
NSDictionary *exifDictionary = (NSDictionary*)CMGetAttachment(sampleBuffer, kCGImagePropertyExifDictionary, NULL);
다른 팁
You can access the underlying pixel data with this code:
CVPixelBufferRef pixelBuffer = CMSampleBufferGetImageBuffer(sampleBuffer);
CVReturn lock = CVPixelBufferLockBaseAddress(pixelBuffer, 0);
if (lock == kCVReturnSuccess) {
int w = 0;
int h = 0;
int r = 0;
int bytesPerPixel = 0;
unsigned char *buffer;
if (CVPixelBufferIsPlanar(pixelBuffer)) {
w = CVPixelBufferGetWidthOfPlane(pixelBuffer, 0);
h = CVPixelBufferGetHeightOfPlane(pixelBuffer, 0);
r = CVPixelBufferGetBytesPerRowOfPlane(pixelBuffer, 0);
bytesPerPixel = r/w;
buffer = CVPixelBufferGetBaseAddressOfPlane(pixelBuffer, 0);
}else {
w = CVPixelBufferGetWidth(pixelBuffer);
h = CVPixelBufferGetHeight(pixelBuffer);
r = CVPixelBufferGetBytesPerRow(pixelBuffer);
bytesPerPixel = r/w;
buffer = CVPixelBufferGetBaseAddress(pixelBuffer);
}
}
제휴하지 않습니다 StackOverflow