LinuxQuestions.org
Visit Jeremy's Blog.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Hardware
User Name
Password
Linux - Hardware This forum is for Hardware issues.
Having trouble installing a piece of hardware? Want to know if that peripheral is compatible with Linux?

Notices


Reply
  Search this Thread
Old 01-10-2019, 07:49 PM   #1
lazardo
Member
 
Registered: Feb 2010
Location: SD Bay Area
Posts: 270

Rep: Reputation: Disabled
fswebcam consistent image capture


After spending way too much time on this for a development project, maybe someone else will find it useful.

Cheers,
Code:
$ v4l2-ctl -D
Driver Info (not using libv4l2):
	Driver name   : uvcvideo
	Card type     : UVC Camera (046d:0819)
	Bus info      : usb-0000:00:1d.7-2
	Driver version: 4.1.39
	Capabilities  : 0x84200001
		Video Capture
		Streaming
		Device Capabilities
	Device Caps   : 0x04200001
		Video Capture
		Streaming
Code:
$ v4l2-ctl -L
                     brightness (int)    : min=0 max=255 step=1 default=128 value=86
                       contrast (int)    : min=0 max=255 step=1 default=32 value=43
                     saturation (int)    : min=0 max=255 step=1 default=32 value=0
 white_balance_temperature_auto (bool)   : default=1 value=1
                           gain (int)    : min=0 max=255 step=1 default=0 value=33
           power_line_frequency (menu)   : min=0 max=2 default=2 value=2
				0: Disabled
				1: 50 Hz
				2: 60 Hz
      white_balance_temperature (int)    : min=0 max=10000 step=10 default=4000 value=10000 flags=inactive
                      sharpness (int)    : min=0 max=255 step=1 default=53 value=51
         backlight_compensation (int)    : min=0 max=1 step=1 default=0 value=0
                  exposure_auto (menu)   : min=0 max=3 default=3 value=3
				1: Manual Mode
				3: Aperture Priority Mode
              exposure_absolute (int)    : min=1 max=10000 step=1 default=166 value=418 flags=inactive
         exposure_auto_priority (bool)   : default=0 value=1
Code:
ROTATE=-1.57
TTE=68x64+147+58
TRH=56x50+150+127
ETE=44x46+117+206
ERH=46x45+193+207

FS_BRIGHT=34
FS_CONT=17
THRESH=18

fswebcam --quiet -d v4l2:/dev/video0 --no-banner \
	-F 15 -S 15 -D 1 -p YUYV --png 9 \
	-s brightness=${FS_BRIGHT}% -s contrast=${FS_CONT} - |
convert - -rotate $ROTATE -threshold ${THRESH}% \
	-colorspace gray -background white \
	-alpha remove -alpha off +dither -posterize 2 -flatten - |
tee \
	>( cat > envchk.raw.png ) \
	>( convert - -crop $TTE tte.png ) \
	>( convert - -crop $TRH trh.png ) \
	>( convert - -crop $ETE ete.png ) \
	>( convert - -crop $ERH erh.png ) \
	> /dev/null

for i in {0..10}; do
	[[ -s tte.png && -s trh.png && -s ete.png && -s erh.png ]] && break
	sleep 0.33
done

for i in tte trh ete erh; do
	ssocr -C -c digits -d -1 -T $i.png || echo "bad value"
done
Details:
Code:
fswebcam:
-d device		# in this case, Logitech C210 USB and a laptop built-in
-F framerate		# camera and region specific
-S skip frames		# USB cameras need settle time 
-D delay		# USB cameras need delay also
-p camera palette	# 'auto' didn't work
--png 9			# use png over jpg
-s brightness		# adjust for light conditions (don't use 'auto')
-s contrast
Code:
convert:
-rotate			# used gimp 'rotate' tool to find value
-threshold		# adjust value for image (don't use 'auto')
-colorspace gray	# these manage png files and remove color artifacts
 thru
-flatten
Operational theory:

1. fswebcam parameters grab a consistent image. Output piped to:
2. convert (imagemagick) to process image. Output is piped to:
3. tee for parallel processing:
3a. save primary and secondary images
3b. crop four individual numbers
4. sleep delay required else incomplete images.
5. Use 'ssocr' to translate image segments to usable values
6. If 'ssocr' doesn't return correct values, play with brightness, constrast and threshold first.

Last edited by lazardo; 01-10-2019 at 07:50 PM.
 
Old 01-12-2019, 08:57 AM   #2
BW-userx
LQ Guru
 
Registered: Sep 2013
Location: Somewhere in my head.
Distribution: Slackware (15 current), Slack15, Ubuntu studio, MX Linux, FreeBSD 13.1, WIn10
Posts: 10,342

Rep: Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242
I am getting just an white image, so I looked up the commands for imagemagick and added -channel played with the threshold and now I am getting some black in the images.

Code:
FS_BRIGHT=34
FS_CONT=17
THRESH=12
dname=webcam-shot.png

fswebcam --quiet -d v4l2:/dev/video0 --no-banner \
	-F 15 -S 15 -D 1 -p YUYV --png 9 $dname \
	-s brightness=${FS_BRIGHT}% -s contrast=${FS_CONT} - | \
convert - -rotate $ROTATE -channel red -threshold ${THRESH}% \
	-colorspace gray -background white \
	-alpha remove -alpha off +dither -posterize 2 -flatten - |
