Etoys: MorphicExtras-kfr.38.mcz

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

Etoys: MorphicExtras-kfr.38.mcz

commits-2
Karl Ramberg uploaded a new version of MorphicExtras to project Etoys:
http://source.squeak.org/etoys/MorphicExtras-kfr.38.mcz

==================== Summary ====================

Name: MorphicExtras-kfr.38
Author: kfr
Time: 12 October 2011, 9:09:51 pm
UUID: 3cf6cb5b-dbde-6341-a856-7deefb277f84
Ancestors: MorphicExtras-kfr.37

Removed most stuff now. Not much left, but now it should be easy to work with.

=============== Diff against MorphicExtras-kfr.37 ===============

Item was removed:
- ----- Method: Player>>captureFrame (in category '*MorphicExtras-WebCam') -----
- captureFrame
- costume captureFrameNow!

Item was removed:
- ----- Method: Player>>getActualFPS (in category '*MorphicExtras-WebCam') -----
- getActualFPS
- ^ costume getActualFPS!

Item was removed:
- ----- Method: Player>>getAutoSnapshot (in category '*MorphicExtras-WebCam') -----
- getAutoSnapshot
- ^ costume getAutoSnapshot
- !

Item was removed:
- ----- Method: Player>>getCamNum (in category '*MorphicExtras-WebCam') -----
- getCamNum
- | camNum |
- camNum := costume getCamNum.
- " self setName: 'Camera',camNum asString.
- " ^ camNum.
- !

Item was removed:
- ----- Method: Player>>getFrameCount (in category '*MorphicExtras-WebCam') -----
- getFrameCount
- ^ costume getFrameCount!

Item was removed:
- ----- Method: Player>>getIsLiveDisplay (in category '*MorphicExtras-WebCam') -----
- getIsLiveDisplay
- ^ costume getIsLiveDisplay!

Item was removed:
- ----- Method: Player>>getManualCapture (in category '*MorphicExtras-WebCam') -----
- getManualCapture
- ^ costume getManualCapture!

Item was removed:
- ----- Method: Player>>getWorldH (in category '*MorphicExtras-WebCam') -----
- getWorldH
- ^ costume getWorldH!

Item was removed:
- ----- Method: Player>>getWorldW (in category '*MorphicExtras-WebCam') -----
- getWorldW
- ^ costume getWorldW!

Item was removed:
- ----- Method: Player>>setAutoSnapshot: (in category '*MorphicExtras-WebCam') -----
- setAutoSnapshot: aBoolean
- costume setAutoSnapshot: aBoolean
- !

Item was removed:
- ----- Method: Player>>setCamNum: (in category '*MorphicExtras-WebCam') -----
- setCamNum: num
- costume setCamNum: num!

Item was removed:
- ----- Method: Player>>setFrameCount: (in category '*MorphicExtras-WebCam') -----
- setFrameCount: aNumber
- costume setFrameCount: aNumber!

Item was removed:
- ----- Method: Player>>setIsLiveDisplay: (in category '*MorphicExtras-WebCam') -----
- setIsLiveDisplay: aBoolean
- costume setIsLiveDisplay: aBoolean!

Item was removed:
- ----- Method: Player>>setManualCapture: (in category '*MorphicExtras-WebCam') -----
- setManualCapture: aBoolean
- costume setManualCapture: aBoolean!

Item was removed:
- ----- Method: Player>>updateDisplay (in category '*MorphicExtras-WebCam') -----
- updateDisplay
- costume updateDisplayNow!

Item was changed:
  RectangleMorph subclass: #WebCamMorph
