Kinectã®æåã®éçºèšäºã¯ããã§èªãããšãã§ããŸã ã æåã®éšåãèªãããšã匷ããå§ãããŸããããããªããšã2çªç®ã®éšåã®å°è±¡ãäžå®å šã«ãªããŸãã
ã¯ããã«
æåã®èšäºã§æ¢ã«è¿°ã¹ãããã«ãMicrosoftã®å ¬åŒSDKã«å ããŠããµãŒãããŒãã£ã¡ãŒã«ãŒã®ã©ã€ãã©ãªãããã€ããããŸãã
- OpenKinectãããžã§ã¯ãïŒlibfreenectïŒ
- OpenNIãããžã§ã¯ã
- NUI Groupã«ããNUI CLãããžã§ã¯ã
å ¬åŒã®SDKãšã¯ç°ãªãã代æ¿SDKã¯Linuxããã³Mac OSã§ã®éçºã«äœ¿çšã§ããŸãã
æãç°¡åã«äœ¿çšã§ããã®ã¯libfreenectã§ãïŒOpenNIãå ¬åŒããã¥ã¡ã³ãã«åŸã£ãŠã³ã³ãã€ã«ããã³ã€ã³ã¹ããŒã«ãããŸããããšãã°ãææ°ã®Ubuntuã§äœæ¥ããããããŸããã§ããã ã å ¬åŒææžã«èšèŒãããŠããããšã¯ãã¹ãŠçå®ã§ãããã¯ããæ©èœããŸãã
libfreenectãã€ã³ã¹ããŒã«ãã
Ubuntuã®å Žåãlibfreenectããã€ããªããã±ãŒãžãšããŠå©çšã§ããããšã¯åã°ããããšã§ãã ããã«ãããã€ã³ã¹ããŒã«äžã®æéãå€§å¹ ã«ç¯çŽã§ããŸããäœãåéããŠæ§æããå¿ èŠã¯ãªããäŸåé¢ä¿ãšã©ã€ãã©ãªèªäœãã€ã³ã¹ããŒã«ããã ãã§ãã äŸã¯ãã®ãŸãŸäœ¿çšã§ããŸãã
ããããã€ã³ãã£ã¢ã³ã¯ç°¡åãªæ¹æ³ãæ¢ããŠããªãããããœãŒã¹ããã©ã€ãã©ãªãæ§ç¯ããããã»ã¹ãæ€èšããŸãã ãã®ããã«è¯ãããšã¯äœã§ããïŒ ããã«ãããã©ã€ãã©ãªã«ä»å±ãããµã³ãã«ã®ãœãŒã¹ã³ãŒããååŸããäœãäœã§ããããææ¡ããå¿ èŠã«å¿ããŠãµã³ãã«ã®ãœãŒã¹ã³ãŒããè©Šããããã¹ãŠãã©ã®ããã«æ©èœãããã«ã€ããŠè³ªåãããå Žåã¯ãããã°ããããšãã§ããŸãã
ãã«ãããã»ã¹ïŒ
sudo apt-get install git-core cmake libglut3-dev pkg-config build-essential libxmu-dev libxi-dev libusb-1.0-0-dev
git clone github.com/OpenKinect/libfreenect.git
cd libfreenect
mkdir build
cd build
cmake ..
make
sudo make install
sudo ldconfig /usr/local/lib/
sudo glview
Ubuntu x64ã®å ŽåãæåŸãã2è¡ç®ã¯
/usr/local/lib64/
ãŸãã
ãã®åŸãbuild / binãã©ã«ããŒã§ãµã³ãã«ãå®è¡ã§ããŸã-ã©ã€ãã©ãªãŒã®æ©èœãããããããŸãã
Linuxã«wxWidgetsãã€ã³ã¹ããŒã«ãã
ãã€ããªããã±ãŒãžã¯ãUbuntuã®wxWidgetsã§ã䜿çšã§ããŸãïŒãã ããå®å®ãã2.8.xãã©ã³ãã§ã®ã¿äœ¿çšã§ããŸãããäœæ¥ã«ã¯ååã§ãïŒã ããã±ãŒãžlibwxgtk2.8-devãã€ã³ã¹ããŒã«ãããšãåé¡ã¯è§£æ±ºããŸãã
1ã€ã®ãžã§ãã2åå®è¡ããªãæ¹æ³
ãã€ãŠã Qtã®ã¢ãããŒã¯ã Write OnceãRun Anywhereãã§ããã åããã®ãwxWidgetsã§æŽçããã®ãããã§ãããã ãããç¶æ³ã¯ããœãŒã¹ã³ãŒãã«å ããŠããŸã ãããžã§ã¯ããã¡ã€ã«ãããïŒæåã®éšåã¯Visual Studioãããããžã§ã¯ããååŸããŸããããLinuxã¯ã»ãšãã©åœ¹ã«ç«ã¡ãŸããïŒãæ°ããOSã®ã³ãŒãã®ãã©ãããã©ãŒã äŸåéšåãèšè¿°ããåã«ãã©ã®ããã«ããã°ãããã§ããããžã§ã¯ããã¡ã€ã«ã®äœæãšæ§æãèªååããŸãã CMakeãŠãŒãã£ãªãã£ã¯ããã«åœ¹ç«ã¡ãŸãã
CMakeãè¯ãã®ã¯ãªãã§ããïŒ ãŸããLinuxã¯ãã¹ãŠç°ãªã£ãŠããŸãã ãã·ã³äžã®ãµãŒãããŒãã£ã©ã€ãã©ãªã1ã€ã®ãã¹äžã«ããå Žåããã¹ãŠã®ååãŸãã¯ãŠãŒã¶ãŒãããã«ãããšããäºå®ã§ã¯ãããŸããã åºåpkg-configã䜿çšããå Žåã§ããäžéšã®ãã«ããã©ã¡ãŒã¿ãŒãå€æŽããå Žåãæåã§äœæããããããžã§ã¯ãã§ã¯ãæ°ãããã©ã¡ãŒã¿ãŒãæåã§äœæããå¿ èŠãããå Žæãå€ããããŸãã ç¹å®ã®äœæ¥ãã·ã³çšã«æ¢ã«æ§æãããŠãããããžã§ã¯ããã¡ã€ã«ãäœæããCMakeã䜿çšããŠããã®å°ããªäœæ¥ããã¹ãŠèªååããããšã§ãå€ãã®æéãç¯çŽããããšãã§ããŸãã
Windowsã®å Žåã話ã¯åãã§ããCMakeèªäœãã·ã¹ãã ã«ã€ã³ã¹ããŒã«ãããŠããããªãå€æ°ã®ç°ãªãã©ã€ãã©ãªãæ€çŽ¢ã§ããå Žåããã¹ãŠã®ãã©ã¡ãŒã¿ãŒãæã§ç»é²ãããã©ã¡ãŒã¿ãŒãæ¢ã«æ§æããããããžã§ã¯ããçæããçç±ã§ãã
å®éã«ãããžã§ã¯ããçæããããšã«å ããŠãCMakeã®ã¹ã¯ãªããã§ã¯ãåãã©ãããã©ãŒã ã®æ¡ä»¶ãã©ã¡ãŒã¿ãŒãæå®ã§ããŸããããšãã°ãç¹å®ã®OSã®ãããžã§ã¯ãã«ãã¡ã€ã«ãå«ãã/é€å€ãããç¹å®ã®OSã«åºæã®ãµãŒãããŒãã£ã©ã€ãã©ãªã®äŸåé¢ä¿ãè¿œå ãŸãã¯åé€ãããªã©
ãããã«ããŠããCMakeã®äœ¿çšã«é¢ãããããã¯ã¯å¥ã®èšäºã«å€ããŸãã ç§ãã¡ã®å ŽåãCMakeã¹ã¯ãªããã®ãªã¹ãã§ããã¹ãããªãŒããŒããŒãããªãããã«ããªããžããªãžã®ãªã³ã¯ãæäŸããŸãã
- ãœãªã¥ãŒã·ã§ã³ã®äžè¬èšå®ãšãããžã§ã¯ãã®ãªã¹ããç»é²ãããã¡ã€ã³ã¹ã¯ãªãã
- wxKinectHelperéçã©ã€ãã©ãªãäœæããã¹ã¯ãªãã
- ãã¹ãã¢ããªã±ãŒã·ã§ã³ãããžã§ã¯ããäœæããã¹ã¯ãªãã
ååããåŸããã®ãèŠçŽããŸãããïŒ
- ãœãªã¥ãŒã·ã§ã³ã¯ãwxKinectHelperéçã©ã€ãã©ãªãšKinectTestãã¹ãã¢ããªã±ãŒã·ã§ã³ã®2ã€ã®ãããžã§ã¯ãã«åãããŠããŸãã
- ãããžã§ã¯ããã¡ã€ã«ïŒVisual Studio for Windowsããã³Makefile / CodeBlocks for LinuxïŒã¯ãCMakeãŠãŒãã£ãªãã£ã䜿çšããŠçæãããŸã
- wxKinectHelperãããžã§ã¯ãã«ã¯wxKinectHelperã¯ã©ã¹ããããã·ã¹ãã å ã®Kinectããã€ã¹ã®æ°ãè¿ãããã®ã€ã³ããã¯ã¹ã§ããã€ã¹åã衚瀺ããã°ã©ããŒã¯ã©ã¹ãäœæããããšãã§ããŸã
- ã°ã©ããŒã¯ã©ã¹ã¯ãããã€ã¹ã®ã«ã¡ã©ããç»åïŒæ·±åºŠãè²ïŒããã£ããã£ãããã¬ã€ã€ãŒã®äœçœ®ãåãåãããšãã§ããŸã
- æ°ãããã¬ãŒã ãŸãã¯ãã¬ãŒã€ãŒã®äœçœ®ã«é¢ããæ å ±ãåä¿¡ãããšããã©ãŒã ã¯ã©ã¹ãªã©ã«ãµãã¹ã¯ã©ã€ãã§ããã€ãã³ããããªã¬ãŒãããŸã
- ãã¬ãŒã€ãŒãæç»ããããã«ãwxKinectHelperã¯ã©ã¹ã䜿çšãããŸããããã¯ããã©ãããã©ãŒã ããšã«åå¥ã®å®è£ ã¯ã©ã¹ã䜿çšããããã«ãã£ãŠããªããžãã¿ãŒã³ãå®è£ ããŸãã
- ãã¹ãã¢ããªã±ãŒã·ã§ã³ã¯1ã€ã®ãã©ãŒã ã§æ§æãããããã€ã¹ã®ãªã¹ãã深床ã»ã³ãµãŒããã®ç»åãã«ã¡ã©ããã®ã«ã©ãŒç»åãããã³ãã¬ãŒã€ãŒã®äœçœ®ã衚瀺ã§ããŸãã
çŽ æŽããããã¿ããªèŠããŠãããä»ç§ãã¡ã¯Linuxã®äžã§libfreenectã®åŸæã«é²ãããšãã§ããŸãã
ã³ãŒãã£ã³ã°
ã©ã€ãã©ãªã®åæåãšåæå解é€
APIã䜿çšããŠKinectããã€ã¹ãžã®ã¢ã¯ã»ã¹ãéå§ããåã«ã
freenect_init()
ã¡ãœãããåŒã³åºããŠãé¢æ°ãæ£åžžã«å®äºããå Žåã«ããã€ã³ã¿ãŒãåæåãããã©ã€ãã©ãªã³ã³ããã¹ããå«ãå€æ°ã®ã¢ãã¬ã¹ãæž¡ãå¿ èŠããããŸãã
FREENECTAPI int freenect_init(
freenect_context **ctx,
freenect_usb_context *usb_ctx);
ããã€ã¹ã§ã®äœæ¥ãçµäºãããã
freenect_shutdown()
é¢æ°ã䜿çšããŠã©ã€ãã©ãªã³ã³ããã¹ãã®åæåã
freenect_shutdown()
ããå¿ èŠããããŸãã
FREENECTAPI int freenect_shutdown(freenect_context *ctx);
ã©ãããŒã©ã€ãã©ãªã§ã¯ã
wxKinectHelper
ã¯ã©ã¹ãã©ã€ãã©ãªã³ã³ããã¹ãã®åæåãšåæå
wxKinectHelper
ãè¡ã£ãŠããŸãããã®ãããLinuxã«åãæ¿ããåŸãWindowsãšLinuxã§åäœããã¯ã©ã¹ãåå¥ã«å®è£ ããå¿ èŠããããŸããã
ããã€ã¹ã®ãªã¹ããååŸãã
libfreenectã§äœ¿çšå¯èœãªããã€ã¹ã®æ°ãååŸããã«ã¯ã
freenect_num_devices()
é¢æ°ã䜿çšããŸãã
FREENECTAPI int freenect_num_devices(freenect_context *ctx);
æ®å¿µãªãããlibfreenectã«ã¯åã ã®ããã€ã¹ã®äžæã®ååãååŸããããã®APIãå«ãŸããŠããªããããã¢ããªã±ãŒã·ã§ã³å ã®ããã€ã¹ãäœããã®æ¹æ³ã§èå¥ããã«ã¯ã次ã®ãããªããã€ã¹ã€ã³ããã¯ã¹ãå«ãæååå€ãè¿ããªã©ã®åé¿çãèãåºãå¿ èŠããããŸãïŒ
wxString KinectHelperImplFreenect::GetDeviceName(size_t index)
{
wxString name = wxT( "Unknown Kinect Sensor" );
if (m_Context)
{
name = wxString::Format(wxT( "Kinect %u" ), index);
}
return name;
}
Kinectç»åãã£ããã£
libfreenectã©ã€ãã©ãªã§Kinectããç»åããã£ããã£ããã«ã¯ãåæããŒãžã§ã³ãŸãã¯éåæããŒãžã§ã³ã®APIã䜿çšãã2ã€ã®æ¹æ³ããããŸãã éåæãªãã·ã§ã³ã®å Žåãæ°ãããã¬ãŒã ãå°çãããšãã³ãŒã«ããã¯é¢æ°ãåŒã³åºãããçä¿¡ãããã¡ãåŠçã§ããŸãã ãããã¡ã®ã¡ã¢ãªã¯åå¥ã«å²ãåœãŠãããšãã§ããŸãããŸãã¯ãã©ã€ãã©ãªèªäœãå éšãããã¡ãäœæããäœæ¥ã®å®äºæã«ã¡ã¢ãªãã¯ãªã¢ããŸãã
ç»åã®ãã£ããã£ãéå§ããã«ã¯ã
freenect_open_device()
é¢æ°ãåŒã³åºãå¿ èŠããããŸãããã®é¢æ°ã¯ãã©ã¡ãŒã¿ãŒãšããŠåãåããŸãã
- ã©ã€ãã©ãªã³ã³ããã¹ããã€ã³ã¿ãŒ
- é¢æ°ãæ£åžžã«å®äºããå Žåãããã€ã¹ã³ã³ããã¹ããå«ãå€æ°ãžã®ãã€ã³ã¿ãŒ
- ããã€ã¹ã€ã³ããã¯ã¹
FREENECTAPI int freenect_open_device(
freenect_context *ctx,
freenect_device **dev, int index);
ç»åã®ãã£ããã£ãå®äºããã«ã¯ã
freenect_close_device()
é¢æ°ãåŒã³åºãå¿ èŠããããŸãã
FREENECTAPI int freenect_close_device(freenect_device *dev);
APIã¯ãéåæãã§ãããå¶åŸ¡ãããŒãæåã§äœæããªããšå®è¡ã§ããŸããã æã ãlibusbããã€ãã³ããã¥ãŒãåŠçãã
freenect_process_events()
é¢æ°ãåŒã³åºãå¿ èŠããããŸãã wxWidgetsã¢ããªã±ãŒã·ã§ã³ã§ã¯ãã€ãã³ãåŠçãããŒã¯æ¬¡ã®ããã«ç·šæã§ããŸãã
wxThread::ExitCode KinectGrabberFreenect::Entry()
{
int status(0);
while (!GetThread()->TestDestroy() && status >= 0)
{
status = freenect_process_events(m_Context);
}
return NULL;
}
深床ãããã¡ã®ååŸ
深床ãããã¡ä»ãã®ãã¬ãŒã ã®åä¿¡ãéå§ããã«ã¯ãããã€ã¹ã®åäœã¢ãŒããæ§æããããã€ãã®é¢æ°ãåŒã³åºãå¿ èŠããããŸãã
-
freenect_set_depth_callback()
ã䜿çšããŠãæ°ãããã¬ãŒã ã深床ãããã¡ãŒã§å°çãããšãã«åŒã³åºãããé¢æ°ãæå®ã§ããŸãã -
freenect_set_depth_buffer()
ã䜿çšããŠãlibfreenectãããã€ã¹ãã深床ã€ã³ãžã±ãŒã¿ãŒãèšé²ããã¡ã¢ãªé åãèšå®ã§ããŸãïŒããã¯ãªãã·ã§ã³ã®æé ã§ãããããŒã¿ã®åŸåŠçãå¿ èŠãªå Žåã¯ãã®é¢æ°ã䜿çšãããšäŸ¿å©ã§ãïŒ -
freenect_set_depth_mode()
é¢æ°ã䜿çšããŠãããã€ã¹ã®åäœã¢ãŒããèšå®ããå¿ èŠããããŸãã freenect_frame_modeæ§é äœã¯ããã®é¢æ°ã®ãã©ã¡ãŒã¿ãŒã«æž¡ãããç®çã®ç»åãµã€ãºãšããŒã¿åœ¢åŒã«é¢ããæ å ±ãå«ãŸããŸãã
freenect_resolutionã®å€ã¯æ¬¡ã®ãšããã§ãã
typedef enum {
FREENECT_RESOLUTION_LOW = 0, /**< QVGA - 320x240 */
FREENECT_RESOLUTION_MEDIUM = 1, /**< VGA - 640x480 */
FREENECT_RESOLUTION_HIGH = 2, /**< SXGA - 1280x1024 */
FREENECT_RESOLUTION_DUMMY = 2147483647, /**< Dummy value to force enum to be 32 bits wide */
} freenect_resolution;
ãããŠããã®ãããªfreenect_depth_formatã®å ŽåïŒ
typedef enum {
FREENECT_DEPTH_11BIT = 0, /**< 11 bit depth information in one uint16_t/pixel */
FREENECT_DEPTH_10BIT = 1, /**< 10 bit depth information in one uint16_t/pixel */
FREENECT_DEPTH_11BIT_PACKED = 2, /**< 11 bit packed depth information */
FREENECT_DEPTH_10BIT_PACKED = 3, /**< 10 bit packed depth information */
FREENECT_DEPTH_DUMMY = 2147483647, /**< Dummy value to force enum to be 32 bits wide */
} freenect_depth_format;
説æãããããããã«ãlibfreenectã§ã¯ãMicrosoftã®å ¬åŒSDKãšã¯ç°ãªãã深床å€ã«ã¯12ãããã§ã¯ãªã11ãããã®ã¿ã䜿çšãããŸãããã¬ãŒã€ãŒã€ã³ããã¯ã¹ãååŸããæ¹æ³ããããŸããã
ã«ã©ãŒç»åãååŸãã
ååãšããŠãããã€ã¹ãã»ããã¢ããããŠã«ã©ãŒç»åãååŸããããã®ã¢ã«ãŽãªãºã ã¯ã深床ãããã¡ãŒãååŸããããã®ã¢ã«ãŽãªãºã ã«äŒŒãŠãããé¢æ°
freenect_set_video_callback()
ã
freenect_set_video_buffer()
ããã³
freenect_set_video_mode()
ã®ã¿ããããã䜿çšãããŸãã
ç»åãã£ããã£ã«é¢ããããã€ãã®ããäžè¬çãªæ å ±
äžèšã®ãã¹ãŠã®åŸãç»åãã£ããã£ã®åæåã³ãŒããèŠãŠã¿ãŸãããã
if (freenect_open_device(m_Context, &m_Device,
( int )m_DeviceIndex) < 0) break ;
freenect_set_depth_callback(m_Device, KinectGrabberFreenect::DepthCallback);
freenect_set_video_callback(m_Device, KinectGrabberFreenect::VideoCallback);
freenect_set_video_mode(m_Device, m_VideoMode);
freenect_set_depth_mode(m_Device, m_DepthMode);
m_VideoBufferLength = m_VideoMode.bytes;
m_DepthBufferLength = m_DepthFrameSize.GetWidth() * m_DepthFrameSize.GetHeight() * 3;
m_VideoBuffer = new unsigned char [m_VideoBufferLength];
m_DepthBufferIndex = 0;
m_GotDepth = false ;
m_DepthBuffers[0] = new unsigned char [
m_DepthFrameSize.GetWidth() *
m_DepthFrameSize.GetHeight() * 3];
m_DepthBuffers[1] = new unsigned char [
m_DepthFrameSize.GetWidth() *
m_DepthFrameSize.GetHeight() * 3];
freenect_set_video_buffer(m_Device, m_VideoBuffer);
DeviceHash[m_Device] = this ;
freenect_start_video(m_Device);
freenect_start_depth(m_Device);
ãªããªã 深床ãããã¡ã®ããŒã¿åœ¢åŒã¯ãããã«ç°ãªãã深床å€ãã°ã¬ãŒã¹ã±ãŒã«ã«å€æããæ©èœãå°ãå€æŽãããŠããŸãã
unsigned char KinectGrabberFreenect::GetDepthValue(unsigned short data)
{
// 0x7ff is 0000011111111111 in binary format - max value for 11bit depth;
return ( double )255 * ( double )data / ( double )0x7ff;
}
説æãããŠãããã¹ãŠã®ã¢ã¯ã·ã§ã³ã®çµæãšããŠãæ°ããã¯ã©ã¹ã®ã°ã©ããŒãäœæãããŸãããããã¯Linuxã§éåžžã«ããŸãæ©èœããŸãã æ®å¿µãªãããlibfreenectã«ã¯ãã¬ãŒã€ãŒã®äœçœ®ãååŸããããã®APIã¯ãããŸããããããã®ç®çã®ããã«ãããšãã°OpenCVã«åºã¥ãããµãŒãããŒãã£ïŒãŸãã¯ç¬èªã®ïŒéçºã䜿çšããå¿ èŠããããŸãã ããããããã¯ãããšãã°åãã®èªèã«ã¯ååã§ãã
çµè«ãšããŠ
ç§ãã¡ã¯ä»ã®ãšããçè«ã§çµãããšæããŸãã 次ã®ããŒãã¯ç·Žç¿ã§ãã
Kinectã䜿çšããããã®ãµã³ãã«ããã³ã©ãããŒã©ã€ãã©ãªã®ãã¹ãŠã®ãœãŒã¹ã³ãŒãã¯ã ããããããŠã³ããŒãã§ããŸã ã
Windowsã®ãããžã§ã¯ããã¡ã€ã«ã¯ãLinuxã®build / cm.batã¹ã¯ãªããã䜿çšããŠçæã§ããŸã-build / cmLinux.sh
ãŸããLinuxããã³Mac OSçšã®OpenNIã䜿ãããªãããã®æ¯æŽãæåŠããŸããã