Jump to content

[TOPIC: topicViewTemplate]
[GLOBAL: userSmallPhoto]
Photo

Camera Feeds as Textures
Started by Bryan01 Dec 19 2013 01:08 PM

45 replies to this topic
[TOPIC CONTROLS]
Page 1 of 2 1 2
[/TOPIC CONTROLS]
[modOptionsDropdown]
[/modOptionsDropdown]
[reputationFilter]
[TOPIC: post.html]
#1

Bryan01

[GLOBAL: userInfoPane.html]
Bryan01
  • Corona Staff
  • 95 posts
  • Jedi

I thought it would be useful to link here to the blog post on using the camera as a texture fill: http://www.coronalabs.com/blog/2013/12/19/holiday-surpril-time-effects/

 

The code snippet to set this up with a filter effect looks like the following:

 

 

 

local shape = display.newRect( 0, 0, 320, 480 )
shape.anchorX = 0
shape.anchorY = 0
shape.fill = { type="camera" }
shape.fill.effect = "filter.sobel"
 

 



[TOPIC: post.html]
#2

roboward

[GLOBAL: userInfoPane.html]
roboward
  • Pro
  • PipPipPip
  • 39 posts
  • Advanced Member

Hi Bryan- any chance it's going to be possible soon to feed the "camera" type into composites? Right now composites only take image files I believe. (For that matter, will we be able to feed snapshots or filtered images or even transformed images into composites?). 

 

Having a lot of fun with this feature right now- being able to use all the composite modes, not just the blend modes- will only increase that fun :)



[TOPIC: post.html]
#3

ksan

[GLOBAL: userInfoPane.html]
ksan
  • Pro
  • PipPipPipPipPipPip
  • 2,599 posts
  • Jedi

Ditto that! This is great fun and opens a lot of avenues. Something that was asked on the blog that might fall through the cracks... Is it possible to use the front facing camera instead? How can we select one or the other programmatically? Thanks!!!



[TOPIC: post.html]
#4

davidJames

[GLOBAL: userInfoPane.html]
davidJames
  • Pro
  • PipPipPipPipPipPip
  • 86 posts
  • Jedi

We're also interested in knowing if it's possible to use the front-facing camera and what the code would be for that.  Anyone at Corona who can chime in?



[TOPIC: post.html]
#5

Bryan01

[GLOBAL: userInfoPane.html]
Bryan01
  • Corona Staff
  • 95 posts
  • Jedi

We will take a look into supporting that in a future daily - at the moment it's back facing camera only.

[TOPIC: post.html]
#6

ksan

[GLOBAL: userInfoPane.html]
ksan
  • Pro
  • PipPipPipPipPipPip
  • 2,599 posts
  • Jedi

Great! Thanks for considering this. Appreciated.



[TOPIC: post.html]
#7

davidJames

[GLOBAL: userInfoPane.html]
davidJames
  • Pro
  • PipPipPipPipPipPip
  • 86 posts
  • Jedi

Also, it appears camera feeds only work in portrait orientation.  Would love to see the feature work for landscape orientation as well!



[TOPIC: post.html]
#8

abiasi

[GLOBAL: userInfoPane.html]
abiasi
  • Enterprise
  • Pip
  • 5 posts
  • Newbie

It seems a crash happens when the shape with the camera fill is deleted or the fill is changed to another type. Is there any way to turn off the camera fill or any workaround to avoid the crash?



[TOPIC: post.html]
#9

Rob Miracle

[GLOBAL: userInfoPane.html]
Rob Miracle
  • Corona Staff
  • 8,543 posts
  • Jedi

You may need to add some things to your build settings.  See this blog post:

 

http://www.coronalabs.com/blog/2013/11/05/tutorial-captureselect-photo-and-video/



[TOPIC: post.html]
#10

davidJames

[GLOBAL: userInfoPane.html]
davidJames
  • Pro
  • PipPipPipPipPipPip
  • 86 posts
  • Jedi