+ instanceVariableNames: 'camNum camIsOn frameExtent displayForm resolution useFrameSize captureDelayMs'
- instanceVariableNames: 'camNum camIsOn frameExtent captureForm displayForm frameCount liveDisplay autoSnapshot actualFPS resolution useFrameSize manualCapture captureDelayMs'
  classVariableNames: ''
  poolDictionaries: ''
  category: 'MorphicExtras-WebCam'!
 
  !WebCamMorph commentStamp: '<historical>' prior: 0!
  INTRODUCTION
  =========
 
  WebCamMorph together with CameraPlugin (originally from MIT Scratch) provides an easy and cross platform way to use webcam input in Squeak and Etoys. The first version has been created specifically with Etoys in mind. To view a live feed simply drag a "WebCam" tile from the "WebCam" category in the objects tool. Open up a viewer on the morph and display the "camera settings" category to explore the following basic settings:
 
  "camera is on": turn the camera on/off.
 
  "camera number": usually the default of "1" is ok but if you have more than one camera connected then adjust between 1 and 9 for other instances of WebCamMorph.
 
  "max fps": leave as is for now. It is unusual for webcams to capture at higher than 30fps. See later for further explanation of how fps is controlled.
 
  "actual fps": read-only. Indicates the actual fps being achieved which can depend significantly on lighting conditions and capture resolution...
 
  "resolution": webcams can have a range of resolutions but for simplicity three are supported: "low" (160x120), "medium" (320x240) and "high" (640x480). Adjust in good lighting to see if "actual fps" increases.
 
  "use frame size": the resolution used for capturing can differ from the resolution used for display. If this setting is true then WebCamMorph is resized to match the camera resolution. If false then you are free to resize it however you want (via the "resize" halo button, use shift to preserve aspect ratio)
 
 
  Beyond viewing a live feed WebCamMorph has been designed to support different uses including simple effects, time-lapse photography, stop-motion animation, character recognition, motion detection and more complex processing of every frame for feature detection. The following information is to help you understand how and why WebCamMorph operates so you can adjust it for your particular needs.
 
 
  "FRAMES PER SECOND", LIGHTING & CAMERA RESOLUTION
  ==================================
 
  The maximum possible frame rate depends on many factors, some of which are outside of our control. Frame rates differ between cameras and usually depend significantly on chosen resolution and lighting conditions. To ensure a balance between capturing every available frame and keeping everything else responsive, WebCamMorph dynamically adjusts the delay between capturing one frame and the next (does not apply when in "manual capture" mode, see later).
 
  WebCams often include automatic compensation for lighting conditions. In low lighting it takes significantly more time for the camera to get a picture than it does in good lighting conditions. For example 30fps may be possible with good lighting compared to 7fps in low lighting. So for best capture rates ensure you have good lighting!!
 
  Cameras have a "native" resolution at which frame rates are usually better than for other resolutions. Note though that the native resolution might be *higher*
  than the *minimum* resolution available. It pays to experiment with different resolutions to find which one results in the highest frame rate. Use good lighting conditions when experimenting with resolutions.
 
 
  "MANUAL CAPTURE" MODE
  ===============
 
  In simply usage WebCamMorph automatically captures a frame and displays it. To support Etoys scripting a "manual capture" mode is provided where you or your script determines when to capture, when to apply effects (or not) and when to update the display. In between these steps you can do anything you want. Note that frames rates will be lower than that in automatic capture mode and that "skip frames" (described next) will need adjusting at very low capture rates.
 
  Tip: In manual mode the camera can be turned off. It will be turned on automatically when required and return to it's previous state after a frame has been captured. For capture periods of five seconds or more turning the camera off may save power, which can especially useful when running off batteries. For smaller periods leaving the camera on will avoid some delays and could help speed up webcam related scripts.
 
 
  "SKIP FRAMES"
  ========
 
  Webcams and their drivers are typically designed for streaming live video and use internal buffering to help speed things up. At low capture rates the picture can appear to lag real-time because what you see is the next available buffer not the *latest* buffer. So for example if you capture a frame every ten seconds and there are three buffers being used then what you actually see may be thirty seconds old. We have little/no control over the number of buffers used and the actual number can vary between cameras and under different circumstances for the same camera. "skip frames" is provided to compensate for buffering so increase it when doing "manual" capturing until you see what you expect to see. Typically a setting of 8 is enough but I have had to use 20 with one particular camera in low lighting.
 
 
  "SNAPSHOTS"
  ========
 
  Where as "capturing" is the process of getting an image from the Camera into Squeak/Etoys, a "snapshot" preserves whatever is currently displayed (which may be the captured image after effects have been applied). To store snapshots you need to designate a "holder" which at the moment can be either a "holder" morph or a "movie" morph. Create one of these before proceeding. To assign a holder open up a viewer for WebCamMorph, display the "snapshot" category and click in the box at the right of the entry called "snapshot holder". The cursor will now resemble a cross-hair and can be clicked on the target holder/movie morph. To take a single snapshot at any time click (!!) on the left of "take snapshot". In auto-capture mode WebCamMorph can also be set to take multiple consecutive snapshots . First, before turning the camera on, set a sensible limit using "snapshot limit" (to avoid using all the computers memory) then set "auto snapshot" to true. When the camera is next turned on then snapshots are taken for every frame until "snapshot limit" becomes zero. "snapshot limit" is automatically decremented but not reset to avoid problems (although you are free to reset it manually or via a script).
 
 
  "EFFECTS" - WIP
  =========
 
  Similar to snapshots, a holder can be designated as the "effects holder". This holder is intended to be populated with "fx" morphs (coming soon) which will operate on captured frames prior to displaying. Stay tuned ;-)
 
 
  CLEARING SNAPSHOT & EFFECTS HOLDERS
  =========================
 
  Keeping a link to snapshot or effects holders can tie up resources even after the target holders have been deleted and are no longer visible. To ensure this does not happen designate the WebCamMorph itself as the holder (for method see "snapshots" section above).
 
 
  COMING SOON!!
  =========
 
  - Built-in basic effects such as brightness, contrast and hue.
  - Image "fx" morphs for effects such as those found in MIT Scratch and many other types of effects/ image processing.
  - More snapshot options, eg, store to file
  - Demo projects
 
  !

