Etoys: MorphicExtras-kfr.37.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.37.mcz

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

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

Name: MorphicExtras-kfr.37
Author: kfr
Time: 12 October 2011, 11:25:41 am
UUID: 9530e4c9-0e8e-bf44-af07-b7dadc8ec809
Ancestors: MorphicExtras-kfr.36

Remove methods and instance variables. We don't need so many settings

=============== Diff against MorphicExtras-kfr.36 ===============

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

Item was changed:
  RectangleMorph subclass: #WebCamMorph
+ instanceVariableNames: 'camNum camIsOn frameExtent captureForm displayForm frameCount liveDisplay autoSnapshot actualFPS resolution useFrameSize manualCapture captureDelayMs'
+ classVariableNames: ''
- instanceVariableNames: 'camNum camIsOn frameExtent captureDelayMs captureForm displayForm frameCount maxFPS skipFrames fxHolder fxEnabled liveDisplay autoCapture autoSnapshot startupDelay prevSkipFrames lastTime actualFPS resolution snapshotHolder useFrameSize overlayControls snapshotLimit lastCaptureTime minCaptureDelayMs manualCapture'
- classVariableNames: 'CaptureDelayMs'
  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 maxFps 'Maximum Frames Per Second'
- Number readWrite Player getMaxFPS Player setMaxFPS:)
  (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 effectsEnabled 'Apply effects or not' Boolean readWrite Player getIsFxEnabled Player setIsFxEnabled:)
- (slot effectsHolder 'Use to select which morph applies effects'
- Player readWrite Player getFxHolder Player setFxHolder:)
  (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 overlayControls 'If true mouse-over displays on-screen controls'
- Boolean readWrite Player getOverlayControls Player setOverlayControls:)
 
  "
  (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 applyEffects 'Apply effects')
  (command updateDisplay 'Update display')
