Ich möchte die Kamera verwenden, um eine rohe Bilddaten und dann Matlab oder Opencv in den Laptop zu verwenden, um es nachbearbeiten. Also muss ich diese rohen Bilddaten vom iPhone zum Laptop nehmen.Wie speichere ich ein BGRA-Bild auf dem iPhone und dann auf einen Laptop für die Nachbearbeitung
Derzeit verwende ich AVFoudnation, um 32BGRA Bild zu erhalten (es sind die rohen Bilddaten, richtig?). Und ich speichere es als Datei, aber ich kann es nicht vom iPhone nehmen. (Gibt es irgendwelche Lösungen ohne jailbreak?)
Im Folgenden sind einige Codes zu verwenden:
if let videoConnection = stillImageOutput!.connectionWithMediaType(AVMediaTypeVideo) {
videoConnection.videoOrientation = AVCaptureVideoOrientation.Portrait
stillImageOutput?.captureStillImageAsynchronouslyFromConnection(videoConnection, completionHandler: {(sampleBuffer, error) in
if (sampleBuffer != nil) {
// get the raw image data
let cameraFrame = CMSampleBufferGetImageBuffer(sampleBuffer)
CVPixelBufferLockBaseAddress(cameraFrame!, 0)
let rawImage = CVPixelBufferGetBaseAddress(cameraFrame!)
let bytesPerRow = CVPixelBufferGetBytesPerRow(cameraFrame!)
let rawImageData = NSData.init(bytes: rawImage, length: bytesPerRow*CVPixelBufferGetHeight(cameraFrame!))
// process the rawImageData, we now save it
var paths = NSSearchPathForDirectoriesInDomains (.DocumentDirectory, .UserDomainMask, true);
let documentsDirectory = paths[0]
let fileName = documentsDirectory.stringByAppendingString("/rawImageData")
do {
try rawImageData.writeToFile(fileName, options: NSDataWritingOptions.DataWritingFileProtectionComplete)
} catch {
}
print("Raw image data write successfully.")
print("Path of raw image data: ", fileName)
CVPixelBufferUnlockBaseAddress(cameraFrame!, 0)
}
})
}
Sollte ich die BGRA Daten in das Fotoalbum speichern müssen und es dann herausnehmen, wenn ja, wie kann ich tun es (UIImage verwenden?)
Danke.
Ein Update:
I BGRA Bild UIImage verwandeln und nutzen UIImageWriteToSavedPhotosAlbum es in das Fotoalbum zu speichern, dann verwende ich airdrop die Image-Datei May Mac zu übernehmen. Ich fand jedoch, dass das Bild JPEG-Format ist. Was ist los mit dir? Im Folgenden sind die Codes:
if (sampleBuffer != nil) {
let rawImage:UIImage = self.imageFromSampleBuffer(sampleBuffer)
self.capturedImage.image = rawImage
UIImageWriteToSavedPhotosAlbum(rawImage, nil, nil, nil)
print("Raw Image write to photo album successfully")
}
// Create a UIImage from sample buffer data
func imageFromSampleBuffer(sampleBuffer : CMSampleBufferRef) -> UIImage
{
// Get a CMSampleBuffer's Core Video image buffer for the media data
let imageBuffer = CMSampleBufferGetImageBuffer(sampleBuffer);
// Lock the base address of the pixel buffer
CVPixelBufferLockBaseAddress(imageBuffer!, 0);
// Get the number of bytes per row for the pixel buffer
let baseAddress = CVPixelBufferGetBaseAddress(imageBuffer!);
// Get the number of bytes per row for the pixel buffer
let bytesPerRow = CVPixelBufferGetBytesPerRow(imageBuffer!);
// Get the pixel buffer width and height
let width = CVPixelBufferGetWidth(imageBuffer!);
let height = CVPixelBufferGetHeight(imageBuffer!);
// Create a device-dependent RGB color space
let colorSpace = CGColorSpaceCreateDeviceRGB();
// Create a bitmap graphics context with the sample buffer data
var bitmapInfo: UInt32 = CGBitmapInfo.ByteOrder32Big.rawValue
bitmapInfo |= CGImageAlphaInfo.PremultipliedLast.rawValue & CGBitmapInfo.AlphaInfoMask.rawValue
let context = CGBitmapContextCreate(baseAddress, width, height, 8,
bytesPerRow, colorSpace, bitmapInfo);
// Create a Quartz image from the pixel data in the bitmap graphics context
let quartzImage = CGBitmapContextCreateImage(context);
// Unlock the pixel buffer
CVPixelBufferUnlockBaseAddress(imageBuffer!,0);
// Create an image object from the Quartz image
let image = UIImage.init(CGImage: quartzImage!);
return (image);
}
In welchem Format möchten Sie MATLAB verwenden? Kann MATLAB kein Bild importieren? – jtbandes
Matlab kann BGRA Image nicht importieren, kann ich die Rohdaten als BMP im iPhone speichern und es zum Laptop bringen? –