Using video input in Squeak

Rob Hensley HensleyRj at Rockhurst.edu
Wed Jul 21 19:35:46 UTC 2004


First of all, thanks again for everyone's help; I am (slowly!) learning
so much with this project and am in love with Squeak! It is SO easy to
use!

I am extending the DShowVideoController class (from Diego Gomez Deck and
friends' plugin) and overwriting the initializeProcess method. This is
my code:

initializeProcess

	| bwFrame threshold thresholdMap |
	frame := Form extent: self decoderSize depth: Display depth.	
	process := [[true] whileTrue: [
		self decoderRequestCapture.
		frameSemaphore wait.
		self decoderCopyLastCapturedFrameInto: frame.
		bwFrame := frame asGrayScale.
		threshold := 123.
		thresholdMap := (0 to: 255) collect:
			[:brightness | 
				brightness < threshold
					ifTrue: [Color black]	
					ifFalse: [Color white]].
		bwFrame color: thresholdMap.
		frame := bwFrame.
	]] forkAt: self decoderProcessPriority.

When I run my class, I crash Squeak altogether (I get a ***System error
handling failed*** message). It looks to me that the problem is that
there is no color: method in the Form class. I have tried a variation,
using a ColorForm object (that does have a color: method). This is that
code:

initializeProcess

	| bwFrame threshold thresholdMap |
	frame := ColorForm extent: self decoderSize depth: 8.		

	"ColorForm objects seem to only want a depth of 8. Could this be
a 	problem?"

	process := [[true] whileTrue: [
		self decoderRequestCapture.
		frameSemaphore wait.
		self decoderCopyLastCapturedFrameInto: frame.
		bwFrame := frame asGrayScale.
		threshold := 123.
		thresholdMap := (0 to: 255) collect:
			[:brightness | 
				brightness < threshold
					ifTrue: [Color black]	
					ifFalse: [Color white]].
		bwFrame color: thresholdMap.
		frame := bwFrame.
	]] forkAt: self decoderProcessPriority. 

This approach doesn't result in the fatal crash, but I do get an "Error:
DirectShow: True" error. It appears to me that the call to the
decoderCopyLastCapturedFrameInto: method throws the error exception;
this is because the primDecoderCopyLastCapturedFrameInto: method in
DShowVideoDecoderPlugin fails if the depth is less than 16, which it is
in my case.

Is there an easy way to get around this? Could I make frame a Form and
bwFrame a ColorForm somehow? That way, frame would have a depth of more
than 16, and bwFrame could use it's color: method.

Thanks again,
Rob

-----Original Message-----
From: squeak-dev-bounces at lists.squeakfoundation.org
[mailto:squeak-dev-bounces at lists.squeakfoundation.org] On Behalf Of Bert
Freudenberg
Sent: Wednesday, July 21, 2004 4:58 AM
To: The general-purpose Squeak developers list
Subject: Re: Using video input in Squeak

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