http://www.sigvc.org/bbs/thread-722-1-1.html
在本文中將詳細梳理使用Kinect進行3d掃描的過程,一共包含3種實現方法:processing編程實現、skanect軟件實現、ReconstructMe軟件實現。RecontructMe只能基於32位系統的驅動與kinect連接,而skanect與processing不論是32位還是64位都可以較好的兼容。
Comparison of ReconstructMe, KinectFusion and Skanect:
我們首先來看ReconstructMe:
ReconstructMe是基於32位系統的,但是在64位操作系統下仍舊使用32位的kinect驅動以及ReconstructMe。
ReconstructMe官方網址:http://reconstructme.net/
官網中針對不同的用戶,有免費版以及收費版兩種軟件,具體下載地址爲:http://reconstructme.net/projects/reconstructme-console/
下載完成以後,先不要安裝,在安裝ReconstructMe之前我們首先需要安裝Kinect的驅動,具體步驟如下:
-
下載32位openni驅動包,下載地址:
https://www.dropbox.com/s/n55mr8q1j0nzyru/Sensor%20Driver%20Package%
20×86%201.5.2.zip
堅果雲下載地址:
https://jianguoyun.com/c/pubfile/uGqA8e_Y18lRqUluPrFMdXnCzq3o0ko9_Eh_5yDu-3U
2.解壓驅動包,首先安裝OpenNI,再然後是SensorKinect,然後是SensorPrimesense。(在安裝之前,一定要把原來kinect的驅動卸載掉)
3.全部安裝完成以後,重啓
4.將你的Kinect連接上電腦,可以通過查看控制面板中的設備管理器,檢查你的電腦是否已 經識別Kinect.
5.確認Kinect已經能和電腦通信之後,安裝下載好的ReconstructMe,安裝完以後運行目錄中的Start ReconstructMe Scan OpenNI.bat,注意不是ReconstructMe.exe。然後根據提示進行操作即可
附圖:
接下來是通過skanect進行3d掃描:
Skanect官方網址:http://skanect.manctl.com
下載地址:http://manctl.com/products.html(頁面中含有詳細的安裝步驟,但是一些鏈接已經失效,在後面的安裝步驟中含有其他下載鏈接)
詳細安裝步驟:
- 下載skanect
-
下載kinect驅動包:
https://www.dropbox.com/s/734160v5imqyd5d/kinect%20driver%20package%20for%2064bit.zip
堅果雲下載地址:
https://jianguoyun.com/c/pubfile/sm_vNwOtndapU8ya3p46l6BXj-ujPkDmnt7JrTnhjoc
3. 下載完驅動包以後,首先安裝OpenNI,然後是NITE,再然後是sensor(此文件也就是Primesense),最後是SensorKinect.
4.把kinect通過USB連接到電腦,檢查控制面板中的設備管理器,判斷是否已經連接成功。
5.安裝skanect並運行skanect.exe
(備註:
1. 若基於32位操作系統,當使用skanect應下載之前ReconstructMe的所需的驅動,並附加NITE(具體安裝順序如上所示):
dropbox下載:https://www.dropbox.com/s/alvz98xzchlhlqj/NITE-Win32-1.5.2.21-Dev.zip
堅果雲下載:
https://jianguoyun.com/c/pubfile/pw4suN5cAEsSIyTDyMGLaoAIw3Dfc6baECBR_1udBkY
2. 若運行skanect時,提示未查找到openni.dll則需根據你安裝的目錄找到openni.dll並複製到system32中!)
附圖:
最後一種方法是通過processing編程實現,對於使用過Processing或者java的人比較適用。雖然自己之前沒有接觸過java,但還是嘗試了一下,歡迎大家一起折騰,具體步驟:
- 首先還是需要安裝Kinect的驅動(本人親測爲安裝64位的驅動,如果你使用的操作系統是32位的還需安裝NITE,因爲後面調用processing庫是需使用到)
-
Processing的simple-openni庫下載及安裝:
(木有接觸過processing的,百度一下即可找到,下載該軟件並根據官網指示瞭解如何安裝庫文件)
3.Coding!
Processing代碼:
-
import processing.opengl.*;
-
import SimpleOpenNI.*;
-
import kinectOrbit.*;
-
KinectOrbit myOrbit;
-
SimpleOpenNI kinect;
-
String turnTableAngle = "0";
-
ArrayList scanPoints = new ArrayList(); // PointCloud
-
ArrayList scanColors = new ArrayList(); // Object Colors
-
ArrayList objectPoints = new ArrayList(); // PointCloud
-
ArrayList objectColors = new ArrayList(); // Object Colors
-
float baseHeight = ; // Height of the Model's base//1
-
-
float modelWidth = ;//2
-
-
float modelHeight = ;//3
-
-
PVector axis = new PVector(0, baseHeight, );//4
-
-
int scanLines = 200;
-
int scanRes = 1;
-
float[] shotNumber = new float[3];
-
int currentShot = 0;
-
-
public void setup()
-
{
-
size(800, 600, OPENGL);
-
// Orbit
-
myOrbit = new KinectOrbit(this, 0, "kinect");
-
myOrbit.drawCS(true);
-
myOrbit.drawGizmo(true);
-
myOrbit.setCSScale( );//5
-
-
myOrbit.drawGround(true);
-
// Simple-openni
-
kinect = new SimpleOpenNI(this);
-
kinect.setMirror(false);
-
kinect.enableDepth();
-
kinect.enableRGB();
-
kinect.alternativeViewPointDepthToImage();
-
for (int i = 0; i < shotNumber.length; i++)
-
{
-
shotNumber<i> = i * (2 * PI) / shotNumber.length;
-
}
-
}
-
-
public void draw()
-
{
-
kinect.update(); // Update Kinect data
-
background(0);
-
myOrbit.pushOrbit(this); // Start Orbiting
-
drawPointCloud(5);
-
updateObject(scanLines, scanRes);
-
if(currentShot>0&¤tShot<4)
-
{
-
scan();
-
}
-
drawObjects();
-
drawBoundingBox(); // Draw Box Around Scanned Objects
-
kinect.drawCamFrustum(); // Draw the Kinect cam
-
myOrbit.popOrbit(this); // Stop Orbiting
-
}
-
-
void drawPointCloud(int steps)
-
{
-
// draw the 3D point depth map
-
int index;
-
PVector realWorldPoint;
-
stroke(255);
-
for (int y = 0; y < kinect.depthHeight(); y += steps)
-
{
-
for (int x = 0; x < kinect.depthWidth(); x += steps)
-
{
-
index = x + y * kinect.depthWidth();
-
realWorldPoint = kinect.depthMapRealWorld()[index];
-
stroke(150);
-
point(realWorldPoint.x, realWorldPoint.y, realWorldPoint.z);
-
}
-
}
-
}
-
-
void drawObjects()
-
{
-
pushStyle();
-
strokeWeight(4);
-
for (int i = 1; i < objectPoints.size(); i++)
-
{
-
stroke(objectColors.get(i).x, objectColors.get(i).y, objectColors.get(i).z);
-
point(objectPoints.get(i).x, objectPoints.get(i).y, objectPoints.get(i).z + axis.z);
-
}
-
for (int i = 1; i < scanPoints.size(); i++)
-
{
-
stroke(scanColors.get(i).x, scanColors.get(i).y, scanColors.get(i).z);
-
point(scanPoints.get(i).x, scanPoints.get(i).y, scanPoints.get(i).z + axis.z);
-
}
-
popStyle();
-
}
-
-
void drawBoundingBox()
-
{
-
stroke(255, 0, 0);
-
line(axis.x, axis.y, axis.z, axis.x, axis.y + 100, axis.z);
-
noFill();
-
pushMatrix();
-
translate(axis.x, axis.x + baseHeight + modelHeight / 2, axis.z);
-
box(modelWidth, modelHeight, modelWidth);
-
popMatrix();
-
}
-
-
void scan()
-
{
-
for (PVector v : scanPoints)
-
{
-
boolean newPoint = true;
-
for (PVector w : objectPoints)
-
{
-
if (v.dist(w) < 1)
-
newPoint = false;
-
}
-
if (newPoint)
-
{
-
objectPoints.add(v.get());
-
int index = scanPoints.indexOf(v);
-
objectColors.add(scanColors.get(index).get());
-
}
-
}
-
}
-
-
void updateObject(int scanWidth, int step)
-
{
-
int index;
-
PVector realWorldPoint;
-
scanPoints.clear();
-
scanColors.clear();
-
float angle=(currentShot-1)*2*PI/3;
-
rotateY(angle);
-
line(0,0,100,0);//draw a line at the base of the bounding box to indicate the rotation
-
int xMin = (int) (kinect.depthWidth() / 2 - scanWidth / 2);
-
int xMax = (int) (kinect.depthWidth() / 2 + scanWidth / 2);
-
for (int y = 0; y < kinect.depthHeight(); y += step)
-
{
-
for (int x = xMin; x < xMax; x += step)
-
{
-
index = x + (y * kinect.depthWidth());
-
realWorldPoint = kinect.depthMapRealWorld()[index];
-
color pointCol = kinect.rgbImage().pixels[index];
-
if (realWorldPoint.y < modelHeight + baseHeight && realWorldPoint.y > baseHeight)
-
{
-
if (abs(realWorldPoint.x - axis.x) < modelWidth / 2)
-
{ // Check x
-
if (realWorldPoint.z < axis.z + modelWidth / 2 && realWorldPoint.z > axis.z -modelWidth / 2)
-
{ // Check z
-
PVector rotatedPoint;
-
realWorldPoint.z -= axis.z;
-
realWorldPoint.x -= axis.x;
-
rotatedPoint = vecRotY(realWorldPoint, angle);
-
scanPoints.add(rotatedPoint.get());
-
scanColors.add(new PVector(red(pointCol), green(pointCol), blue(pointCol)));
-
}
-
}
-
}
-
}
-
}
-
}
-
-
PVector vecRotY(PVector vecIn, float phi)
-
{
-
// Rotate the vector around the y-axis
-
PVector rotatedVec = new PVector();
-
rotatedVec.x = vecIn.x * cos(phi) - vecIn.z * sin(phi);
-
rotatedVec.z = vecIn.x * sin(phi) + vecIn.z * cos(phi);
-
rotatedVec.y = vecIn.y;
-
return rotatedVec;
-
}
-
-
public void keyPressed() {
-
switch(key)
-
{
-
case 's':
-
currentShot++;
-
break;
-
case 'c': // Clear the object points
-
objectPoints.clear();
-
objectColors.clear();
-
currentshot=0;
-
break;
-
case 'e': // Export the object points
-
exportPly('0');
-
break;
-
case '+': // Increment the number of scanned lines
-
scanLines++;
-
println(scanLines);
-
break;
-
case '-': // Decrease the number of scanned lines
-
scanLines--;
-
println(scanLines);
-
break;
-
}
-
}
代碼下載地址:
Dropbox下載:https://www.dropbox.com/s/90fttmvheag2k2r/scan.pde
堅果雲下載:https://jianguoyun.com/c/pubfile/GHAf-ZzTMjgr1KNNinHgpWf7QKdTmBu2Z-2SIU_YbE8
收工!