Skip to content

Commit

Permalink
Release 10-29
Browse files Browse the repository at this point in the history
These changes provide less bugs,more functions and better interface
  • Loading branch information
DZP committed Oct 29, 2014
1 parent bc7a41b commit adad507
Show file tree
Hide file tree
Showing 18 changed files with 387 additions and 590 deletions.
13 changes: 0 additions & 13 deletions Duke/Duke.pro
Original file line number Diff line number Diff line change
Expand Up @@ -47,16 +47,3 @@ HEADERS += \
utilities.h \
virtualcamera.h

OTHER_FILES += \
Resource/cal.png \
Resource/calib.png \
Resource/camera.png \
Resource/close.png \
Resource/new.png \
Resource/open.png \
Resource/projector.png \
Resource/reconstruct.png \
Resource/save.png \
Resource/scan.png \
Resource/set.png \
Resource/splash.png
2 changes: 1 addition & 1 deletion Duke/Duke.pro.user
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE QtCreatorProject>
<!-- Written by QtCreator 3.2.1, 2014-10-21T15:23:36. -->
<!-- Written by QtCreator 3.2.1, 2014-10-29T16:39:33. -->
<qtcreator>
<data>
<variable>EnvironmentId</variable>
Expand Down
6 changes: 3 additions & 3 deletions Duke/graycodes.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ IplImage* GrayCodes::getNextImg()
if(currentImgNum<numOfImgs)
{
currentImgNum++;
return grayCodes[currentImgNum-1];
return grayCodes[currentImgNum - 1];//currentImgNum是从0开始的,++操作后变为1,所以要-1
}
else
return NULL;
Expand Down Expand Up @@ -178,10 +178,10 @@ void GrayCodes::save()