tee \
	>( cat > $dname ) \
	>( convert - -crop $TTE tte.png ) \
	>( convert - -crop $TRH trh.png ) \
	>( convert - -crop $ETE ete.png ) \
	>( convert - -crop $ERH erh.png ) \
	> /dev/null
running just this
Code:
#!/bin/bash

set -x

ROTATE=-1.57
TTE=68x64+147+58
TRH=56x50+150+127
ETE=44x46+117+206
ERH=46x45+193+207

FS_BRIGHT=34
FS_CONT=17
THRESH=12
dname=webcam-shot.png


fswebcam --quiet -d v4l2:/dev/video0 --no-banner \
	-F 15 -S 15 -D 1 -p YUYV --png 9 $dname \
	-s brightness=${FS_BRIGHT}% -s contrast=${FS_CONT} - | \
	convert - -rotate $ROTATE -channel red -threshold ${THRESH}% $dname
I can actually see me from my laptop webcam with the red channel having been manipulated.

using that threshold maybe forgetting to pick the channel red,green,blue leaves it whatever it leaves it then with no real bases to work with when you add your black and white -- basically white maybe the only thing it has to work with.

I am not versed in image manipulations.

but if you are going to just turn it back and white in the end then what are you doing messing with the threshold for? it seems redundant to me.

removing all of the colors then calling to have it posterized on a black and white image.

I have not tested all the way down to that, but it still seems if one has a black and white image then how is one suspect to get reds and greens and blues out of it to be posterized?

Code:
-posterize levels

reduce the image to a limited number of color levels per channel.

Very low values of levels, e.g., 2, 3, 4, have the most visible effect.
it has nothing to work with, but as I said, I am not versed in image manipulations. So i might be talking out my butt.

MOD:
messing with it still, if you use the code I tore down in the second code posted then add -posterize 2 to the last line, and change the name of the image so I can compare them. I see a definite difference between the two images.
Code:
convert - -rotate $ROTATE -channel red -threshold ${THRESH}% -posterize 2  $dname
this will give you an actual image you can make out, and I changed it to resize, cropping only gives you a little peice of the image, leaving it unreconziable to what it was.

Code:
#!/bin/bash

set -x

ROTATE=-1.57
TTE=68x64+147+58
TRH=56x50+150+127
ETE=44x46+117+206
ERH=46x45+193+207

FS_BRIGHT=34
FS_CONT=17
THRESH=3
dname=webcam-shot.png

fswebcam --quiet -d v4l2:/dev/video0 --no-banner \
	-F 15 -S 15 -D 1 -p YUYV --png 9 \
	-s brightness=${FS_BRIGHT}% -s contrast=${FS_CONT} - | 
	convert - -rotate $ROTATE -channel red -threshold ${THRESH}% \
	-posterize 2 - | \
		
tee \
	>( cat > $dname ) \
	>( convert - -resize $TTE tte.png ) \
	>( convert - -resize $TRH trh.png ) \
	>( convert - -resize $ETE ete.png ) \
	>( convert - -resize $ERH erh.png ) \
	> /dev/null

for i in {0..10}; do
	[[ -s tte.png && -s trh.png && -s ete.png && -s erh.png ]] && break
	sleep 0.33
done

#for i in tte trh ete erh; do
#	ssocr -C -c digits -d -1 -T $i.png || echo "bad value"
#done
I commented out the last one because I have no idea what that is doing, ssocr, I do not even have installed, as well.

Last edited by BW-userx; 01-12-2019 at 09:39 AM.
 
Old 01-13-2019, 02:27 AM   #3
lazardo
Member
 
Registered: Feb 2010
Location: SD Bay Area
Posts: 270

Original Poster
Rep: Reputation: Disabled
Quote:
I am getting just an white image, so I looked up the commands for imagemagick and added -channel played with the threshold and now I am getting some black in the images.
Everything in the original script was done to grab the face of a temp/humidity sensor which appears visually as grey and black, but is actually full color.

ssocr is an open source program that extracts segmented display values from an image, for which the success rate goes from 70% to 99.9% using the script.

Play with brightness, contrast and threshold to get the image you want, remove the posterization, colorspace and background values if not using ssocr.

If you don't need to straighten the image, remove the rotation also.

Cheers,

Last edited by lazardo; 01-13-2019 at 02:31 AM.
 
Old 01-13-2019, 01:02 PM   #4
BW-userx
LQ Guru
 
Registered: Sep 2013
Location: Somewhere in my head.
Distribution: Slackware (15 current), Slack15, Ubuntu studio, MX Linux, FreeBSD 13.1, WIn10
Posts: 10,342

Rep: Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242
oH so this was more of a share then a what am I doing wrong question.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] How to autostart fswebcam at startup? lepidas Linux - Server 7 08-24-2012 02:38 PM
Exact time of image capture and Unicap library for video capture devices Dstruct0 Programming 3 09-10-2011 06:34 PM
consistent look through gtk apps garba Linux - Software 3 05-29-2005 04:55 PM
Speed not consistent w/ hardware during dl Aterxerxes Linux - Networking 15 12-16-2003 08:50 PM
Consistent web UI w/o duplicating HTML ugenn Programming 0 08-23-2002 11:47 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Hardware

All times are GMT -5. The time now is 11:57 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration