motion capture ?

General FreeBASIC programming questions.
Post Reply
BasicCoder2
Posts: 3906
Joined: Jan 01, 2009 7:03
Location: Australia

motion capture ?

Post by BasicCoder2 »

Boromir wrote:The unit sprite is now a pre-rendered 3d model. I haven't been spending too much time on this RTS game recently because I had also had been working on a 2d skeletal animation program.
Working on writing a 2d skeletal animation program or working on learning how to use one? If you are writing one why not make it 3D?

You really need some motion capture hardware/software. One way might be with Kinect hardware?

https://www.youtube.com/watch?v=_POTSkgARHc
https://www.youtube.com/watch?v=NxbH-QDHAVg

You can use the RoboRealm software with Kinect however I don't know how to interface RoboRealm with a FreeBASIC program although they do explain how to connect it with another language (and have done so for some languages) but I don't have the knowledge to make use of their explanations.

I don't know if anyone has used Kinect directly with FreeBASIC.

Or some web cams?
https://www.youtube.com/watch?v=iVgTxm0v4pw
Making your own.
https://www.youtube.com/watch?v=XIw9cZ8i4mE
.
Maybe I will write a simple example of motion capture using my laptop webcam and escapi.bi
.
D.J.Peters
Posts: 8586
Joined: May 28, 2005 3:28
Contact:

Re: motion capture ?

Post by D.J.Peters »

Why not downloading free *.bhv files ? (bhv, fbx, tvd, c3d...)
(you can find/google thausends of captured high quality motions)
2400# http://mocap.cs.cmu.edu/
500# https://gumroad.com/l/eTsK#
...

Then select one that match the nearest you need and edit it.