int GrayCodes::grayToDec(cv::vector<bool> gray)//convert a gray code sequence to a decimal number
{
int dec=0;
int dec = 0;
bool tmp = gray[0];
if(tmp)
dec+=(int) pow((float)2,int (gray.size() -1));
dec += (int) pow((float)2,int (gray.size() -1));
for(int i=1; i< gray.size(); i++)
{
tmp=Utilities::XOR(tmp,gray[i]);
Expand Down
3 changes: 3 additions & 0 deletions Duke/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,9 @@ int main(int argc, char *argv[])
* 10-20
* 成功将大恒相机移植到Qt环境,对rawbuffer的调取没有采用callback函数,而是通过定时器触发信号槽的形式
* 对QImage*指针指向图片的操作,应首先将其转换为QPixmap,再进行缩放、变形等操作
* ******************************************************
* 10-25
* 改进了扫描图像的采集方式,利用单帧采集函数采集,在投影和采集之间添加延时
*
*
*
Expand Down
380 changes: 75 additions & 305 deletions Duke/mainwindow.cpp

Large diffs are not rendered by default.

12 changes: 12 additions & 0 deletions Duke/mainwindow.h
Original file line number Diff line number Diff line change
Expand Up @@ -179,11 +179,22 @@ class MainWindow : public QMainWindow
HHV m_hhv_1; ///< 数字摄像机句柄
HHV m_hhv_2;

BYTE *ppBuf_1[1];
BYTE *ppBuf_2[1];

BYTE *m_pRawBuffer_1; ///< 采集图像原始数据缓冲区
BYTE *m_pRawBuffer_2;

static int CALLBACK SnapThreadCallback(HV_SNAP_INFO *pInfo);
////////////////////////////////////////////////
///与set对话框有关的变量
int black_ ;
int white_;
bool isAutoContrast;
bool isSaveAutoContrast;
bool isRaySampling;
bool isExportObj;
bool isExportPly;

private slots:
void newproject();
Expand All @@ -199,6 +210,7 @@ private slots:
void scan();
void reconstruct();
void set();
void getSetInfo();
};

#endif // MAINWINDOW_H
93 changes: 45 additions & 48 deletions Duke/meshcreator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@

MeshCreator::MeshCreator(PointCloudImage *in)
{
cloud=in;
w=cloud->getWidth();
h=cloud->getHeight();
cloud = in;
w = cloud->getWidth();
h = cloud->getHeight();
pixelNum = new int[w*h];
}

Expand All @@ -22,43 +22,43 @@ void MeshCreator::exportObjMesh(QString path)
std::string cstr = qstringToString(path);
out1.open(cstr);

for(int i=0; i<w;i++)
for(int i = 0; i<w;i++)
{
for(int j=0; j<h; j++)
for(int j = 0; j<h; j++)
{
return_val = cloud->getPoint(i,j,point);
return_val = cloud -> getPoint(i, j, point);
if(return_val)
{
pixelNum[access(i,j)]=count;
pixelNum[access(i, j)]=count;
out1<<"v "<< point.x<< " "<< point.y<< " "<<point.z<< "\n";
count++;
}
else
pixelNum[access(i,j)]=0;
pixelNum[access(i, j)]=0;
}
}

for(int i=0; i<w;i++)
for(int i = 0; i < w;i++)
{
for(int j=0; j<h; j++)
for(int j = 0; j < h; j++)
{
int v1=pixelNum[access(i,j)],v2,v3;
int v1 = pixelNum[access(i, j)],v2,v3;

if(i<w-1)
v2=pixelNum[access(i+1,j)];
if(i < w - 1)
v2 = pixelNum[access(i + 1, j)];
else
v2=0;

if(j<h-1)
v3=pixelNum[access(i,j+1)];
if(j < h - 1)
v3 = pixelNum[access(i, j + 1)];
else
v3=0;
v3 = 0;

if(v1!=0 && v2!=0 && v3!=0)
if(v1 != 0 && v2 != 0 && v3 != 0)
out1<<"f "<< v1<<"/"<<v1<< " "<< v2<<"/"<<v2<< " "<<v3<<"/"<<v3<<"\n";

if(j>0&&i<w-1)
v3=pixelNum[access(i+1,j-1)];
if(j > 0&&i < w - 1)
v3 = pixelNum[access(i+1,j-1)];
else
v3=0;

Expand All @@ -78,35 +78,30 @@ void MeshCreator::exportPlyMesh(QString path)
std::ofstream out1;
std::string cstr = qstringToString(path);
out1.open(cstr);

int vertexCount = 0;//find vertex num

for(int i=0; i<w;i++)
{
for(int j=0; j<h; j++)
{
if(cloud->getPoint(i,j,point))
if(cloud->getPoint(i, j, point))
{
pixelNum[access(i,j)]=vertexCount;
pixelNum[access(i, j)] = vertexCount;
vertexCount++;
}
else
pixelNum[access(i,j)]=0;
pixelNum[access(i, j)]=0;
}
}

int facesCount = 0;//find faces num

for(int i=0; i<w;i++)
{
for(int j=0; j<h; j++)
{
int v1=pixelNum[access(i,j)],v2,v3;

if(i < w-1)
v2=pixelNum[access(i+1,j)];
int v1 = pixelNum[access(i,j)],v2,v3;
if(i < w - 1)
v2 = pixelNum[access(i+1,j)];
else
v2=0;
v2 = 0;

if(j < h-1)
v3=pixelNum[access(i,j+1)];
Expand Down Expand Up @@ -144,39 +139,41 @@ void MeshCreator::exportPlyMesh(QString path)
{
for(int j=0; j<h; j++)
{
return_val = cloud->getPoint(i,j,point,color);
return_val = cloud->getPoint(i, j, point);
if(return_val)
{
out1<< point.x << " " << point.y << " " << point.z << " "<< (int) color[2] << " " << (int) color[1] << " " << (int) color[0] << "\n";
out1<< point.x << " " << point.y << " " << point.z << " "<< 10 << " " << 10 << " " << 10 << "\n";
//这里去掉了表示颜色的项,统一赋值为10
//out1<< point.x << " " << point.y << " " << point.z << " "<< (int) color[2] << " " << (int) color[1] << " " << (int) color[0] << "\n";
}
else
pixelNum[access(i,j)]=0;
pixelNum[access(i, j)]=0;
}
}

for(int i=0; i<w;i++)
for(int i = 0; i < w;i++)
{
for(int j=0; j<h; j++)
for(int j = 0; j < h; j++)
{
int v1=pixelNum[access(i,j)],v2,v3;
int v1 = pixelNum[access(i, j)], v2, v3;

if(i<w-1)
v2=pixelNum[access(i+1,j)];
if(i < w - 1)
v2 = pixelNum[access(i + 1, j)];
else
v2=0;
v2 = 0;

if(j<h-1)
v3=pixelNum[access(i,j+1)];
v3 = pixelNum[access(i, j + 1)];
else
v3=0;
v3 = 0;

if(v1!=0 && v2!=0 && v3!=0)
if(v1 != 0 && v2 != 0 && v3 != 0)
out1 << "3 " << v1 << " " << v2 << " " << v3 << "\n";

if(j>0&&i<w-1)
v3=pixelNum[access(i+1,j-1)];
if(j > 0 && i< w - 1)
v3 = pixelNum[access(i + 1, j - 1)];
else
v3=0;
v3 = 0;

if(v1!=0 && v2!=0 && v3!=0)
out1 << "3 " << v1 << " " << v3 << " " << v2 << "\n";
Expand All @@ -185,9 +182,9 @@ void MeshCreator::exportPlyMesh(QString path)
out1.close();
}

int MeshCreator::access(int i,int j)
int MeshCreator::access(int i, int j)
{
return i*h+j;
return i * h + j;
}

std::string MeshCreator::qstringToString(QString qstring)
Expand Down
26 changes: 13 additions & 13 deletions Duke/pointcloudimage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,16 @@

PointCloudImage::PointCloudImage(int imageW,int imageH, bool colorFlag)
{
w=imageW;
h=imageH;
points = cv::Mat(h,w,CV_32FC3);
if(colorFlag==true)
w = imageW;
h = imageH;
points = cv::Mat(h, w, CV_32FC3);
if(colorFlag == true)
{
color = cv::Mat(h,w,CV_32FC3,cv::Scalar(0));
color = cv::Mat(h, w, CV_32FC3,cv::Scalar(0));
}
else
color = NULL;
numOfPointsForPixel = cv::Mat(h,w,CV_8U,cv::Scalar(0));
numOfPointsForPixel = cv::Mat(h, w, CV_8U, cv::Scalar(0));
}

PointCloudImage::~PointCloudImage(void)
Expand All @@ -23,7 +23,7 @@ bool PointCloudImage::setPoint(int i_w, int j_h, cv::Point3f point, cv::Vec3f co
if(i_w>w || j_h>h)
return false;
setPoint(i_w,j_h,point);
Utilities::matSet3D(color,i_w,j_h,colorBGR);
//Utilities::matSet3D(color,i_w,j_h,colorBGR);//这里暂时注释掉
return true;
}

Expand Down Expand Up @@ -80,16 +80,16 @@ bool PointCloudImage::getPoint(int i_w, int j_h, cv::Point3f &pointOut)

bool PointCloudImage::addPoint(int i_w, int j_h, cv::Point3f point, cv::Vec3f colorBGR)
{
if(i_w>w || j_h>h)
if(i_w > w || j_h > h)
return false;
uchar num = numOfPointsForPixel.at<uchar>(j_h,i_w);
uchar num = numOfPointsForPixel.at<uchar>(j_h, i_w);
if(num == 0)
return setPoint(i_w,j_h,point,colorBGR);
addPoint(i_w,j_h,point);
return setPoint(i_w, j_h, point, colorBGR);
addPoint(i_w, j_h, point);
if(!color.empty())
{
cv::Vec3f c = Utilities::matGet3D(color,i_w,j_h);
Utilities::matSet3D(color,i_w,j_h,colorBGR + c);
cv::Vec3f c = Utilities::matGet3D(color, i_w, j_h);
Utilities::matSet3D(color, i_w, j_h, colorBGR + c);
}
else
{
Expand Down
39 changes: 7 additions & 32 deletions Duke/projector.cpp
Original file line number Diff line number Diff line change
@@ -1,14 +1,11 @@
#include "projector.h"
#include <QLayout>
Projector::Projector(int projW, int projH, int scrnW)
Projector::Projector(QWidget *parent, int projW, int projH, int xos, int yos) : QWidget(parent)
{
width = projW;
height = projH;
scrnwidth = scrnW;//main screen width
pW = new QWidget();//projector window
pW->move(scrnwidth,0);//make the window displayed by the projector
pW->showFullScreen();
imageLabel = new QLabel(pW);
xoffset = xos;
yoffset = yos;
}

Projector::~Projector()
Expand All @@ -19,8 +16,8 @@ void Projector::opencvWindow()
{
cvNamedWindow("Projector Window",CV_WINDOW_NORMAL);
cvResizeWindow("Projector Window",width,height);
cvMoveWindow("Projector Window", scrnwidth, 0);
cvSetWindowProperty("Projector Window", CV_WND_PROP_FULLSCREEN, CV_WINDOW_FULLSCREEN);
cvMoveWindow("Projector Window", xoffset, yoffset);
//cvSetWindowProperty("Projector Window", CV_WND_PROP_FULLSCREEN, CV_WINDOW_FULLSCREEN);
}

void Projector::showImg(IplImage *img)
Expand All @@ -40,11 +37,10 @@ void Projector::destoryWindow()

void Projector::displaySwitch(bool isWhite)
{
pW->setAutoFillBackground(true);//necessary when using palette
if(isWhite)
pW->setPalette(Qt::white);//set the background color to be white, aka open the light
this->setPalette(Qt::white);
else
pW->setPalette(Qt::black);
this->setPalette(Qt::black);
}

QImage* Projector::IplImageToQPixmap(const IplImage *img)
Expand All @@ -55,27 +51,6 @@ QImage* Projector::IplImageToQPixmap(const IplImage *img)
image=new QImage(imgData,img->width,img->height,QImage::Format_Indexed8);
return image;
delete imgData;
/*
const uchar* imgData = (const uchar*)(img->imageData);
QPixmap *qpix;
qpix->loadFromData(imgData,8);
return qpix;
delete imgData;
unsigned char* ptrQImage;
if(img->nChannels==1){
for(int row=0;row<img->height;row++){
unsigned char* ptr=(unsigned char*)(img->imageData+row*img->widthStep);
for(int col=0;col<img->width;col++){
*(ptrQImage)=*(ptr+col);
*(ptrQImage+1)=*(ptr+col);
*(ptrQImage+2)=*(ptr+col);
*(ptrQImage+3)=0;
ptrQImage+=4;
}
}
}
*/
}

IplImage* Projector::QImageToIplImage(const QImage *qImage)
Expand Down
Loading

0 comments on commit adad507

Please sign in to comment.