Using video input in Squeak

Bert Freudenberg bert at impara.de
Wed Jul 21 09:58:02 UTC 2004


Am 20.07.2004 um 18:26 schrieb Rob Hensley:

> Ultimately, what I want to do is a) convert the color image to B/W, b)
> set a threshold of what is "white" and what is "black" (that is,
> everything over a certain value -- let's say 123 -- will be considered
> white, and everything below will be considered black), and c) construct
> a Morph object out of the "black" part of the image. This Morph object
> will interact w/ the virtual balls (which are already done).

Like this?


| orgForm bwForm threshold thresholdMap rect morph |
"Make a dark shape on light ground"
Display getCanvas
	fillRectangle: (0 at 0 extent: 400 at 300) color: Color yellow;
	fillOval: (100 at 100 extent: 30 at 50) color: Color blue.
orgForm := Form fromUser.

"a) convert the color image to B/W"
bwForm := orgForm asGrayScale.

"b) set a threshold of what is 'white' and what is 'black'"
threshold := 123.
thresholdMap := (0 to: 255) collect: [:brightness |
	brightness < threshold
		ifTrue: [Color black]
		ifFalse: [Color white]].
bwForm colors: thresholdMap.

"c) construct a Morph object out of the 'black' part of the image."
bwForm := bwForm asFormOfDepth: 16. "bug?"
rect := bwForm rectangleEnclosingPixelsNotOfColor: Color white.
morph := Morph new.
morph bounds: rect; color: (Color red alpha: 0.5).

"display"
ImageMorph new
	image: bwForm;
	addMorph: morph;
	openInWorld.

"done"

- Bert -




More information about the Squeak-dev mailing list