Capture a photo on camera

Hello, 

I need to take a photo and focus between the shape boundaries. (similar to the image attached).

I would like to know if is it possible in corona to crop that specific shape and filter a person face shape? 

Hi @blablu1212,

This is currently possible on iOS, but not on Android. Or rather, you could accomplish it in Corona Enterprise for both platforms, but only on iOS using the base Corona SDK.

Best regards,

Brent

I am able to capture a photo by using:   media.capturePhoto()

I am trying to create the face shape as an image object to set over when camera is on and crop it after, but it’s not working the right way.
Please may you guide which method should i use?

Regards

Hi @blablu1212,

Take a look at the last example on this page…

https://docs.coronalabs.com/api/type/ShapeObject/fill.html

Hi @Brent,

Thank you for your guide. 
I tried the code and it looks like it works only for geometric shapes like rectangle or circle.

Because when i try to add an image of transparent background but with a face shape it looks all a white rectangle.

Hi @blablu1212,

From your original sample screenshot, I thought the idea was to have the photo (camera) on the large background rectangle, and then you place the white head/face outline with transparent background over the rectangle…

Brent

Hi @Brent,

Yes that’s the idea, i can place the camera on the rectangle background using shapeobject you guide me, but i can’t place the white head/face outline over it while camera is capturing the image. Because the idea is the white head outline will behave as a border to focus the human face, take the picture and crop it after.
Is this possible to achieve? 

Hi @blablu1212,

If you’re doing the “camera fill” on the rectangle, then it’s just another Corona display object. So, you can place the white outline on top using standard display group/object z-index ordering.

Brent

Thank you @Brent, it works that way an object over another, so i can use it right as an outline guide.

Excuse me if i insist one more time on getting it all clear: What about cropping the photo as an irregular shape (face shape) ?
Please can you assist me on knowing the right method?

Hi @Brent,

I created a group object to appear over on the screen when camera is on and seems like on a real device it doesn’t work.
Should i simplify this problem and open it as another question?

Thanks

Hi @blablu1212,

What device are you testing on?

Brent

@Brent I am testing on android device, samsung galaxy sII.

Here is the code i am using to display an object on the screen while camera is on.

But seems that the object i put over (in this case an image with transparent background) doesn’t appear when i test it on real device. 

If i create the object inside the “if media.hasSource” statement it won’t appear neither.

Please may you help.

– camera
local function onComplete( event )
local photo = event.target
print( "photo w,h = " … photo.width … “,” … photo.height )
end

if media.hasSource( media.Camera ) then
media.capturePhoto( { listener=onComplete } )
else
native.showAlert( “Corona”, “This device does not have a camera.”, { “OK” } )
end

– image group
local group = display.newGroup()
group.x=150
group.y=100

local myImage = display.newImage( “myimage.png” )
myImage.width=300
myImage.height=300
group:insert( myImage )

Hi @blablu1212,

As I mentioned in the second post of this thread, the “camera fill” feature is only available for iOS. It is not supported on Android at this time.

Brent

What’s happening, is that the device’s native camera is being opened at the point when you call media.capturePhoto(). This is leaving the Corona app’s environment and going to the device’s phone thread. From the docs:

Overview

Opens a platform-specific interface to the device’s camera. This function is asynchronous, meaning that it returns immediately so the calling code will continue to execute until the end of its scope; after that, the application will be suspended until the session is complete. 

You won’t be able to overlay a Corona display object over the camera view in this fashion. What you (I believe) want to do, is use the object.fill() API (as Brent referenced above) to have a “live feed” display object, and then overlay a Corona display object on that. See the below thread for more info on this:

https://forums.coronalabs.com/topic/58834-shapefill-typecamera

Hi @Alex@Panc,

Thank you for your detailed answer.
Yes that would make the trick, but object.fill it’s not able for android devices :frowning:
I need an alternative way to reach it, but seems like it’s not possible in corona.

Regards

Hi @blablu1212,

This is currently possible on iOS, but not on Android. Or rather, you could accomplish it in Corona Enterprise for both platforms, but only on iOS using the base Corona SDK.

Best regards,

Brent

I am able to capture a photo by using:   media.capturePhoto()

I am trying to create the face shape as an image object to set over when camera is on and crop it after, but it’s not working the right way.
Please may you guide which method should i use?

Regards

Hi @blablu1212,

Take a look at the last example on this page…

https://docs.coronalabs.com/api/type/ShapeObject/fill.html

Hi @Brent,

Thank you for your guide. 
I tried the code and it looks like it works only for geometric shapes like rectangle or circle.

Because when i try to add an image of transparent background but with a face shape it looks all a white rectangle.

Hi @blablu1212,

From your original sample screenshot, I thought the idea was to have the photo (camera) on the large background rectangle, and then you place the white head/face outline with transparent background over the rectangle…

Brent