+
- (slot skipFrames 'Number of frames to skip to get latest frame'
- Number readWrite Player getSkipFrames Player setSkipFrames:)
  ))
 
  (#'snapshot' (
+
+
- (slot snapshotHolder 'Set holder for snapshot storage' Player readWrite Player getSnapshotHolder Player setSnapshotHolder:)
- (slot snapshotLimit 'Camera #' Number readWrite Player getSnapshotLimit Player setSnapshotLimit:)
  (slot autoSnapshot 'When camera is on do automatic snapshots (up to limit)'
  Boolean readWrite Player getAutoSnapshot Player setAutoSnapshot:)
+
- (command takeSnapshot 'Take snapshot')
  "
  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.
 
  "
+
- CaptureDelayMs := 20.
  !

Item was removed:
- ----- Method: WebCamMorph>>applyFx:checkEnabled: (in category 'private') -----
- applyFx: aForm checkEnabled: aBoolean
- fxHolder == nil ifTrue: [^ aForm].
-
- ((aBoolean == true) & (fxEnabled == false)) ifTrue: [^ aForm].
-
- aForm bits: (
- self scanFxHolder: fxHolder frame: aForm
- ) bits copy.!

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

Item was changed:
  ----- 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.
- captureDelayMs := (captureDelayMs - 1) max: minCaptureDelayMs.
  (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 := skipFrames + 1.
  [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 changed:
  ----- Method: WebCamMorph>>captureStubWithFx:withDisplayUpdate: (in category 'private') -----
  captureStubWithFx: doFx withDisplayUpdate: doDisplayUpdate
+
- lastCaptureTime ifNotNil: [
- actualFPS := 1000 // (Time millisecondClockValue - lastCaptureTime)
- ].
- lastCaptureTime := Time millisecondClockValue.
-
  frameCount := frameCount + 1.
 
+
- doFx ifTrue: [self applyFx: captureForm checkEnabled: false].
  doDisplayUpdate ifTrue: [self updateDisplay: captureForm].
+
- autoSnapshot ifTrue: [self snapshotNow].
 
  !

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

Item was removed:
- ----- Method: WebCamMorph>>fxClear (in category 'e-toy - settings') -----
- fxClear
- fxHolder := nil!

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

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

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

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

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

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

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

Item was changed:
  ----- Method: WebCamMorph>>initialize (in category 'initialization') -----
  initialize
  super initialize.
 
  self color: Color red.
 
  camNum := 1.
  camIsOn := false.
+
+
- startupDelay := 1.
- captureDelayMs := CaptureDelayMs.
  frameCount := 0.
  manualCapture := false.
+ captureDelayMs := 20. "stepTime"
+
- maxFPS := 30.
- minCaptureDelayMs := 1000 // maxFPS.
  actualFPS := 0.
+
- skipFrames := 8.
  liveDisplay := true.
+
+
- fxHolder := nil.
- fxEnabled := false.
  useFrameSize := false.
+
- overlayControls := false.
 
+
- snapshotHolder := nil.
  autoSnapshot := false.
+
- snapshotLimit := 10.
 
  resolution := #'medium'.
  frameExtent := self class resolutionFor: resolution.
  self extent: frameExtent.
  captureForm := Form extent: frameExtent depth: 32.
  self updateDisplay: captureForm.
 
+
- lastCaptureTime := Time millisecondClockValue.
 
  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?"
- (Delay forSeconds: startupDelay) wait.
 
  "frameExtent := CameraInterface frameExtent: camNum.
  captureForm := Form extent: (CameraInterface frameExtent: camNum) depth: 32."
 
  self resetFrameCount.
+
+
- lastTime := nil.
- captureDelayMs := 20.
 
  camIsOn := true.
+
- lastCaptureTime := Time millisecondClockValue.
  "self startStepping."
 
  ^ true
  !

Item was removed:
- ----- Method: WebCamMorph>>setFxHolder: (in category 'e-toy - settings') -----
- setFxHolder: aMorph
- fxHolder := (aMorph == self ifTrue: [nil] ifFalse: [aMorph])
- !

Item was removed:
- ----- Method: WebCamMorph>>setIsFxEnabled: (in category 'e-toy - settings') -----
- setIsFxEnabled: aBoolean
- fxEnabled := aBoolean!

Item was removed:
- ----- Method: WebCamMorph>>setMaxFPS: (in category 'e-toy - settings') -----
- setMaxFPS: aNumber
- maxFPS := aNumber max: 1.
- minCaptureDelayMs := 1000 // maxFPS.
-
-
- !

Item was removed:
- ----- Method: WebCamMorph>>setOverlayControls: (in category 'e-toy - settings') -----
- setOverlayControls: aBoolean
- overlayControls := aBoolean
- !

Item was removed:
- ----- Method: WebCamMorph>>setSkipFrames: (in category 'e-toy - manual capture') -----
- setSkipFrames: aNumber
- skipFrames := aNumber max: 0
- !

Item was removed:
- ----- Method: WebCamMorph>>setSnapshotHolder: (in category 'e-toy - snapshot') -----
- setSnapshotHolder: aMorph
- snapshotHolder := (aMorph == self ifTrue: [nil] ifFalse: [aMorph])
- !

Item was removed:
- ----- Method: WebCamMorph>>setSnapshotLimit: (in category 'e-toy - snapshot') -----
- setSnapshotLimit: aNumber
- snapshotLimit < 0 ifTrue: [^ self].
- snapshotLimit := aNumber!

Item was removed:
- ----- Method: WebCamMorph>>snapshotNow (in category 'e-toy - snapshot') -----
- snapshotNow
- snapshotLimit > 0 ifFalse: [^ self].
- snapshotHolder ifNil: [^ self].
-
- snapshotHolder class == PasteUpMorph ifTrue: [
- snapshotHolder addMorphBack: (
- displayForm asMorph
- name: ('frame ', frameCount asString)
- ).
- ].
-
- snapshotHolder class == MovieMorph ifTrue:[
- snapshotHolder insertFrames: {
- (SketchMorph withForm: displayForm)
- position: snapshotHolder position
- }
- ].
-
- snapshotLimit := snapshotLimit - 1.
- !

Item was changed:
  ----- Method: WebCamMorph>>stepTime (in category 'stepping and presenter') -----
  stepTime
  "Answer the desired time between steps in milliseconds"
  ^ captureDelayMs
  !

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