Superimposing graphics on USB camera image

Discussions related to graphics (2D and 3D), animation and games programming
manxman
Posts: 11
Joined: Tue 13 Sep 2022, 09:13

Superimposing graphics on USB camera image

Post by manxman »

Hi folks,

I am a returnee to this forum after a break in BBC4W programming. My current project is building a tree-ring measuring machine in which I would like to superimpose graphics composed in BBC Basic over an image generated by a USB microscope camera. The graphics requirement is simple, namely a set of cross hairs and some text.

However, I am foxed as to how to achieve this. Any tips from the more experienced here would be much appreciated.

Mark
Hated Moron

Re: Superimposing graphics on USB camera image

Post by Hated Moron »

manxman wrote: Tue 13 Sep 2022, 13:27 I would like to superimpose graphics composed in BBC Basic over an image generated by a USB microscope camera.
It's not clear from your description whether this is a moving image (i.e. live video) or a still image that was captured from the camera. If it's a still image then of course it's straightforward - just display the image and draw the graphics on top! If it's a video source however it could be more tricky, because I'm not sure which of the various methods of displaying video in a BASIC program allow you to draw graphics in the same window. You might have to resort to layering a 'transparent' window over the video window, and even that may not work.

Perhaps you can provide a little more detail.
manxman
Posts: 11
Joined: Tue 13 Sep 2022, 09:13

Re: Superimposing graphics on USB camera image

Post by manxman »

I should have stated that the live feed from the USB microscope is real-time 2K video. The wood sample will be slowly traversed (mechanically) beneath this camera-scope until a ring boundary is beneath the cross hairs. Then I will take a displacement reading ... then move on to the next boundary, etc until the ring-width series is logged. Hence for this scheme to work the image must be real-time video.

The option of having an opaque black or transparent cross hair over the camera feed would be nice to have as an option.

Mark
Hated Moron

Re: Superimposing graphics on USB camera image

Post by Hated Moron »

manxman wrote: Tue 13 Sep 2022, 16:55 Hence for this scheme to work the image must be real-time video.
OK, in your position I think I would try each of the different approaches to displaying video in BB4W (as exemplified by the various webcam_ programs at the Discussion Group) to ascertain (a) whether they work at all with your camera and (b) whether they play nicely with a transparent BBC BASIC window layered on top.
manxman
Posts: 11
Joined: Tue 13 Sep 2022, 09:13

Re: Superimposing graphics on USB camera image

Post by manxman »

Thanks for the suggestion. However I am not sure how to visit that Discussion Group since when I try to create a password I get the message:

"That email address does not have a Groups.io account."

By the way I am not on Facebook

Mark
Hated Moron

Re: Superimposing graphics on USB camera image

Post by Hated Moron »

manxman wrote: Tue 13 Sep 2022, 19:47 "That email address does not have a Groups.io account."
The Discussion Group has always been a convenient place for people to exchange programs etc., since (unlike this forum, and most others) it has a 'Files' area where such things can be stored and to which anybody can upload. It is the 'original' support forum for (my) BBC BASIC - starting off as a Yahoo! group before moving to Groups.io - and the message archive there goes back to January 2005!

If you have some objection in principle to joining it (I wonder what that is; it's not affiliated to Facebook or any other Social Media platform as far as I know) you are cutting yourself off from a valuable source of information.
manxman
Posts: 11
Joined: Tue 13 Sep 2022, 09:13

Re: Superimposing graphics on USB camera image

Post by manxman »

I have no objection at all to joining the group but, as I mentioned, I seem to have a problem actually signing up! No problem I will press on regardless.

Mark
Hated Moron

Re: Superimposing graphics on USB camera image

Post by Hated Moron »

manxman wrote: Wed 14 Sep 2022, 12:18 as I mentioned, I seem to have a problem actually signing up!
What I understood from your previous post was that you received the message "That email address does not have a Groups.io account" which sounds like what would happen if you'd never signed up for one. What happens if you try? Perhaps you might consider posting a screenshot of any error message(s) you are seeing.
KenDown
Posts: 327
Joined: Wed 04 Apr 2018, 06:36

Re: Superimposing graphics on USB camera image

Post by KenDown »

What you are asking for is, as Richard says, most conveniently done using a transparent window. This function will create a transparent window (you will need to have enabled multi-win)

Code: Select all

      DEFFNcreatetransparent(scrnx%,scrny%,win%)
      trans%=FN_createwin(win%,"",0,0,scrnx%,scrny%,0,&96C00000,0)
      PROC_selectwin(win%)
      SYS"SetWindowLong",trans%,-16,&16000000
      SYS"SetWindowPos",trans%,-1,0,0,scrnx%,scrny%,32
      COLOUR3,255,252,162
      COLOUR9,255,0,0
      PROCsetdc(win%)
      VDU26
      COLOUR129:CLS
      transparent%=TINT(60,160)
      SYS"SetWindowLong",trans%,-20,&80000
      SYS"SetLayeredWindowAttributes",trans%,transparent%,0,1
      PROC_selectwin(0):VDU26,5
      =trans%
            :
      DEFPROCsetdc(handle%)
      SYS`GdipCreateFromHDC`,@memhdc%,^dchandle%(handle%)
      IFdchandle%(handle%)=0ERROR 101,"Couldn't initialise window for GDIP"
      SYS`GdipSetInterpolationMode`,dchandle%(handle%),3:REM bilinear
      ENDPROC
The parameters are the size of the desired window (scrnx%, scrny%) and the number of the proposed window. The flag when creating the window makes it without any "furniture", so if you want close buttons etc you will have to change the flag. Once created, the function returns you to window 0.

The process of creating a transparent window is to create the window, then fill it with a particular colour and finally declare that colour to be transparent. I have chosen deep red as the transparent colour, you may prefer something else.

If you do not need to use special graphics, delete the call to PROCsetdc.

I have used this to superimpose foreign language subtitles over video. I presume it will work equally well for crosshairs or whatever.
manxman
Posts: 11
Joined: Tue 13 Sep 2022, 09:13

Re: Superimposing graphics on USB camera image

Post by manxman »

Ken,

Thanks for your most helpful suggestion and apologies for the delay in my reply. I will try that approach to solving my task.

Mark