Another tab for WebCam

More
03 Dec 2010 18:01 - 03 Dec 2010 18:02 #5846 by eslavko
Replied by eslavko on topic Re:Another tab for WebCam
So here is some results.
All button's now work. And little explanation What can do and how.

The top slider resize aperture (circle here in image but can be paralel lines too)
The botom slider change angle of aperture (usable with paralel lines as aperture)
G43H99 checkbox Just do what is says. Ie introduce offset for camera (is not mounted on spindle) and move machine to camera just see position was under the tool. (When unchecking the all is done in reverse - the tool goes where cam was)
SaveXYZ Button just save coordinates to the file (log) so some tracing is possible and some other things can be done too. The last 4 coordinates are saved in internal variables too.
Center3 button means that clicking on that machine find center of circle from last 3 points and Center4 button is for centering with 4 points (top, bottom and left, right).
All that with great help from Pavel Shramov (psha) Thanks.

Attachments:
Last edit: 03 Dec 2010 18:02 by eslavko.

Please Log in or Create an account to join the conversation.

More
07 Dec 2010 16:47 - 07 Dec 2010 16:54 #5911 by eslavko
Replied by eslavko on topic Re:Another tab for WebCam
As few people ask me to publis how I get folowing interface here is How it's done.

(just little comment on picture. The micrometer is oppened to have 3um gap. So anybody can see how precise cheap webcam can be.)


The system works on Ubuntu Hardy heron and EMC2 is version 2.5.0~pre (latest 2.4.x should work too).

So for the start we need to check if our cam is recongnized/woorking. So the right package is 'camview' and is available form web. (link)
If cam is working then just save that configuration (from camview) to file 'camviewcfg' in EMC2 machine folder.

Now we need the 'camview-emc' package (link)

Then we need to say AXIS that we want CAMERA tab and this is way how to get it.
Edit the machine INI file and add in [DISPLAY] section

[DISPLAY]
EMBED_TAB_NAME = CAM_View
EMBED_TAB_COMMAND = camview-emc -C camviewcfg -w {XID}

Start EMC and there should be camera window.

So the next steep is to add some widgets in that window. Change the line from

EMBED_TAB_COMMAND = camview-emc -C camviewcfg -w {XID}
to
EMBED_TAB_COMMAND = camview-emc -C camviewcfg -g togle-caa.ui -H campins.hal -w {XID}
and download the file 'togle-caa.ui' from (link). The file can be created with GladeVCP too.

And we need to make another HAL file for cam support. The file should be in machine INI folder.
Here is my version of that file. The OneShoot is needed to create just right sequence for executing subs
'
campins.hal file
#CamView pins

loadrt oneshot names=forOn,forOff
addf forOn servo-thread
addf forOff servo-thread
setp forOn.width .1
setp forOff.width .1
setp forOff.falling 1
setp forOff.rising 0
net forOnNet camview.hal_checkbutton1 => forOn.in forOff.in
net cam1 forOn.out => halui.mdi-command-00
net cam2 forOff.out => halui.mdi-command-01
net cam3 camview.hal_button1 => halui.mdi-command-02
net cam4 camview.hal_button2 => halui.mdi-command-03
net cam5 camview.hal_button3 => halui.mdi-command-04
'

we must add the few lines to machine INI file in HALUI section
[HALUI]
MDI_COMMAND=o<_camon>call
MDI_COMMAND=o<_camoff>call
MDI_COMMAND=o<_camstore>call
MDI_COMMAND=o<_camcenter3>call
MDI_COMMAND=o<_camcenter4>call

Every action just start that custom file located in PROGRAM_PREFIX folder.
And my files are:

_camon.ngc
When checkbox (G43H99) is checked this is executed.
It moves the machine in such way to position camera in place where tool was before.
The camera offset (from tool holder) is defined as Tool 99 offset in tolltable.
'
o<_camon> sub
g92 x0 y0 z0
g92.2
#<_CamOfsX> = #5211
#<_CamOfsY> = #5212
g92.1
g43 h99
g92 x0 y0 z0
g92.2
#<_CamOfsX> = [#<_CamOfsX> - #5211]
#<_CamOfsY> = [#<_CamOfsY> - #5212]
g92.1
g91 g0 x#<_CamOfsX> y #<_CamOfsY>
g90
o<_camon> endsub
M2
'