Download an editor or write your own (it's easy if you know the mocap file format).
bvhacker: http://www.bvhacker.com

Joshy
Boromir
Posts: 463
Joined: Apr 30, 2015 19:28
Location: Oklahoma,U.S., Earth,Solar System
Contact:

Re: motion capture ?

Post by Boromir »

BasicCoder2 wrote:
Boromir wrote:The unit sprite is now a pre-rendered 3d model. I haven't been spending too much time on this RTS game recently because I had also had been working on a 2d skeletal animation program.
Working on writing a 2d skeletal animation program or working on learning how to use one? If you are writing one why not make it 3D?
I'm avoiding 3d because I'm not very comfortable with complex 3d render math.
And Blender works for me when doing 3d animation. It's when doing 2d sprite animations that I find programs hard to find.

3d cameras are a bit expensive and I can't see myself really using one too much. Though one would be useful for robots as well.
For motion capture I assume there is professional software that can be used in conjunction with 3d animation software.
BasicCoder2 wrote:Maybe I will write a simple example of motion capture using my laptop webcam and escapi.bi
That would definitely be interesting to see. I did not know there was a library that added webcam support.
BasicCoder2
Posts: 3906
Joined: Jan 01, 2009 7:03
Location: Australia

Re: motion capture ?

Post by BasicCoder2 »

Boromir wrote: I did not know there was a library that added webcam support.
It was the reason I changed from C to using FreeBASIC as at the time I was working on building a robot.

There is a .dll you can get from,
http://sol.gfxile.net/code.html
And use it with,
escapi.bi

Code: Select all

' Extremely Simple Capture API

Type SimpleCapParams
  ' Target buffer. 
  ' Must be at least mWidth * mHeight * sizeof(int) of size! 
  As Integer Ptr mTargetBuf
  As Integer  mWidth
  As Integer  mHeight
End Type


' Sets up the ESCAPI DLL and the function pointers below. Call this first!
' Returns number of capture devices found (same as countCaptureDevices, below)
Declare Function setupESCAPI() As Integer

' return the number of capture devices found
Type countCaptureDevicesProc As Function Cdecl As Integer
Dim Shared As countCaptureDevicesProc countCaptureDevices

' initCapture tries to open the video capture device. 
' Returns 0 on failure, 1 on success. 
' Note: Capture parameter values must not change while capture device
'       is in use (i.e. between initCapture and deinitCapture).
'       Do *not* free the target buffer, or change its pointer!
Type initCaptureProc As Function Cdecl (deviceno As Integer,p As  SimpleCapParams Ptr) As Integer
Dim Shared As initCaptureProc initCapture

' deinitCapture closes the video capture device.
Type deinitCaptureProc As Sub Cdecl(deviceno As Integer)
Dim Shared As deinitCaptureProc deinitCapture

' doCapture requests video frame to be captured.
Type doCaptureProc As Sub Cdecl(deviceno As Integer)
Dim Shared As doCaptureProc doCapture

' isCaptureDone returns 1 when the requested frame has been captured.
Type isCaptureDoneProc As Function Cdecl(deviceno As Integer) As Integer
Dim Shared As isCaptureDoneProc isCaptureDone

' Get the user-friendly name of a capture device.
Type getCaptureDeviceNameProc As Sub Cdecl(deviceno As Integer,namebuffer As Zstring Ptr,bufferlength As Integer)
Dim Shared As getCaptureDeviceNameProc getCaptureDeviceName

' Returns the ESCAPI DLL version. 0x200 for 2.0
Type ESCAPIDLLVersionProc As Function() As Integer
Dim Shared As ESCAPIDLLVersionProc ESCAPIDLLVersion

' Internal: initialize COM
Type initCOMProc As Sub Cdecl
Dim Shared As initCOMProc initCOM

Function setupESCAPI() As Integer

  ' Load DLL dynamically
  Dim As Any Ptr capdll = DyLibLoad("escapi.dll")
  If (capdll = 0) Then
    Print "can't load 'escapi.dll' !"
    Beep:Sleep:Return 0
  End If
  ' Fetch function DyLibSymbol(escapi_dll,
  countCaptureDevices  = DyLibSymbol(capdll, "countCaptureDevices")
  initCapture          = DyLibSymbol(capdll, "initCapture")
  deinitCapture        = DyLibSymbol(capdll, "deinitCapture")
  doCapture            = DyLibSymbol(capdll, "doCapture")
  isCaptureDone        = DyLibSymbol(capdll, "isCaptureDone")
  initCOM              = DyLibSymbol(capdll, "initCOM")
  getCaptureDeviceName = DyLibSymbol(capdll, "getCaptureDeviceName")
  ESCAPIDLLVersion     = DyLibSymbol(capdll, "ESCAPIDLLVersion")

  If ESCAPIDLLVersion=0 Then
    Print "can't get proc address !"
    Beep:Sleep:Return 0
  End If
  If (ESCAPIDLLVersion() <> &H200) Then
        Print "wrong dll version !"
    Beep:Sleep:Return 0
  End If
  ' Initialize COM.
  initCOM()

  ' and return the number of capture devices found.
  Return countCaptureDevices()
End Function

Here is an old example to grab from more than one webcam.

Code: Select all

#include "escapi.bi"


Const iWIDTH = 320
Const iHEIGHT = 240

ScreenRes 640,480,32

Dim As Integer nDevices=setupESCAPI()

If nDevices<1 Then
    Print "No active capture device found!"
    Beep:Sleep:End
Else
    if nDevices > 4 then
        nDevices = 4
    end if    
    print "number of devices=";nDevices
End If

'list of pointers
Dim shared As Any Ptr lpImage(4)

for k as integer = 0 to nDevices-1
    lpImage(k)=ImageCreate(iWIDTH,iHEIGHT)
next k

Dim Shared As SimpleCapParams Params(4)

for k as integer = 0 to nDevices-1
  Params(k).mWidth  = iWIDTH
  Params(k).mHeight = iHEIGHT
  Params(k).mTargetBuf=cptr(Integer Ptr,lpImage(k))
  Params(k).mTargetBuf+=8
  doCapture(k)
next k

for k as integer = 0 to nDevices-1
    initCapture(k, @Params(k))
next k

'main loop
dim as integer x,y
do
    for k as integer = 0 to nDevices-1
        print k
        doCapture(k)
        locate 1,1
        While isCaptureDone(k)<>1:Sleep(10):Wend
        if k = 0 or k = 2 then x = 0 else x = 320
        if k = 0 or k = 1 then y = 0 else y = 240
        Put (x,y),lpImage(k),Pset
    next k
loop until multikey(&H01)


for k as integer = 0 to nDevices-1
    imageDestroy(lpImage(k))
next k
Last edited by BasicCoder2 on Sep 08, 2017 20:05, edited 1 time in total.
BasicCoder2
Posts: 3906
Joined: Jan 01, 2009 7:03
Location: Australia

Re: motion capture ?

Post by BasicCoder2 »

Boromir wrote:... Blender works for me when doing 3d animation.
As I understand it with Blender you have to change the positions of the limbs manually for animation unless you can use bone animations made by others as suggested by Joshy. You needed a set of animations taken from an isometric viewpoint. I saw the problem as having realistic movements best obtained from actual subjects rather than manually moving the joints in Blender. Then there is the problem of designing costumes for the characters along with the tools they may be using. The cheapest solution would be to have eight cameras on the top of poles arranged in a circle that can record the actions of an actors dressed as Vikings. If there is only one camera the actor could perform the same movement eight times but looking in the eight different directions. This would be easier and faster than learning Blender to get animated isometric images.

It is the easiest way to get 2D animations as well for 2d platformer sprites except you don't need to have your camera up high looking down at the correct angle and depending on the game would need less animated views.

I obtained the joint position in my stickman demos from walking sprites animations freely available on web.
http://www.freebasic.net/forum/viewtopi ... d+stickman
.
Boromir
Posts: 463
Joined: Apr 30, 2015 19:28
Location: Oklahoma,U.S., Earth,Solar System
Contact:

Re: motion capture ?

Post by Boromir »

BasicCoder2 wrote:As I understand it with Blender you have to change the positions of the limbs manually for animation unless you can use bone animations made by others as suggested by Joshy. You needed a set of animations taken from an isometric viewpoint. I saw the problem as having realistic movements best obtained from actual subjects rather than manually moving the joints in Blender.
Manually moving joints in blender isn't that hard. You can probably find motion tracking software on the web that can be used with blender if extremely realistic motion is necessary. For my RTS, I'm satisfied with a more simplistic animation style that can be made fairly easily with blender.
BasicCoder2 wrote:The cheapest solution would be to have eight cameras on the top of poles arranged in a circle that can record the actions of an actors dressed as Vikings. If there is only one camera the actor could perform the same movement eight times but looking in the eight different directions. This would be easier and faster than learning Blender to get animated isometric images.
I would have thought that that would be extremely expensive. Also that doesn't give you the nice artistic look you get from hand drawn or 3d.
BasicCoder2
Posts: 3906
Joined: Jan 01, 2009 7:03
Location: Australia

Re: motion capture ?

Post by BasicCoder2 »

Boromir wrote:Manually moving joints in blender isn't that hard. You can probably find motion tracking software on the web that can be used with blender if extremely realistic motion is necessary. For my RTS, I'm satisfied with simplistic animation that can be made with blender.
BasicCoder2 wrote:The cheapest solution would be to have eight cameras on the top of poles arranged in a circle that can record the actions of an actors dressed as Vikings. If there is only one camera the actor could perform the same movement eight times but looking in the eight different directions. This would be easier and faster than learning Blender to get animated isometric images.
Boromir wrote:I would have thought that that would be extremely expensive. Also that doesn't give you the nice artistic look you get from hand drawn or 3d.
The expense would be in hiring performers and making costumes otherwise it is cheap and easy. That is how I made the character in this demo using myself as the performer.
http://www.freebasic.net/forum/viewtopi ... 15&t=22633

Set up your camera and take a video of yourself walking or some other action. Then using video editing software grab a set of images, say 8 to 16, that cover the whole action. You can then trace out the character using a Paint program, I used the old MSPAINT and imagegrab by Paul Glagla.
https://imagegrab.en.softonic.com/

This at least gives you proportion and smooth movements to which you can add your own art. I did think of automating it further by making a suit with different colors for each arm, leg, front, back, boots, vest area, gloves and so on. Then you can write a program to remove anything not of the set of colors.

As for a cartoon look there is simple software that you can write yourself or use an online version for which essentially reduces the number of colors and then overlays an edged version over that.

This is a quick example of one frame showing how I imagine using color to extract parts of the body automatically.

Code: Select all

screenres 640,480,32
color rgb(0,0,0),rgb(255,255,255):cls

dim as any ptr image
image = imagecreate(37, 68)

dim as ulong colors(0 to 9)
colors(0)=RGB(255,255,255)
colors(1)=RGB(237,28,36)
colors(2)=RGB(255,174,201)
colors(3)=RGB(163,73,164)
colors(4)=RGB(0,162,232)
colors(5)=RGB(112,146,190)
colors(6)=RGB(63,72,204)
colors(7)=RGB(136,0,21)
colors(8)=RGB(94,86,65)
colors(9)=RGB(255,127,39)
locate 2,2
print "colors in the image"
for i as integer = 0 to 11
    line (i*32,32)-(i*32+31,32+31),colors(i),bf
next i

dim as string datum
dim as integer n
for j as integer = 0 to  67
    read datum
    for i as integer = 0 to  36
        n = val("&H" & mid(datum,i+1,1))
        pset image,(i,j),colors(n)
    next i
next j
bsave "walker3.bmp",image
put (100,100),image,trans
sleep

DATA "0000000000000000001111100000000000000"
DATA "0000000000000000011111110000000000000"
DATA "0000000000000000111111110000000000000"
DATA "0000000000000000111111220000000000000"
DATA "0000000000000000111122220000000000000"
DATA "0000000000000000111122220000000000000"
DATA "0000000000000000111122220000000000000"
DATA "0000000000000000022222200000000000000"
DATA "0000000000000000022222200000000000000"
DATA "0000000000000000333222000000000000000"
DATA "0000000000000003333330000000000000000"
DATA "0000000000000033333443000000000000000"
DATA "0000000000000033334444000000000000000"
DATA "0000000000000033344444000000000000000"
DATA "0000000000000333344444400000000000000"
DATA "0000000000000333344444400000000000000"
DATA "0000000000000333344444440000000000000"
DATA "0000000000005333344444444000000000000"
DATA "0000000000005333334444444400000000000"
DATA "0000000000005333333444444440000000000"
DATA "0000000000005333333444444444000000000"
DATA "0000000000005333333344444444400000000"
DATA "0000000000005333333344444444440000000"
DATA "0000000000005333333334444444444400000"
DATA "0000000000005333333333444444444440000"
DATA "0000000000055533333333334444444444000"
DATA "0000000000055533333333330004444444400"
DATA "0000000000055533333333330000044444420"
DATA "0000000000055533333333330000000442222"
DATA "0000000000055533333333330000000000222"
DATA "0000000000555533333333330000000000222"
DATA "0000000000555033333333330000000000000"
DATA "0000000000555033333333330000000000000"
DATA "0000000000222011111111110000000000000"
DATA "0000000002222011111111110000000000000"
DATA "0000000002220111111111110000000000000"
DATA "0000000000000111111111110000000000000"
DATA "0000000000000111111111110000000000000"
DATA "0000000000000111111111110000000000000"
DATA "0000000000001111111111166000000000000"
DATA "0000000000001111111111666000000000000"
DATA "0000000000001111111116666600000000000"
DATA "0000000000011111111116666600000000000"
DATA "0000000000011111111166666660000000000"
DATA "0000000000011111111666666660000000000"
DATA "0000000000111111111666666660000000000"
DATA "0000000000111111110666666666000000000"
DATA "0000000001111111100066666666000000000"
DATA "0000000001111111000006666666000000000"
DATA "0000000011111110000000666666600000000"
DATA "0000000111111100000000066666600000000"
DATA "0000000111111000000000066666600000000"
DATA "0000001111110000000000006666600000000"
DATA "0000011111110000000000006666660000000"
DATA "0000011111100000000000000666660000000"
DATA "0000111111000000000000000666660000000"
DATA "0000111110000000000000000066666000000"
DATA "0001111110000000000000000066666000000"
DATA "0001111100000000000000000066666600000"
DATA "0011111000000000000000000066666600000"
DATA "0011111000000000000000000006666600000"
DATA "0111111000000000000000000006666600000"
DATA "0771110000000000000000000000666899999"
DATA "7777770000000000000000000000669999999"
DATA "7777770000000000000000000000099999990"
DATA "7777777000000000000000000000099999000"
DATA "0777777700000000000000000000099900000"
DATA "0000777700000000000000000000000000000"
Boromir
Posts: 463
Joined: Apr 30, 2015 19:28
Location: Oklahoma,U.S., Earth,Solar System
Contact:

Re: motion capture ?

Post by Boromir »

BasicCoder2 wrote: The expense would be in hiring performers and making costumes otherwise it is cheap and easy. That is how I made the character in this demo using myself as the performer.
http://www.freebasic.net/forum/viewtopi ... 15&t=22633

Set up your camera and take a video of yourself walking or some other action. Then using video editing software grab a set of images, say 8 to 16, that cover the whole action. You can then trace out the character using a Paint program, I used the old MSPAINT and imagegrab by Paul Glagla.
https://imagegrab.en.softonic.com/

This at least gives you proportion and smooth movements to which you can add your own art. I did think of automating it further by making a suit with different colors for each arm, leg, front, back, boots, vest area, gloves and so on. Then you can write a program to remove anything not of the set of colors.

As for a cartoon look there is simple software that you can write yourself or use an online version for which essentially reduces the number of colors and then overlays an edged version over that.
That seems like a lot of work to me. In blender all I have to do is model a new character. Animations can be carried between models so its easy for me to have lots of different characters with animations as opposed to having to trace thousands of images.
BasicCoder2
Posts: 3906
Joined: Jan 01, 2009 7:03
Location: Australia

Re: motion capture ?

Post by BasicCoder2 »

Boromir wrote:That seems like a lot of work to me. In blender all I have to do is model a new character. Animations can be carried between models so its easy for me to have lots of different characters with animations as opposed to having to trace thousands of images.
And how hard and time consuming is it to model a new character with clothes?

They seem to use what amounts to virtual clay and would require the same artistic abilities as someone who could sculpt with real clay.

But this was about motion capture for said models. I looked at the Joshy links and it seems to require a big learning curve compared with simply taking video of a motion performance. Of course a video gives you perspective so the camera needs to be as far away as possible which in the case of an isometric view that means very high up!
.
Boromir
Posts: 463
Joined: Apr 30, 2015 19:28
Location: Oklahoma,U.S., Earth,Solar System
Contact:

Re: motion capture ?

Post by Boromir »

BasicCoder2 wrote:
Boromir wrote:That seems like a lot of work to me. In blender all I have to do is model a new character. Animations can be carried between models so its easy for me to have lots of different characters with animations as opposed to having to trace thousands of images.
And how hard and time consuming is it to model a new character with clothes?

They seem to use what amounts to virtual clay and would require the same artistic abilities as someone who could sculpt with real clay.
It takes a little time but once you have one character you only have to tweak it to have another. In 3d you have the benefit of not having to redraw everything if you decide to change something later.
I did the viking character in about 6 hours. He has 2 animations walking and chopping.
Post Reply