Skip to content

Commit 63438d2

Browse files
committed
Check the image size captured by webcam
TODO: Add an API to webcam/v4l2, which returns the current capture size. Signed-off-by: kfei <kfei@kfei.net>
1 parent 221134f commit 63438d2

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

util.go

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,11 @@ func rgb2Gray(r, g, b byte) float64 {
4545
}
4646

4747
func scaleRGBArrayToGrayPixels(from []byte, tSize Size) []float64 {
48+
// Check the image size actually captured by webcam
49+
if size.Width*size.Height*3 > len(from) {
50+
log.Fatal("Pixels conversion failed. Did you specified a size " +
51+
"which is not supported by the webcam?")
52+
}
4853
// TODO: Improve this inefficient and loosy algorithm
4954
var to []float64
5055
skipX := size.Width / tSize.Width
@@ -80,7 +85,7 @@ func floatMin(x, y float64) float64 {
8085
func draw(ttyStatus <-chan string, wg *sync.WaitGroup) {
8186
defer wg.Done()
8287

83-
fmt.Println("Start streaming, press Ctrl-c to exit...")
88+
log.Println("Start streaming, press Ctrl-c to exit...")
8489
time.Sleep(3 * time.Second)
8590

8691
var chr string

0 commit comments

Comments
 (0)