Thread: CameraController, 3GS and 3.0
-
08-19-2009, 06:15 PM #41
I tried to do it from a timer called function.
I then tried to print the data in readblePixels and pixels in various ways, all giving the pixels of a black image with a white alpha channel.Code:- (void)frame { CoreSurfaceBufferRef coreSurfaceBuffer = [cameraController performSelector:@selector(_createPreviewIOSurface)]; uii = [cameraController performSelector:@selector(_createPreviewImage)]; if (!coreSurfaceBuffer) return; Surface *surface = [[Surface alloc]initWithCoreSurfaceBuffer:coreSurfaceBuffer]; [surface lock]; unsigned int height = surface.height; unsigned int width = surface.width; unsigned int alignmentedBytesPerRow = (width * 4); if (!readblePixels) { readblePixels = CGBitmapAllocateData(alignmentedBytesPerRow * height); NSLog(@"alloced readablepixels"); } unsigned int bytesPerRow = surface.bytesPerRow; void *pixels = surface.baseAddress; for (unsigned int j = 0; j < height; j++) { memcpy(readblePixels + alignmentedBytesPerRow * j, pixels + bytesPerRow * j, bytesPerRow); } previewWidth = width; previewHeight = height; pixelDataLength = alignmentedBytesPerRow * height; previewBytesPerRow = alignmentedBytesPerRow; [surface unlock]; [surface release]; } - (void)applicationDidFinishLaunching:(UIApplication *)application { cameraController = [(id)objc_getClass("PLCameraController") performSelector:@selector(sharedInstance)]; [cameraController setDelegate:self]; [cameraController setFocusDisabled:NO]; [cameraController setCaptureAtFullResolution:YES]; [cameraController setDontShowFocus:YES]; [cameraController retain]; UIView *previewView = [cameraController performSelector:@selector(previewView)]; [previewView retain]; [window addSubview:previewView]; [cameraController performSelector:@selector(startPreview)]; sleep(2); [window makeKeyAndVisible]; self.frameTimer = [NSTimer scheduledTimerWithTimeInterval:1.0/30.0 target:self selector:@selector(frame) userInfo:nil repeats:YES]; }
Could you please post your function using the _createPreviewIOSurface or tell me where I'm going wrong?
Thanks.
-
08-21-2009, 09:17 AM #42
Mmm... that should work...
When I was testing with that code, I used readblePixels for creating an UIImage and I was able to see the screen shot...
The only difference with my code is this line:
CoreSurfaceBufferRef *coreSurfaceBuffer = [cameraController _createPreviewIOSurface];
Try using a pointer.
-
08-22-2009, 07:12 PM #43
Thanks a lot rilocr.
I'm now able to get the data.
However, after about ten seconds the application is running, it crashes on _createPreviewIOSurface and gdb says:
Program received signal: “0”.
warning: check_safe_call: could not restore current frame
Got any idea what might mess up the stack?
-
08-23-2009, 11:09 AM #44
Hello all (new to these parts),
I've successfully gotten access to the PLCameraController and am stuck where a lot of you are also stuck, trying to access raw image data.
The screen shot accessors from the PLCameraController object are unfortunetly useless to me as I need to modify the current frame, and display it. Unless I did some form of switching back and forth every frame to get a new screenshot but I am certain this would flicker like crazy.
I've tried taking the previewView UIView from the PLCameraController and rendering that but have had no luck. Here is the code I used in that attempt:
Unfortunetly all this does is return a completely black image. I am not even sure if this is a valid path to take for finding a fix.Code:UIGraphicsBeginImageContext(cameraView.bounds.size); [cameraView.layer renderInContext:UIGraphicsGetCurrentContext()]; UIImage *contextImage = UIGraphicsGetImageFromCurrentImageContext(); UIGraphicsEndImageContext(); [imageView setImage:contextImage];
Anyone have any thoughts on possibly getting camera frames from rendering previewView as a UIImage? Possible? Crazy? Wild goose hunt?
-
08-25-2009, 02:48 PM #45
Hi natios,
Try releasing the coreSurfaceBuffer variable with CFRelease(coreSurfaceBuffer).
That's the only additional code I have.
-
08-29-2009, 01:08 PM #46
Hard!!!
its hard to add on the extra bits of code you guys tell me. can one of you, who has successfully completed the plcameracontroller, send a download link with the xcode file so i can recieve it on a file sharing website. its really hard to code the camera controller.
-
08-29-2009, 05:57 PM #47
Thanks for your time rilocr.
You've helped me a lot.
-
09-09-2009, 09:22 AM #48
Direct Access?
Hi there,
has anyone ever figured out a way to access the camera directly or find a workaround?
It is really annoying that you get a screen-capture when calling _createPreviewImage !! Whenever you overlay the cameras UIView with controls or opengl the image returned from _createPreviewImage is useless!
I tried to do a screen capture and only capture the camera UIView, but i can't use the cams UIView with:
because it's not a full UIView and i don't know how to extend it to be able to use it with the screen capture mechanism.Code:UIGraphicsBeginImageContext(cam.bounds.size); [cam.layer renderInContext:UIGraphicsGetCurrentContext()]; UIImage *resultingImage = UIGraphicsGetImageFromCurrentImageContext(); UIGraphicsEndImageContext();
Did any of you figure out how to get the cameras raw data or does anyone know how to extend the camdelegate to be able to take screenshots?
Greets
bas
-
09-16-2009, 09:00 AM #49
Hi,
i have an iphone 3g and want to make a video camera.
I can see the preview and i can get every 1/15 sec an UIImage ([cameraController _createPreviewImage]).
Now i want to save them because if they are stored in an array the iphone's memory is in less than 5 sec full.
Thans in advance
Max
Sorry, my English is so bad;
I'm german and 14 years old.Last edited by max.reif; 09-17-2009 at 08:32 AM.
-
09-21-2009, 10:45 AM #50
Hi,
You can use ffmpeg, just google it. That would be an external library for your app, but I think there are other solutions.
Regards
-
10-27-2009, 10:10 AM #51
I seem to be hitting this wall as well. trying to do AR apps using screengrabs is obviously impossible. I can see that the _camera variable was removed in FW3 which is proving to be a stumbling block. Has anybody managed to find the secret to grabbing the raw data yet and installing the needed callbacks?
Actually, I've noticed that Cycorder still works fine with my iPhone with FW3. I take it then, that Cycorder uses a different method than the one we are talking about here? If so, does anyone know the method used there? Personally, I don't care how it's done, so long as I can get to play with some AR.Last edited by OniDaito; 10-27-2009 at 10:10 AM. Reason: Automerged Doublepost
-
10-27-2009, 11:10 AM #52
I read in another forum the Cycorder does access the camera directly and also it uses the hardware MPEG encoder provided by the Infineon PMB8876 S-GOLD 2 chip onboard, but it seems Saurik doesn't want to share his secret, obviously...
-
10-27-2009, 11:23 AM #53
Yeah, he aint talkin' about that sort of thing. I suspect it's some evil, low-level c hacking with the Jailbreak stuff. It's certainly an option I'm considering anyway. Theres probably a /dev style device he's playing with. Regardless I'd like to use the non-jailbreak method but the removal of _camera is proving annoying. Damn you Apple!
-
11-16-2009, 09:36 AM #54
hope this help ...
Hey,
I'm using the same kind of code you used (with a _createPreviewIOSurface inside a timer), and I just found a way to superpose drawings without affecting the Preview image.
You just have to add a UIWindow, with a transparent view, and draw inside that view :
with MyImageView a UIView class in which I derived the drawRect method, and with a call to [faceImageView setNeedsDisplay] inside the timer method.Code:cameraController = [(id)objc_getClass("PLCameraController") performSelector:@selector(sharedInstance)]; [cameraController retain]; [cameraController setDelegate:self]; [cameraController setFocusDisabled:NO]; [cameraController setDontShowFocus:YES]; [cameraController setCameraMode:1]; previewView = [self.cameraController performSelector:@selector(previewView)]; [previewView retain]; previewView.center = CGPointMake(previewView.center.x, previewView.center.y + 43); [self.view addSubview:previewView]; myImageView = [[MyImageView alloc] initWithFrame:previewView.frame]; myImageView.center = CGPointMake(myImageView.center.x, myImageView.center.y + 20); myImageView.backgroundColor = [UIColor clearColor]; myWindow = [[UIWindow alloc] init]; [myWindow addSubview:myImageView]; [myWindows makeKeyAndVisible];
It's still not the best method ever to grab the camera buffer, but at least I can start displaying things without affecting my algorithm.
-
11-16-2009, 11:31 AM #55
Have I understood you rightly? Does this method allow you to sample the CameraView without sampling the stuff you draw over the top?
-
11-16-2009, 12:32 PM #56
yep, just an a new UIwindow and draw stuff you want inside it.
-
11-17-2009, 05:02 AM #57
Cant remember if I ever got the PLCameraController to work. I presume this is using iPhone SDK/OS 2?
I tried this but my self.cameraController is always null. I suspect there is something I'm missing; a framework maybe?
Sorry guys, just figured it out. PhotoLibrary framework for OS 3.1.2 fixes this to a degree.... I end up with a black screen with the classic white bar at the bottom. Argh!Last edited by OniDaito; 11-17-2009 at 05:09 AM. Reason: Automerged Doublepost
-
12-10-2009, 09:57 AM #58
Hi!
Have any of you seen the app Ustream Live Broadcaster from the App Store?
They make video live streaming!! And the performance is really good!
That means Apple now allows apps that make live streaming!
-
12-10-2009, 10:44 AM #59
It appears to be taking a sample of the camera, most likely with takePicture() calls. I can't see how fast the framerate is but its not brilliant (don't get me wrong though, I'm really impressed with the work). But, I suspect the overlays are being cropped out of the final frames sent to the server.
-
12-10-2009, 11:12 AM #60
Mmm... but I think takePicture() is not as fast as the streammed video, I will make some tests...
Any other way to take a sample of the camera, without using a private API?



LinkBack URL
About LinkBacks
Reply With Quote