Item was changed:
  ----- Method: WebCamMorph class>>additionsToViewerCategories (in category 'scripting') -----
  additionsToViewerCategories
  "Answer a list of (<categoryName> <list of category specs>) pairs that characterize the phrases this kind of morph wishes to add to various Viewer categories."
  ^ #(
  (#'camera settings' (
- (slot cameraNumber 'Camera #' Number readWrite Player getCamNum Player setCamNum:)
  (slot resolution '160x120, 320x240 or 640x480'
  WebCamResolution readWrite Player getWebCamResolution Player setWebCamResolution:)
-
  (slot cameraIsOn 'Whether the camera is on/off' Boolean readWrite Player getWebCamIsOn Player setWebCamIsOn:)
- (slot liveDisplay 'Update display on new frame' Boolean readWrite Player getIsLiveDisplay Player setIsLiveDisplay:)
-
-
  (slot useFrameSize 'Resize the morph to match the cameras frame size'
  Boolean readWrite Player getUseFrameSize Player setUseFrameSize:)
- (slot frameCount 'Number if frames since turned on' Number readWrite Player getFrameCount Player setFrameCount:)
- (slot actualFps 'Actual FPS' Number readOnly Player getActualFPS Player unused)
-
-
- "
- (slot highPerformance 'Faster display updates. Does not effect camera FPS. Uses more power!!'
- Boolean readWrite Player getHighPerformance Player setHighPerformance:)
- "
  ))
 
- (#'manual capture' (
- (slot manualCapture 'Set to true for scripting'
- Boolean readWrite Player getManualCapture Player setManualCapture:)
- (command captureFrame 'Get a frame')
-
- (command updateDisplay 'Update display')
-
- ))
-
- (#'snapshot' (
-
-
- (slot autoSnapshot 'When camera is on do automatic snapshots (up to limit)'
- Boolean readWrite Player getAutoSnapshot Player setAutoSnapshot:)
-
- "
- Other potential options:
- - format
- - diff (from ref frame, from previous frame)
- - to file
- "
- ))
-
- "Only here for convenience until reinstated in correct context"
- (#'temp' (
- (slot worldWidth 'world width' Number readOnly Player getWorldW Player unused)
- (slot worldHeight 'world height' Number readOnly Player getWorldH Player unused)
- ))
-
  )
  !

Item was changed:
  ----- Method: WebCamMorph class>>initialize (in category 'class initialization') -----
  initialize
  "CameraMorph initialize"
 
- " Smalltalk addToStartUpList: self.
- Smalltalk addToShutDownList: self.
 
- "
 
  !

Item was removed:
- ----- Method: WebCamMorph>>captureFrameAutoMode: (in category 'private') -----
- captureFrameAutoMode: autoMode
- | wasOn gotFrame nFrames |
-
- captureForm bits class == ByteArray
- ifTrue: [captureForm unhibernate].
-
- ">>>>>>>>>>>>>>>>>>>>>>>>>>"
- "STEPPING TRIGGERED CAPTURE >>>"
-
- autoMode ifTrue: [
- manualCapture ifTrue: [^ nil].
- self getWebCamIsOn ifFalse: [^ nil].
-
- captureDelayMs := (captureDelayMs - 1) max: 10.
- (CameraInterface getFrameForCamera: camNum into: captureForm bits) > 0
- ifFalse: [
- captureDelayMs := (captureDelayMs + 2) min: 500.
- ^ nil.
- ].
-
- self captureStubWithFx: true withDisplayUpdate: true.
-
- ^ captureForm.
- ].
-
-
- ">>>>>>>>>>>>>>>>>>>>>>>>>>"
- "MANUAL/SCRIPT TRIGGERED CAPTURE >>>"
-
- (wasOn := camIsOn) ifTrue: [
- manualCapture ifFalse: [^ nil].
- ].
- (self on) ifFalse: [^ nil].
-
- gotFrame := false.
- nFrames :=  10.
- [nFrames > 0] whileTrue: [
- (CameraInterface getFrameForCamera: camNum into: captureForm bits) > 0
- ifTrue: [gotFrame := gotFrame | true].
- nFrames := nFrames - 1.
- ].
- gotFrame ifFalse: [^ nil].
-
- self captureStubWithFx: false withDisplayUpdate: false.
-
- wasOn ifFalse: [self off].
-
- ^ captureForm.
- !