Hi Rob, I inserted this into our build.settings file but the camera feed still displays in portrait mode even though my device is set to landscape orientation.

iphone = {
   plist = {
      CoronaUseIOS7IPadPhotoPickerLandscapeOnlyWorkaround = true,
      CoronaUseIOS6IPadPhotoPickerLandscapeOnlyWorkaround = true,
      CoronaUseIOS7LandscapeOnlyWorkaround = true,
      CoronaUseIOS6LandscapeOnlyWorkaround = true,
   },
}


[TOPIC: post.html]
#11

abiasi

[GLOBAL: userInfoPane.html]
abiasi
  • Enterprise
  • Pip
  • 5 posts
  • Newbie

The app I'm testing with is portrait only.



[TOPIC: post.html]
#12

Bryan01

[GLOBAL: userInfoPane.html]
Bryan01
  • Corona Staff
  • 95 posts
  • Jedi

@davidjames At the moment portrait mode is the only supported orientation but we will add your request to our camera fill feature request list (along with front facing camera support).

@abiasi Can you post your sample code for changing/deleting the fill - we will use this to reproduce the issue.

[TOPIC: post.html]
#13

abiasi

[GLOBAL: userInfoPane.html]
abiasi
  • Enterprise
  • Pip
  • 5 posts
  • Newbie

Here's the project attached. When I run it on my iPhone 5S, the camera only captures 1 image, is not real time and when it switches from scene1 to scene2 it crashes after a few seconds.

Attached Files



[TOPIC: post.html]
#14

dmekersa

[GLOBAL: userInfoPane.html]
dmekersa
  • Pro
  • PipPipPipPipPipPip
  • 58 posts
  • Jedi

I confirm the camera fill is not refreshed in real time. It refresh only if I hide/show the app again (or display the notification menu and close it).

I'm currently downloading the last daily build, I saw something about 'CameraPaint update' in the change log...



[TOPIC: post.html]
#15

tschussler

[GLOBAL: userInfoPane.html]
tschussler
  • Pro
  • PipPipPip
  • 48 posts
  • Advanced Member

Huge vote for landscape support.  All but one of our apps are in landscape orientation and in particular all of the apps where we would use this feature.



[TOPIC: post.html]
#16

mpappas

[GLOBAL: userInfoPane.html]
mpappas
  • Enterprise
  • PipPipPipPipPipPip
  • 515 posts
  • Jedi

@dmekersa -- I am getting the same behavior, camera feed not updating, but it does if you suspend/resume (Build 2171).

 

I noticed something further - If I update the coordinates of *anything* on the screen (move the camera feed rectangle a bit, or even an onscreen button by 1 pixel), then the camera feed updates. But just for 1 frame - while the other object is updating. If you move something a pixel later, again the camera feed updates at that time.

 

So I'm guessing the camera feed by itself doesn't trigger the SDK to update/refresh the openGL buffers, or something along those lines.

 

Something else onscreen must update/move to trigger the cascade of openGL buffer goodness. Well, until coronaLabs starts making live camera feeds force screen updates, me thinks...



[TOPIC: post.html]
#17

roboward

[GLOBAL: userInfoPane.html]
roboward
  • Pro
  • PipPipPip
  • 39 posts
  • Advanced Member

I've been putting a 1 pixel circle at .004 alpha moving back and forth on the screen to get live camera. Works well enough I suppose...



[TOPIC: post.html]
#18

Bryan01

[GLOBAL: userInfoPane.html]
Bryan01
  • Corona Staff
  • 95 posts
  • Jedi

We will look into this. A possible work-around is to call: display.setDrawMode( "forceRender" ). It overrides several optimizations in rendering to redraw the scene.



[TOPIC: post.html]
#19

mpappas

[GLOBAL: userInfoPane.html]
mpappas
  • Enterprise
  • PipPipPipPipPipPip
  • 515 posts
  • Jedi

@robo -- it's good enough for now, we can move ahead with our code.

 

I think an important thing here is this:

 

If we can identify the issues (in beta features like this), and help them to isolate and home in on the technicalities, then we all win.

 

And CoronaLabs is listening.

 

So hopefully in the end, we all win.

 

PS: Note that my meaning is that: CornoaLabs intends for camera feeds / textures to update automatically independent of other objects, and our proposed "workaround" behavior is understood by all, CL too, as temporary until the issues, if any, are resolved. Your mileage may vary.



[TOPIC: post.html]
#20

ksan

[GLOBAL: userInfoPane.html]
ksan
  • Pro
  • PipPipPipPipPipPip
  • 2,599 posts
  • Jedi

@mpappas, well said. This has been precisely my experience most recently in the graphics.newOutline API question I posted. 



[TOPIC: post.html]
#21

c.mihai

[GLOBAL: userInfoPane.html]
c.mihai
  • Pro
  • Pip
  • 2 posts
  • Newbie

regarding the landscape vs portrait issue : I created a shape with the camera feed texture and width = wanted_height, height = wanted_width and then just rotated it -90 °, and it seems to work :) I also wobbled a pixel to get the feed in realtime and not just one frame at a time. 



[TOPIC: post.html]
#22

mpappas

[GLOBAL: userInfoPane.html]
mpappas
  • Enterprise
  • PipPipPipPipPipPip
  • 515 posts
  • Jedi

Oh, another bug I thought I saw posted about the feeds, but after looking back, I don't see it mentioned by anyone, so while we're piling on the feeds here... Anyone else seeing this one?

-

I put the feed on a rectangle. Great, works good (as long as something else is updating on screen of course, otherwise the feed never updates -- already discovered). Put poverlays on top, works great. Mask the feed object, works great. Everything works great... Until.

-

The user changes screens, and I call display:remove() or object:removeSelf(). Shortly I release() the screen that had the feed (and construct/display the new screen), I get a hard crash on iOS -- "Bus Error: 10".

 

I had tried several ways to disengage the feed from the OS before the remove() (like setting isVisible = false, setting.fill = "" / nil, using a timer.delay to allow the graphics update, etc), but couldn't isolate a method that would get around it...  So I switched to the "if you can't beat them, join them" strategy again (like for the other bug, just keep something moving)...

 

To prevent the crash (actually to prevent the removal of the feed), when the screen with the feed exits it now creates a global feedgroup and inserts the feed rect into it, then places the group object WAY offscreen so it wont be seen, makes it invisible, etc. (Next time it reloads it checks if the feed already exists, and re-uses it).

 

With both bugs (feed not updating, and the bus error bug), I've got more workaround code than I'd like, but hey, I'm still moving forward onto more screens.

 

Anyways -- anyone else seeing bus error 10: when removing your feed yet?



[TOPIC: post.html]
#23

dmekersa

[GLOBAL: userInfoPane.html]
dmekersa
  • Pro
  • PipPipPipPipPipPip
  • 58 posts
  • Jedi

Did not try yet... Why don't you use Composer and do not recycle the scene when hidden (it keeps the objects in memory, just hide them)?

You should submit a sample to bug report no? It could help to get this feature fixed. It's amazing how new features are published and then not updated like this... I got a similar issue with the iTunes plugin, I had to create a project to show the bug, I hope they will fix one day...



[TOPIC: post.html]
#24

samwit

[GLOBAL: userInfoPane.html]
samwit
  • Pro
  • PipPipPip
  • 35 posts
  • Advanced Member

+1 for front facing camera



[TOPIC: post.html]
#25

warrenwsav

[GLOBAL: userInfoPane.html]
warrenwsav
  • Pro
  • PipPipPipPipPipPip
  • 514 posts
  • Jedi

I definitely note for the landscape feature. But mihal's solution of rotating it may work for now. I plan to try this tonight.

 

Warren




[topic_controls]
Page 1 of 2 1 2
 
[/topic_controls]