I have used Wiebe Barons WebCamMorph and added some Etoy support to it. It is possible to track a color with the camera and a ellipse on the screen reflect the movement. I'll see if I can make it into a input feature like the eyeToy to the Playstation2. Enjoy
Karl
'From etoys2.3 of 1 December 2007 [latest update: #1891] on 4 February 2008 at 9:24:40 pm'! "Change Set: TrackColorWithCamera Date: 4 February 2008 Author: Karl Ramberg
A simple experiment to track colors with the camera. Use viewer to change tracking color and color tolerance. Based on Wiebe Barons WebCamMorph"!
VideoMorph subclass: #VideoColorTrackerMorph instanceVariableNames: 'trackColor ball colorTolerance ' classVariableNames: '' poolDictionaries: '' category: 'VideoForSqueak-Morphic'!
!Player methodsFor: '*VideoForSqueak-slot getters/setters' stamp: 'kfr 2/4/2008 16:53'! getColorTolerance "Answer the numeric value contained in my costume" ^ costume renderedMorph getColorTolerance! !
!Player methodsFor: '*VideoForSqueak-slot getters/setters' stamp: 'kfr 2/4/2008 16:55'! getTrackColor "Set the track color value in my costume" ^ costume renderedMorph getTrackColor! !
!Player methodsFor: '*VideoForSqueak-slot getters/setters' stamp: 'kfr 2/4/2008 16:55'! setColorTolerance: aNumber "Set the numeric value in my costume" ^ costume renderedMorph setColorTolerance: aNumber! !
!Player methodsFor: '*VideoForSqueak-slot getters/setters' stamp: 'kfr 2/4/2008 16:55'! setTrackColor: aColor "Set the track color value in my costume" ^ costume renderedMorph setTrackColor: aColor! !
!VideoColorTrackerMorph methodsFor: 'as yet unclassified' stamp: 'kfr 2/4/2008 13:17'! addOptionalHandlesTo: aHalo box: box super addOptionalHandlesTo: aHalo box: box. (aHalo addHandleAt: box rightCenter color: Color blue icon: 'Halo-Paint' on: #mouseDown send: #getColor to: self) ! !
!VideoColorTrackerMorph methodsFor: 'as yet unclassified' stamp: 'kfr 2/4/2008 17:00'! defaultFloatPrecisionFor: aGetSelector "Answer a number indicating the default float precision to be used in a numeric readout for which the receiver provides the data. Individual morphs can override this. Showing fractional values for readouts of getCursor was in response to an explicit request from ack" (#(#getColorTolerance ) includes: aGetSelector) ifTrue: [^ 0.01]. ^ super defaultFloatPrecisionFor: aGetSelector.! !
!VideoColorTrackerMorph methodsFor: 'as yet unclassified' stamp: 'kfr 2/4/2008 13:17'! getColor Cursor crossHair showWhile: [[Sensor redButtonPressed] whileTrue. [Sensor redButtonPressed] whileFalse: [World doOneCycle]. trackColor _ (Display colorAt: Sensor cursorPoint)]! !
!VideoColorTrackerMorph methodsFor: 'as yet unclassified' stamp: 'kfr 2/4/2008 16:51'! getColorTolerance ^colorTolerance! !
!VideoColorTrackerMorph methodsFor: 'as yet unclassified' stamp: 'kfr 2/4/2008 16:52'! getTrackColor ^trackColor! !
!VideoColorTrackerMorph methodsFor: 'as yet unclassified' stamp: 'kfr 2/4/2008 21:18'! initialize super initialize. trackColor := Color red. colorTolerance _ 0.2. ball := EllipseMorph new openInWorld! !
!VideoColorTrackerMorph methodsFor: 'as yet unclassified' stamp: 'kfr 2/4/2008 16:51'! setColorTolerance: aNumber colorTolerance _ aNumber! !
!VideoColorTrackerMorph methodsFor: 'as yet unclassified' stamp: 'kfr 2/4/2008 16:52'! setTrackColor: aColor trackColor _ aColor! !
!VideoColorTrackerMorph methodsFor: 'as yet unclassified' stamp: 'kfr 2/4/2008 21:18'! step "Track a color in the camera and move the ball acordingly" | avx avy div pos | super step. avx := avy := div := 0. 1 to: self scaledForm height by: 16 do: [:y | 1 to: self scaledForm width by: 16 do: [:x | (trackColor diff: (self scaledForm colorAt: x @ y)) < colorTolerance "tolerance for color difference" ifTrue: [self scaledForm colorAt: x @ y put: Color green. "show where trackColor is" avx := avx + x. avy := avy + y. div := div + 1]]]. div = 0 ifFalse: [pos := (Display width - (Display width / self scaledForm width * (avx // div)) @ (Display height / self scaledForm height * (avy // div))) rounded. ball position: ball position * 2 + pos // 3]! !
!VideoColorTrackerMorph class methodsFor: 'as yet unclassified' stamp: 'kfr 2/4/2008 17:03'! 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." ^ #( (video ( (slot trackColor 'The color to track in camera' Color readWrite Player getTrackColor Player setTrackColor:) (slot colorTolerance 'The tolerance of the track color' Number readWrite Player getColorTolerance Player setColorTolerance:) ) ) ) ! !
VideoMorph subclass: #VideoColorTrackerMorph instanceVariableNames: 'trackColor ball colorTolerance' classVariableNames: '' poolDictionaries: '' category: 'VideoForSqueak-Morphic'!
On Feb 4, 2008, at 21:31 , karl wrote:
I have used Wiebe Barons WebCamMorph and added some Etoy support to it. It is possible to track a color with the camera and a ellipse on the screen reflect the movement. I'll see if I can make it into a input feature like the eyeToy to the Playstation2. Enjoy
Not bad :) Here's a project version of this:
http://dev.laptop.org/~bert/camTrack.pr
Works nicely on the XO (if you have good lighting and a distinctly colored shape) ...
- Bert -
Bert Freudenberg wrote:
On Feb 4, 2008, at 21:31 , karl wrote:
I have used Wiebe Barons WebCamMorph and added some Etoy support to it. It is possible to track a color with the camera and a ellipse on the screen reflect the movement. I'll see if I can make it into a input feature like the eyeToy to the Playstation2. Enjoy
Not bad :) Here's a project version of this:
http://dev.laptop.org/~bert/camTrack.pr
Works nicely on the XO (if you have good lighting and a distinctly colored shape) ...
- Bert -
Cool. I tinkered a little more with this and added a setting for how many points should be scanned each scan. That fewer scanned points made morphic more responsive but jumpier movement of the ellipse. Next change will be to just return x and y values so any object can be hooked up to input.
Future enhancement is: - several colors scanned for, that would enable more advanced input like one for mouse click simulation and one for movement. -putting scanning in a primitive would really speed up everything and make even more stuff possible, like gestures, sign language ? etc.
Karl
On Feb 6, 2008, at 15:03 , Karl wrote:
Bert Freudenberg wrote:
On Feb 4, 2008, at 21:31 , karl wrote:
I have used Wiebe Barons WebCamMorph and added some Etoy support to it. It is possible to track a color with the camera and a ellipse on the screen reflect the movement. I'll see if I can make it into a input feature like the eyeToy to the Playstation2. Enjoy
Not bad :) Here's a project version of this:
http://dev.laptop.org/~bert/camTrack.pr
Works nicely on the XO (if you have good lighting and a distinctly colored shape) ...
- Bert -
Cool. I tinkered a little more with this and added a setting for how many points should be scanned each scan. That fewer scanned points made morphic more responsive but jumpier movement of the ellipse. Next change will be to just return x and y values so any object can be hooked up to input.
Future enhancement is:
- several colors scanned for, that would enable more advanced
input like one for mouse click simulation and one for movement. -putting scanning in a primitive would really speed up everything and make even more stuff possible, like gestures, sign language ? etc.
You might try (ab-)using BitBlt for this - for example, convert to 16 bit, then use a 32k entry tolerant color map to convert to b/w, then use #innerPixelRectFor:orNot: or #rectangleEnclosingPixelsNotOfColor: to find the rectangle enclosing the object ... Or with WarpBlt and smoothing you can reduce the image size while retaining colors ...
- Bert -
Bert Freudenberg wrote:
On Feb 6, 2008, at 15:03 , Karl wrote:
Bert Freudenberg wrote:
On Feb 4, 2008, at 21:31 , karl wrote:
I have used Wiebe Barons WebCamMorph and added some Etoy support to it. It is possible to track a color with the camera and a ellipse on the screen reflect the movement. I'll see if I can make it into a input feature like the eyeToy to the Playstation2. Enjoy
Not bad :) Here's a project version of this:
http://dev.laptop.org/~bert/camTrack.pr
Works nicely on the XO (if you have good lighting and a distinctly colored shape) ...
- Bert -
Cool. I tinkered a little more with this and added a setting for how many points should be scanned each scan. That fewer scanned points made morphic more responsive but jumpier movement of the ellipse. Next change will be to just return x and y values so any object can be hooked up to input.
Future enhancement is:
- several colors scanned for, that would enable more advanced
input like one for mouse click simulation and one for movement. -putting scanning in a primitive would really speed up everything and make even more stuff possible, like gestures, sign language ? etc.
You might try (ab-)using BitBlt for this - for example, convert to 16 bit, then use a 32k entry tolerant color map to convert to b/w, then use #innerPixelRectFor:orNot: or #rectangleEnclosingPixelsNotOfColor: to find the rectangle enclosing the object ... Or with WarpBlt and smoothing you can reduce the image size while retaining colors ...
- Bert -
I found a promising looking method: Form>>cgForPixelValue: pv orNot: not "Return the center of gravity for all pixels of value pv. Note: If orNot is true, then produce the center of gravity for all pixels that are DIFFERENT from the supplied (background) value"
The method has no senders but there is a example. I have to experiment. It's fun to browse around the image and look for stuff :-)
Karl
At Wed, 6 Feb 2008 11:45:50 +0100, Bert Freudenberg wrote:
On Feb 4, 2008, at 21:31 , karl wrote:
I have used Wiebe Barons WebCamMorph and added some Etoy support to it. It is possible to track a color with the camera and a ellipse on the screen reflect the movement. I'll see if I can make it into a input feature like the eyeToy to the Playstation2. Enjoy
Not bad :) Here's a project version of this:
http://dev.laptop.org/~bert/camTrack.pr
Works nicely on the XO (if you have good lighting and a distinctly colored shape) ...
This works pretty nicely (i.e., quite fast) with good precision on uniform background.
How does the color tolerance used BTW? Ah, ok it is cut-off for the results from #diff:... Then it works nicer than I would expect.
-- Yoshiki
etoys-dev@lists.squeakfoundation.org