Item was removed:
- ----- Method: WebCamMorph>>captureFrameNow (in category 'e-toy - manual capture') -----
- captureFrameNow
- self captureFrameAutoMode: false.
- !

Item was removed:
- ----- Method: WebCamMorph>>captureStubWithFx:withDisplayUpdate: (in category 'private') -----
- captureStubWithFx: doFx withDisplayUpdate: doDisplayUpdate
-
- frameCount := frameCount + 1.
-
-
- doDisplayUpdate ifTrue: [self updateDisplay: captureForm].
-
-
- !

Item was removed:
- ----- Method: WebCamMorph>>defaultFloatPrecisionFor: (in category 'e-toy support') -----
- defaultFloatPrecisionFor: aGetSelector
- (#(#getActualFPS) includes: aGetSelector)
- ifTrue: [^ 0.01].
- "
- (#(#getMaxFPS #getFrameCount #getSkipFrames #getSnapshotLimit)
- includes: aGetSelector) ifTrue: [^ 0].
- "
- ^ super defaultFloatPrecisionFor: aGetSelector!

Item was changed:
  ----- Method: WebCamMorph>>delete (in category 'submorphs-add/remove') -----
  delete
  self off.
-
-
  super delete.!

Item was removed:
- ----- Method: WebCamMorph>>getActualFPS (in category 'e-toy - settings') -----
- getActualFPS
- ^ actualFPS
-
- !

Item was removed:
- ----- Method: WebCamMorph>>getAutoSnapshot (in category 'e-toy - snapshot') -----
- getAutoSnapshot
- ^ autoSnapshot!

Item was removed:
- ----- Method: WebCamMorph>>getCamNum (in category 'e-toy - settings') -----
- getCamNum
- ^ camNum!

Item was removed:
- ----- Method: WebCamMorph>>getFrameCount (in category 'e-toy - settings') -----
- getFrameCount
- ^ frameCount
- !

Item was removed:
- ----- Method: WebCamMorph>>getHighPerformance (in category 'e-toy - misc/temp') -----
- getHighPerformance
- ^ Preferences valueOfPreference: #higherPerformance
- !

Item was removed:
- ----- Method: WebCamMorph>>getIsLiveDisplay (in category 'e-toy - settings') -----
- getIsLiveDisplay
- ^ liveDisplay
- !

Item was removed:
- ----- Method: WebCamMorph>>getManualCapture (in category 'e-toy - manual capture') -----
- getManualCapture
- ^ manualCapture
- !

Item was changed:
  ----- Method: WebCamMorph>>getWebCamIsOn (in category 'e-toy - settings') -----
  getWebCamIsOn
+
- " ^ (camIsOn := CameraPlugin cameraIsOpen: camNum).
- "
  ^ camIsOn!

Item was removed:
- ----- Method: WebCamMorph>>getWorldH (in category 'e-toy - misc/temp') -----
- getWorldH
- ^ World height!

Item was removed:
- ----- Method: WebCamMorph>>getWorldW (in category 'e-toy - misc/temp') -----
- getWorldW
- ^ World width!

Item was changed:
  ----- Method: WebCamMorph>>initialize (in category 'initialization') -----
  initialize
  super initialize.
-
- self color: Color red.
-
  camNum := 1.
  camIsOn := false.
-
-
- frameCount := 0.
- manualCapture := false.
  captureDelayMs := 20. "stepTime"
-
- actualFPS := 0.
-
- liveDisplay := true.
-
-
  useFrameSize := false.
-
-
-
- autoSnapshot := false.
-
-
  resolution := #'medium'.
  frameExtent := self class resolutionFor: resolution.
+ displayForm := Form extent: frameExtent depth:32.
  self extent: frameExtent.
- captureForm := Form extent: frameExtent depth: 32.
- self updateDisplay: captureForm.
-
-
-
  self on.
 
  !

Item was changed:
  ----- Method: WebCamMorph>>on (in category 'accessing') -----
  on
+ camIsOn
+ ifTrue: [^ true].
+ "Avoid more than one WebCamMorph per
+ Camera "
+ (CameraInterface cameraIsOpen: camNum)
+ ifTrue: [^ false].
+ (CameraInterface
+ openCamera: camNum
+ width: frameExtent x
+ height: frameExtent y)
+ ifNil: [^ false].
+ (Delay forSeconds: 1) wait.
+ "why?"
- camIsOn ifTrue: [^ true].
-
- "Avoid more than one WebCamMorph per Camera"
- (CameraInterface cameraIsOpen: camNum) ifTrue: [^ false].
-
- (CameraInterface openCamera: camNum
- width: (frameExtent x)
- height: (frameExtent y)
- ) ifNil: [^ false].
-
- (Delay forSeconds: 1) wait."why?"
-
- "frameExtent := CameraInterface frameExtent: camNum.
- captureForm := Form extent: (CameraInterface frameExtent: camNum) depth: 32."
-
- self resetFrameCount.
-
-
-
  camIsOn := true.
+ self startStepping.
+ ^ true!
-
- "self startStepping."
-
- ^ true
- !

Item was removed:
- ----- Method: WebCamMorph>>resetFrameCount (in category 'accessing') -----
- resetFrameCount
- frameCount := 0!

Item was removed:
- ----- Method: WebCamMorph>>scanFxHolder:frame: (in category 'private') -----
- scanFxHolder: aMorph frame: aForm
- (aMorph respondsTo: #processNewFrame:) ifTrue: [
- ^ aMorph processNewFrame: aForm
- ].
-
- ^ aForm
- "
- aMorph class = #PasteUpMorph
- "!

Item was removed:
- ----- Method: WebCamMorph>>setAutoSnapshot: (in category 'e-toy - snapshot') -----
- setAutoSnapshot: aBoolean
- autoSnapshot := aBoolean!

Item was removed:
- ----- Method: WebCamMorph>>setCamNum: (in category 'e-toy - settings') -----
- setCamNum: num
- | isOn |
-
- ((camNum == num) or: [((1 to: 9) includes: num) not]) ifTrue: [^ self].
-
- isOn := camIsOn.
- self off.
- camNum := num.
- isOn ifTrue: [self on].
- !

Item was removed:
- ----- Method: WebCamMorph>>setFrameCount: (in category 'e-toy - settings') -----
- setFrameCount: aNumber
- frameCount := aNumber
- !

Item was removed:
- ----- Method: WebCamMorph>>setHighPerformance: (in category 'e-toy - misc/temp') -----
- setHighPerformance: aBoolean
- Preferences setPreference: #higherPerformance toValue: aBoolean
- !

Item was removed:
- ----- Method: WebCamMorph>>setIsLiveDisplay: (in category 'e-toy - settings') -----
- setIsLiveDisplay: aBoolean
- liveDisplay := aBoolean.
- " live
- ifTrue: [self startStepping]
- ifFalse: [self stopStepping]
- "!

Item was removed:
- ----- Method: WebCamMorph>>setManualCapture: (in category 'e-toy - manual capture') -----
- setManualCapture: aBoolean
- manualCapture := aBoolean
- !

Item was changed:
  ----- Method: WebCamMorph>>setWebCamResolution: (in category 'e-toy - settings') -----
  setWebCamResolution: aSymbol
  | wasOn |
 
  ((WebCamResolutionType resolutions) includes: aSymbol) ifFalse: [^ self].
  resolution := aSymbol.
 
  (wasOn := camIsOn) ifTrue: [self off].
  frameExtent := self class resolutionFor: aSymbol.
+
- captureForm := Form extent: frameExtent depth: 32.
  " self resetSize.
  " wasOn ifTrue: [self on].
 
 
  !

Item was changed:
  ----- Method: WebCamMorph>>step (in category 'stepping and presenter') -----
  step
+ self getWebCamIsOn ifFalse: [^ nil].
+ CameraInterface getFrameForCamera: camNum into: displayForm bits.
+ self changed!
- self captureFrameAutoMode: true
- !

Item was removed:
- ----- Method: WebCamMorph>>updateDisplay: (in category 'private') -----
- updateDisplay: aForm
- liveDisplay ifFalse: [^ self].
- displayForm := aForm deepCopy.
- self changed.
- !

Item was removed:
- ----- Method: WebCamMorph>>updateDisplayNoCheck: (in category 'private') -----
- updateDisplayNoCheck: aForm
- displayForm := aForm deepCopy.
- self changed.
- !

Item was removed:
- ----- Method: WebCamMorph>>updateDisplayNow (in category 'e-toy - manual capture') -----
- updateDisplayNow
- manualCapture ifFalse: [^ false].
- self updateDisplayNoCheck: captureForm
- !

_______________________________________________
etoys-dev mailing list
[hidden email]
http://lists.squeakland.org/mailman/listinfo/etoys-dev