_camoff.ngc
When checkbox (G43H99) is unchecked this is executed.
It moves the machine in such way to position tool back where camera is pointing.
'
o<_camoff> sub
g43 h99 g91 g0 x[-#<_CamOfsX>] y-[#<_CamOfsY>]
g90 g49
o<_camoff> endsub
M2
'



_camstore.ngc
When SaveXYZ is clicked the machine store current position in file and preserve last 4 coordinate as variables too
The EMC2 should be patched to have LOGAPPEND command available. (Latest version should already be patched)
'
o<_camstore> sub
g92 x0 y0 z0
g92.2
#3999=[#3999+1] ;next parameter
O100 if[#3999 EQ 1]
#<_CamX1> = #5211
#<_CamY1> = #5212
O100 endif
O101 if[#3999 EQ 2]
#<_CamX2> = #<_CamX1>
#<_CamY2> = #<_CamY1>
#<_CamX1> = #5211
#<_CamY1> = #5212
O101 endif
O102 if[#3999 EQ 3]
#<_CamX3> = #<_CamX2>
#<_CamY3> = #<_CamY2>
#<_CamX2> = #<_CamX1>
#<_CamY2> = #<_CamY1>
#<_CamX1> = #5211
#<_CamY1> = #5212
O102 endif
O103 if[#3999 GE 4]
#<_CamX4> = #<_CamX3>
#<_CamY4> = #<_CamY3>
#<_CamX3> = #<_CamX2>
#<_CamY3> = #<_CamY2>
#<_CamX2> = #<_CamX1>
#<_CamY2> = #<_CamY1>
#<_CamX1> = #5211
#<_CamY1> = #5212
#3999=4
O103 endif
(LOGAPPEND,_CAMlog)
(LOG, X=#5211, Y=#5212, Z=#5213)
(LOGCLOSE)
g92.1
(MSG, CAM position stored.)
o<_camstore> endsub
M2
'



_camcenter3.ngc
When Center3 is clicked the last 3 saved point is used to calculate circle center.
The routine isn't perfect and throw Nonsense coordinates when can't calculate it.
(in most case this is when X or Y coordinates of point lie in same line.) The machine does move to the calculated center!
'
o<_camcenter3> sub
O99 if[#3999 GE 3]
#<ok> = 0
#<m1>=[#<_Camy2> - #<_Camy1>]
O100 if[#<m1> EQ 0]
#<m1>=1
#<ok>=1
O100 endif
#<m2>=[#<_Camy3> - #<_Camy2>]
O101 if[#<m2> EQ 0]
#<m2>=1
#<ok>=1
O101 endif
#<m1> =[[#<_CamX1> - #<_CamX2>] / #<m1>]
#<m2> =[[#<_CamX2> - #<_CamX3>] / #<m2>]
#<ix> =[#<m1> - #<m2>]
O102 if[#<ix> EQ 0]
#<ix>=1
#<ok>=1
O102 endif
#<b1> =[#<_CamY1> + #<_CamY2>] / 2] - [#<m1> * [#<_CamX1> + #<_CamX2>] /2
#<b2> =[#<_CamY2> + #<_CamY3>] / 2] - [#<m2> * [#<_CamX2> + #<_CamX3>] /2
#<ix>=[[#<b2> - #<b1>] / #<ix>]
#<iy>=[#<m1> * #<ix> + #<b1>]
O200 if[#<ok> EQ 0]
G0 X[#<ix>] Y[#<iy>]
(MSG,Centered)
O200 else
(MSG,Nonsense coordinates!)
O200 endif
#3999 = 0
O99 else
(MSG,Must have 3 points saved!)
O99 endif
o<_camcenter3> endsub
M2
'


_camcenter4.ngc
When Center4 is clicked the last 4 saved point is used to calculate center coordinate.
This one is pretty stupid as just expect left-right and up-down pair and find middle position from that. The machine move here!
'
o<_camcenter4> sub
O99 if[#3999 EQ 4]
#<ok> = 0
O100 if#<_CamX1> EQ #<_CamX2>] AND [#<_CamY3> EQ #<_CamY4>
G0 X[[#<_CamX3> + #<_CamX4>]/2] Y[[#<_CamY1> + #<_CamY2>]/2]
#<ok>= 1
O100 endif
O101 if#<_CamX3> EQ #<_CamX4>] AND [#<_CamY1> EQ #<_CamY2>
G0 X[[#<_CamX1> + #<_CamX2>]/2] Y[[#<_CamY3> + #<_CamY4>]/2]
#<ok>= 1
O101 endif
O200 if[#<ok> EQ 1]
(MSG,Centered)
O200 else
(MSG,Nonsense coordinates!)
O200 endif
#3999 = 0
O99 else
(MSG,Must have 4 points saved!)
O99 endif
o<_camcenter4> endsub
M2
'



That's all.
And the big thanks to Pavel Shramov (psha)

File Attachment:

File Name: emcfiles.zip
File Size:7 KB
Attachments:
Last edit: 07 Dec 2010 16:54 by eslavko. Reason: Just adding zip files contain all my configs for machine

Please Log in or Create an account to join the conversation.

More
07 Dec 2010 16:57 #5912 by eslavko
Replied by eslavko on topic Re:Another tab for WebCam
Just need to say WARNING. The sub's use G92 offset. So if user uses G92 then conflicting situation is here.

Please Log in or Create an account to join the conversation.

More
07 Dec 2010 20:23 #5915 by marzetti
Replied by marzetti on topic Re:Another tab for WebCam
Excellent work, Slavko! I will be implementing this on my machine as soon as I have time. This should be added to the wiki so others can find it in the future.

Thanks,
Greg

Please Log in or Create an account to join the conversation.

More
07 Dec 2010 20:43 #5916 by eslavko
Replied by eslavko on topic Re:Another tab for WebCam
marzetti wrote:

Excellent work, Slavko! I will be implementing this on my machine as soon as I have time. This should be added to the wiki so others can find it in the future.

Thanks,
Greg


I'm tryed that. I spend 10 minutes to create new page but fail. So I posted result here...

Please Log in or Create an account to join the conversation.

More
07 Dec 2010 20:56 #5918 by psha
Replied by psha on topic Re:Another tab for WebCam
You have to log in into wiki
Otherwise it's reject edits
wiki.linuxcnc.org/cgi-bin/emcinfo.pl?Axis_Embed_Video
Go to 'Preferences' link in the bottom

Please Log in or Create an account to join the conversation.

More
08 Dec 2010 15:12 #5928 by Dimitrios
Replied by Dimitrios on topic Re:Another tab for WebCam
Congratulations eslavko and psha,

I will implement it in a new machine I am building.

Kind regards,

Dimitri

Please Log in or Create an account to join the conversation.

More
26 Mar 2011 23:33 - 26 Mar 2011 23:48 #8132 by Andy123
Replied by Andy123 on topic Re:Another tab for WebCam
I hope somebody can help me
I loaded camview and camview-emc

See just a black window in camview

Any ideas how to fix it?

arkcnc@arkcncD610:~$ lsmod | grep video
uvcvideo 56990 0
videodev 33267 1 uvcvideo
v4l1_compat 13198 2 uvcvideo,videodev
video 17089 0
output 1773 1 video
arkcnc@arkcncD610:~$ lsmod | grep gspca
arkcnc@arkcncD610:~$ lsusb
Bus 005 Device 001: ID 1d6b:0001 Linux Foundation 1.1 root hub
Bus 004 Device 001: ID 1d6b:0001 Linux Foundation 1.1 root hub
Bus 003 Device 001: ID 1d6b:0001 Linux Foundation 1.1 root hub
Bus 002 Device 001: ID 1d6b:0001 Linux Foundation 1.1 root hub
Bus 001 Device 002: ID 04f2:a133 Chicony Electronics Co., Ltd Gateway Webcam
Bus 001 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub

Thanks

Attachments:
Last edit: 26 Mar 2011 23:48 by Andy123.

Please Log in or Create an account to join the conversation.

More
27 Mar 2011 05:48 #8138 by psha
Replied by psha on topic Re:Another tab for WebCam
I've added section about finding out which component is failing.

psha.org.ru/b/camview-emc.html#_troubleshooting

What if you try example/vivi instead of your cam?

Please Log in or Create an account to join the conversation.

More
27 Mar 2011 11:19 - 27 Mar 2011 11:20 #8147 by Andy123
Replied by Andy123 on topic Re:Another tab for WebCam
As far as I know camera works just fine, since I am using with Skype on the same computer

vivi and example input giving me black screeen

So my guess will be OpenGL issue

After I posted this last night I tried different configurations
In some combinations I was able to get a frozen picture for a short time, but this was not consistent at all.

I can try other ideas if you have them

Spasibo!
Last edit: 27 Mar 2011 11:20 by Andy123.

Please Log in or Create an account to join the conversation.

Time to create page: 0.448 seconds
Powered by Kunena Forum