camera programming in black berry - blackberry

my following code returns null ,
byte[] image1 = _videoControl.getSnapshot(null);
any suggestion please

Few important moments about VideoControl.getSnapshot method:
some manufacturers may not implement getSnapshot() method;
the viewfinder must actually be visible on the screen prior to calling getSnapShot();
if you attempt to take pictures too quickly, however, getSnapShot() may
return null. The camera requires time to clear out its buffer and
prepare for the next shot;
you may check MMAPI System Property for "video.snapshot.encodings" before capturing:
if (System.getProperty("video.snapshot.encodings") == null) {
// getSnapshot() is not supported
}
You may read this chapter from book "Advanced BlackBerry Development":
http://books.google.com/books?id=F4Qu-lpoVncC&pg=PA53&lpg=PA53#v=onepage&q&f=false

Since VideoControl.getSnapshot method is not supported by all devices I'd recommend to use another approach. You can start the native BB Camera app with this line of code:
Invoke.invokeApplication(Invoke.APP_TYPE_CAMERA, new CameraArguments());
and then using the FileSystemJournalListener catch the taken image.
The BB SDK on your PC contains samples. Search for 'fileexplorerdemo' sample to see the rest of details.

Related

ML kit face recognition not working on IOS

I'm working on an app that does facial recognition. One of the steps include detecting the user smile. For that, I am currently using google's Ml Kit. The application works fine on Android platform but when I run on Ios (Iphone Xr and others) it does not recognize any faces on any image. I have already followed every steps on how to integrate Ios and Firebase and it runs fine.
Here's my code. It's always falling on length == 0, as the image would not contain any faces. The image passed as parameter is coming from the image_picker plugin.
Future<Face> verifyFace(File thisImage) async {
var beforeTime = new DateTime.now();
final image = FirebaseVisionImage.fromFile(thisImage);
final faceDetector = FirebaseVision.instance.faceDetector(
FaceDetectorOptions(
mode: FaceDetectorMode.accurate,
enableClassification: true,
),
);
var processedImages = await faceDetector.processImage(image);
print('Processing time: ' +
DateTime.now().difference(beforeTime).inMilliseconds.toString());
if (processedImages.length == 0) {
throw new NoFacesDetectedException();
} else if (processedImages.length == 1) {
Face face = processedImages.first;
if(face.smilingProbability == null){
throw new LipsNotFoundException();
}
else {
return face;
}
} else if (processedImages.length > 1) {
throw new TooManyFacesDetectedException();
}
}
If someone has any tips or can tell what I am doing wrong I would be very grateful.
I know this is an old issue, but I was having the same problem and turns out I just forgot to add the pod 'Firebase/MLVisionFaceModel' in the podfile.
there is configuration in some many places so i will better left you this video (although maybe you already see it) so you can see some code and how Matt Sullivan make that one you are trying to do.
let met know if you already see it and please add maybe an example repo i could work with so see you exact code.
From what I can tell, ML Kit face detection does work on iOS but very poorly.
It doesn't even seem worth it to use the SDK.
The docs do say that the face itself must be at least 100x100px. In my testing though the face itself needs to be at least 700px for the SDK to detect the face.
The SDK on Android works super well even on small image sizes (200x200px in total).

Paste a copied image into an AIR iOS app?

Is it possible to paste a copied image from the Safari browser to an Adobe AIR built iOS app?
I tried it with this image but couldn't find a solution yet.
Below is a screenshot of the copy button from the Safari browser on iOS 8:
Yes and no. You can't use the native dialogs or handling, but I believe you can access the data in the clipboard, even if it is an image.
You'll want to use Clipboard#getData() with a format of ClipboardFormats.BITMAP_FORMAT. That will give you access to the raw image data in a BitmapData object. You can then draw that BitmapData to a Bitmap container (or Image/BitmapImage if using Flex). You'll have to include a separate button for instantiating the paste process, but that isn't difficult to do.
Untested, but this should be a good place to start:
pasteButton.addEventListener(MouseEvent.CLICK, this.pasteEventHandler);
function(e:MouseEvent):void {
var clipboard:Clipboard = new Clipboard()
var bd:BitmapData = clipboard.getData(ClipboardFormats.BITMAP_FORMAT);
bitmap.bitmapData = bd;
}
I believe you'll need to handle errors in there as well, since the clipboard could contain text would either throw an error on the getData() line or return null.

How to get current stream position using GoogleCast frameWork in iOS

I am working on an application in which I will connect to the T.V using ChromeCast device, to achieve this I have used GoogleCast FrameWork in my project,
I am facing a problem when I try to access the approximate stream position of the video using the below statements,
GCKMediaControlChannel *mediaControlChannel = [[GCKMediaControlChannel alloc] init];
NSLog(#"Approximate stream position is %f",mediaControlChannel.approximateStreamPosition);
But this is resulting in a time difference of 20 seconds.
I tried below statements to get the exact stream position,
GCKMediaStatus *deviceStatus = [[GCKMediaStatus alloc] initWithSessionID:sessionId mediaInformation:self.mediaInformation];
NSLog(#"Stream Position %f", self.deviceStatus.streamPosition);
As the above method is having two parameters,We need to send session as an integer, but we are getting session id as a string alpha numeric and upon converting this to integer resulting in 0.
Can any one help me to get the session ID as an integer, Or suggest me to get the current stream position with any different method.
I use the following code to retrieve the stream position of the video that is currently being casted, and it's pretty accurate! The Google Cast SDK version that we use in our project is 3.5.3.
let position = Double(GCKCastContext.sharedInstance().sessionManager.currentSession!.remoteMediaClient!.mediaStatus!.streamPosition)
Hope it helps!
approximateStreamPosition should give you a pretty accurate time, certainly not off by 20 seconds. You can take a look at our iOS reference app for an example.
You can use approximateStreamPosition for the same.
Below code will print the more accurate time.
if let position = GCKCastContext.sharedInstance().sessionManager.currentSession?.remoteMediaClient?.approximateStreamPosition() {
print("current time ",position)
}

Flex/Flash Builder/Actionscript/AIR/Mobile iOS How to take video using the camera and/or browse for & view/access video stored in the 'Camera Roll"

My understanding currently is that:
CameraUI
I can use the CameraUI to access the built in camera for MediaType.VIDEO and that delegates to the built-in video camera app and lets me record a video. My app does that now.
When I stop recording and click the "Use" button, I am returned to my app and theoretically I have a valid MediaPromise.
iOS does -not- provide a valid/usable url/filename to the recorded video (or to photos) and so I would have to use a Loader to bring-in/use/access the 'recorded' video... AND... iOS does not actually create a file anywhere on the device, most importantly, in the Camera Roll where one would expect by the normal behavior when uses the system native camera/video app.
The documentation says that the Loader can load various image types and SWFs but nothing about video data, so I conclude from that that I cannot actually use the CameraUI to generate a valid MediaPromise that I can then pass to a Loader class or similar to read in the information created by the system camera and then manipulate (upload, save to applicationStorageDirectory, and/or display in one of the two video player components available in the API).
CameraRoll
I can have video entities in the iOS Camera Roll but the AS3/Air3.5 CameraRoll class won't let me view/access/reference them in any way.
Normal File I/O
All my attempts to use the Air3.5 File classes to browse to the storage location of the iOS Camera Roll have been rebuffed.
------- Questions -------
Am I correct in believing that there is a way to take video but no way to use the video that's been captured. (No way to use the resulting MediaPromise successfully).
I believe you can take video and access it using Android, but there's nothing in the documentation that says that you cannot using iOS.
Am I correct in believing that iOS sandboxes apps so that they cannot browse to video/photo storage using standard File I/O, but only through the apparently non-workable means I've tried (CameraUI & CameraRoll)
Am I wrong to think that these should be rather obvious NEEDS that one can achieve using the XCode Objective C++ etc route but the AIR Mobile Framework does not allow either because of Apple blocking functionality or because Adobe has failed to meet reasonable expectations?
One item of ironic note to convey. If I use the iOS system camera app to record a video, a thumnail of that video then appears in the Gallery/Camera Roll, and of course, I can share it or view it, or whatever... If I use AIR's CameraRoll.browseForImage(), provided I haven't used the camera to take another image, when it shows me the folder where the pictures are stored, the folder icon uses the thumbnail of the last object added... in this case, the video I took, but if I then enter the folder, the video cannot be found. It's teasing us. It knows it's there, but it is apparently forbidden fruit.
I can't answer all your questions, so this entry may not be acceptable, but I found this page while searching a solution for some the problems you described and thought that someone else may find this answer (partially) useful.
To save the movie you just took you need to open and read the data from the promise.
The iOS won't save the file anywere, so the MediaPromise.file is always null.
This is my solution to the problem:
private var camera:CameraUI;
private var dataInput:IDataInput;
public function recordVideo():void
{
// Start the camera and ask for a video
camera = new CameraUI();
camera.addEventListener(MediaEvent.COMPLETE, onCameraComplete);
camera.launch(MediaType.VIDEO);
}
private function onCameraComplete(event:MediaEvent):void
{
// event.data is a MediaPromise and MediaPromise.open() returns a IDataInput
// Let's cast it to a dispatcher and check when it's complete
dataInput = event.data.open();
var dispatcher:IEventDispatcher = IEventDispatcher(dataInput);
dispatcher.addEventListener(Event.COMPLETE, onDataInputComplete);
}
private function onDataInputComplete(event:Event):void
{
// We can do whatever we want with the data, so we'll store it in a File
var file:File = new File();
var bytes:ByteArray = new ByteArray();
var stream:FileStream = new FileStream();
// Reading the data from the opened MediaPromise
dataInput.readBytes(bytes);
stream.open(file, FileMode.WRITE);
stream.writeBytes(bytes, 0, bytes.bytesAvailable);
stream.close();
}
Also, I'm still looking for a way to put the movie in the CameraRoll

Black berry camera programming

I want take pictures using black berry camera for my app, it is possible in v5.0 and yes then how?
Yes it is definitely possible, but not a very simple task if you don't get some advice up front.
First and foremost, there is some sample code that is shipped with the Eclipse package at least (CameraDemo) that shows how to create a viewfiender using a Field, Player, and VideoScreen. The biggest issue is third party developers cannot overlay anything on top of the view finder (which is the what they'll call the Field after you set it as such with a VideoControl.
Also, you are very limited to what size you can set the Field -- I only got half size and fullscreen working, some dimensions got ignored and others caused it to not be displayed at all.
Here is some code that shows this:
private Field _videoField;
private Player _player;
private VideoControl _videoControl;
private void initCamera() {
try{
_player = Manager.createPlayer( "capture://video??encoding=jpeg&width=640&height=480" );
_player.realize();
_player.prefetch();
_videoControl = (VideoControl)_player.getControl("VideoControl");
_player.start();
if (_videoControl != null){
_videoField = (Field) _videoControl.initDisplayMode (VideoControl.USE_GUI_PRIMITIVE, "net.rim.device.api.ui.Field");
_videoControl.setDisplayFullScreen(true);
add(_videoField);
}
}
catch(Exception e)
{
//show error
}
}
After you do this you can use
byte[] image = _videoControl.getSnapshot(sizeAndEncodingParamters);
to snap the picture. To determine what sizeAndEncodingParameters your device supports, you can use System.getProperty("video.snapshot.encodings"); which will return a String[] that you can iterate over to determine what to use.
Take a look at samples that come with the BB SDK installation on your PC. There is CameraDemo sample. You can just try searching for CameraDemo.java on your HDD if you're unsure where those samples are.

Resources