|
@@ -95,11 +95,11 @@ MainWindow::MainWindow(QWidget *parent) :
|
|
|
|
|
|
gw = this;
|
|
gw = this;
|
|
mTime.start();
|
|
mTime.start();
|
|
- mnlidarcount = 0;
|
|
|
|
- mnonepcd = 0;
|
|
|
|
|
|
+ mnsaveone = 0;
|
|
mbSaveOne = false;
|
|
mbSaveOne = false;
|
|
mbSave = false;
|
|
mbSave = false;
|
|
mnsave = 0;
|
|
mnsave = 0;
|
|
|
|
+ mnpiccount = 0;
|
|
|
|
|
|
mbOpen = false;
|
|
mbOpen = false;
|
|
|
|
|
|
@@ -117,27 +117,25 @@ MainWindow::MainWindow(QWidget *parent) :
|
|
|
|
|
|
scene = new QGraphicsScene;
|
|
scene = new QGraphicsScene;
|
|
|
|
|
|
- CreateView();
|
|
|
|
|
|
+ QString strpath = QCoreApplication::applicationDirPath();
|
|
|
|
+ strpath = strpath + "/picview_usbport.xml";
|
|
|
|
|
|
- int i;
|
|
|
|
- for(i=0;i<MAX_CAMERA;i++)
|
|
|
|
- {
|
|
|
|
- mpicindex[i] = 0;
|
|
|
|
- mpicviewindex[i] = 0;
|
|
|
|
- }
|
|
|
|
|
|
+ std::cout<<strpath.toStdString()<<std::endl;
|
|
|
|
+ iv::xmlparam::Xmlparam xp(strpath.toStdString());
|
|
|
|
+
|
|
|
|
+ mnwidth = xp.GetParam("Width",1920);
|
|
|
|
+ mnheight = xp.GetParam("Height",1080);
|
|
|
|
+ mnFrameRate = xp.GetParam("FrameRate",30);
|
|
|
|
+
|
|
|
|
+ CreateView();
|
|
|
|
|
|
- mCurCameraIndex = 0;
|
|
|
|
|
|
|
|
// myview->scale(0.3,0.3);
|
|
// myview->scale(0.3,0.3);
|
|
// myview->show();
|
|
// myview->show();
|
|
|
|
|
|
- QString strpath = QCoreApplication::applicationDirPath();
|
|
|
|
|
|
|
|
|
|
|
|
- strpath = strpath + "/picview.xml";
|
|
|
|
|
|
|
|
- std::cout<<strpath.toStdString()<<std::endl;
|
|
|
|
- iv::xmlparam::Xmlparam xp(strpath.toStdString());
|
|
|
|
|
|
|
|
|
|
|
|
connect(&mTimer,SIGNAL(timeout()),this,SLOT(onTimer()));
|
|
connect(&mTimer,SIGNAL(timeout()),this,SLOT(onTimer()));
|
|
@@ -212,73 +210,6 @@ void MainWindow::SearchCamera()
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
-void MainWindow::UpdatePic(iv::vision::rawpic pic,int index)
|
|
|
|
-{
|
|
|
|
- mMutex.lock();
|
|
|
|
- mrectime = QDateTime::currentMSecsSinceEpoch();
|
|
|
|
- mrawpics[index].CopyFrom(pic);
|
|
|
|
- // qDebug("timex is %ld ",mrawpic.time());
|
|
|
|
-
|
|
|
|
-
|
|
|
|
- mpicindex[index]++;
|
|
|
|
- mMutex.unlock();
|
|
|
|
-
|
|
|
|
- if((mbSaveOne)&&(index == mCurCameraIndex))
|
|
|
|
- {
|
|
|
|
- QString strpath = mstrSavePath;
|
|
|
|
- strpath = strpath+"/";
|
|
|
|
- strpath = strpath + QDateTime::currentDateTime().toString("yyyy-MM-dd-hh-mm-ss-zzz") + ".jpg";
|
|
|
|
- // pcl::io::loadPCDFile<pcl::PointXYZRGBA>("table_scene_lms400.pcd", *cloud
|
|
|
|
- SaveOnePic(strpath,index);
|
|
|
|
- mbSaveOne = false;
|
|
|
|
- mnonepcd++;
|
|
|
|
-
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- if((mbSave)&&(index == mCurCameraIndex))
|
|
|
|
- {
|
|
|
|
- QString strpath = mstrSavePath;
|
|
|
|
- strpath = strpath+"/";
|
|
|
|
- strpath = strpath + QDateTime::currentDateTime().toString("yyyy-MM-dd-hh-mm-ss-zzz") + ".jpg";
|
|
|
|
- SaveOnePic(strpath,index);
|
|
|
|
- mnsave++;
|
|
|
|
-
|
|
|
|
- }
|
|
|
|
- mnlidarcount++;
|
|
|
|
-
|
|
|
|
- emit updatepic();
|
|
|
|
-
|
|
|
|
-
|
|
|
|
-
|
|
|
|
-}
|
|
|
|
-
|
|
|
|
-void MainWindow::UpdatePointCloud(pcl::PointCloud<pcl::PointXYZI>::Ptr pc)
|
|
|
|
-{
|
|
|
|
- if(mbSaveOne)
|
|
|
|
- {
|
|
|
|
- QString strpath = mstrSavePath;
|
|
|
|
- strpath = strpath+"/";
|
|
|
|
- strpath = strpath + QDateTime::currentDateTime().toString("yyyy-MM-dd-hh-mm-ss-zzz") + "-1.pcd";
|
|
|
|
- // pcl::io::loadPCDFile<pcl::PointXYZRGBA>("table_scene_lms400.pcd", *cloud
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- if(mbSave)
|
|
|
|
- {
|
|
|
|
- QString strpath = mstrSavePath;
|
|
|
|
- strpath = strpath+"/";
|
|
|
|
- strpath = strpath + QDateTime::currentDateTime().toString("yyyy-MM-dd-hh-mm-ss-zzz") + ".pcd";
|
|
|
|
-
|
|
|
|
- }
|
|
|
|
- mMutex.lock();
|
|
|
|
- mMutex.unlock();
|
|
|
|
- mnlidarcount++;
|
|
|
|
- mpLE_lidarcount->setText(QString::number(mnlidarcount));
|
|
|
|
-
|
|
|
|
-
|
|
|
|
-// if(!pc->empty())update();
|
|
|
|
-}
|
|
|
|
-
|
|
|
|
-
|
|
|
|
void MainWindow::on_checkBox_clicked()
|
|
void MainWindow::on_checkBox_clicked()
|
|
{
|
|
{
|
|
|
|
|
|
@@ -296,25 +227,20 @@ void MainWindow::onTimer()
|
|
void MainWindow::paintEvent(QPaintEvent *)
|
|
void MainWindow::paintEvent(QPaintEvent *)
|
|
{
|
|
{
|
|
|
|
|
|
|
|
+ if(mbupdate == false)return;
|
|
|
|
|
|
- if(mpicviewindex[mCurCameraIndex] == mpicindex[mCurCameraIndex])return;
|
|
|
|
-
|
|
|
|
- mpicviewindex[mCurCameraIndex] = mpicindex[mCurCameraIndex];
|
|
|
|
|
|
+ std::shared_ptr<char> pdata_ptr;
|
|
|
|
+ int npicsize;
|
|
|
|
+ mmutexpic.lock();
|
|
|
|
+ mbupdate = false;
|
|
|
|
+ pdata_ptr = mppic_ptr;
|
|
|
|
+ npicsize = mnpicsize;
|
|
|
|
+ mmutexpic.unlock();
|
|
|
|
|
|
|
|
|
|
- mpLE_onepcd->setText(QString::number(mnonepcd));
|
|
|
|
|
|
+ mpLE_onepcd->setText(QString::number(mnsaveone));
|
|
mpLE_savepcd->setText(QString::number(mnsave));
|
|
mpLE_savepcd->setText(QString::number(mnsave));
|
|
- mpLE_lidarcount->setText(QString::number(mnlidarcount));
|
|
|
|
-
|
|
|
|
- // qDebug("hear4.");
|
|
|
|
- iv::vision::rawpic pic;
|
|
|
|
- qint64 rectime;
|
|
|
|
- mMutex.lock();
|
|
|
|
- pic.CopyFrom(mrawpics[mCurCameraIndex]);
|
|
|
|
- rectime = mrectime;
|
|
|
|
- mMutex.unlock();
|
|
|
|
-
|
|
|
|
-// qDebug("hear5.");
|
|
|
|
|
|
+ mpLE_lidarcount->setText(QString::number(mnpiccount));
|
|
|
|
|
|
|
|
|
|
painter->begin(image);
|
|
painter->begin(image);
|
|
@@ -325,48 +251,17 @@ void MainWindow::paintEvent(QPaintEvent *)
|
|
painter->setRenderHint(QPainter::Antialiasing, true);//设置反锯齿模式,好看一点
|
|
painter->setRenderHint(QPainter::Antialiasing, true);//设置反锯齿模式,好看一点
|
|
|
|
|
|
painter->translate(1000,1000);
|
|
painter->translate(1000,1000);
|
|
-
|
|
|
|
-
|
|
|
|
- // std::string strpic = pic.picdata();
|
|
|
|
-
|
|
|
|
-// int rows,cols,type;
|
|
|
|
-// const char * pstr = strpic.data();
|
|
|
|
-// memcpy(&rows,pstr+2,sizeof(int));
|
|
|
|
-// memcpy(&cols,pstr+6,sizeof(int));
|
|
|
|
-// memcpy(&type,pstr+10,sizeof(int));
|
|
|
|
-
|
|
|
|
-
|
|
|
|
-
|
|
|
|
- cv::Mat mat(pic.height(),pic.width(),pic.mattype());
|
|
|
|
|
|
|
|
- if(pic.type() == 1)
|
|
|
|
- memcpy(mat.data,pic.picdata().data(),mat.rows*mat.cols*mat.elemSize());
|
|
|
|
- else
|
|
|
|
- {
|
|
|
|
-
|
|
|
|
- qDebug("jpg");
|
|
|
|
- std::vector<unsigned char> buff(pic.picdata().data(),pic.picdata().data()+pic.picdata().size());
|
|
|
|
- mat = cv::imdecode(buff,1);
|
|
|
|
- }
|
|
|
|
- // qDebug("pic len is %d ",strpic.length());
|
|
|
|
-
|
|
|
|
-
|
|
|
|
-
|
|
|
|
|
|
+ cv::Mat mat;
|
|
|
|
+
|
|
|
|
+ std::vector<unsigned char> buff(pdata_ptr.get(),pdata_ptr.get() + npicsize);
|
|
|
|
+ mat = cv::imdecode(buff,1);
|
|
|
|
|
|
cv::cvtColor(mat, mat, CV_BGR2RGB);
|
|
cv::cvtColor(mat, mat, CV_BGR2RGB);
|
|
QImage image2 = QImage((uchar*)(mat.data), mat.cols, mat.rows, QImage::Format_RGB888);
|
|
QImage image2 = QImage((uchar*)(mat.data), mat.cols, mat.rows, QImage::Format_RGB888);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
-// QImage image2 = QImage((uchar*)(mat.data), mat.cols, mat.rows, QImage::Format_ARGB32);
|
|
|
|
-
|
|
|
|
- // QImage image2 = QImage((uchar*)(mat.data), mat.cols, mat.rows, QImage::Format_RGBA8888);
|
|
|
|
-
|
|
|
|
-
|
|
|
|
-
|
|
|
|
-
|
|
|
|
-
|
|
|
|
-
|
|
|
|
// QColor x;
|
|
// QColor x;
|
|
// x.setHsl(200,255,120);
|
|
// x.setHsl(200,255,120);
|
|
// painter->setPen(x);
|
|
// painter->setPen(x);
|
|
@@ -377,15 +272,6 @@ void MainWindow::paintEvent(QPaintEvent *)
|
|
myview->setScene(scene);
|
|
myview->setScene(scene);
|
|
myview->show();
|
|
myview->show();
|
|
|
|
|
|
- mpLE_capturetime->setText(QString::number(pic.time()));
|
|
|
|
-
|
|
|
|
- // qint64 timediff = rectime - pic.time();
|
|
|
|
- qint64 timediff = xt - pic.time();
|
|
|
|
-
|
|
|
|
-
|
|
|
|
- mpLE_rectime->setText(QString::number(xt));
|
|
|
|
- mpLE_timediff->setText(QString::number(timediff));
|
|
|
|
-
|
|
|
|
|
|
|
|
mat.release();
|
|
mat.release();
|
|
}
|
|
}
|
|
@@ -474,46 +360,6 @@ void MainWindow::CreateStatusView(QGridLayout *gl)
|
|
mpLE_savefolder = ple4;
|
|
mpLE_savefolder = ple4;
|
|
connect(pb4,SIGNAL(clicked(bool)),this,SLOT(onSelectFolder()));
|
|
connect(pb4,SIGNAL(clicked(bool)),this,SLOT(onSelectFolder()));
|
|
|
|
|
|
- QLabel * pl5 = new QLabel(this);
|
|
|
|
- pl5->setText("capture time");
|
|
|
|
- pl5->setFixedWidth(150);
|
|
|
|
-
|
|
|
|
- QLineEdit * ple5 = new QLineEdit(this);
|
|
|
|
- ple5->setFixedWidth(150);
|
|
|
|
-
|
|
|
|
- gl->addWidget(pl5,iRow,0);
|
|
|
|
- gl->addWidget(ple5,iRow,1);
|
|
|
|
- iRow++;
|
|
|
|
-
|
|
|
|
- mpLE_capturetime = ple5;
|
|
|
|
-
|
|
|
|
- QLabel * pl6 = new QLabel(this);
|
|
|
|
- pl6->setText("receive time");
|
|
|
|
- pl6->setFixedWidth(150);
|
|
|
|
-
|
|
|
|
- QLineEdit * ple6 = new QLineEdit(this);
|
|
|
|
- ple6->setFixedWidth(150);
|
|
|
|
-
|
|
|
|
- gl->addWidget(pl6,iRow,0);
|
|
|
|
- gl->addWidget(ple6,iRow,1);
|
|
|
|
- iRow++;
|
|
|
|
-
|
|
|
|
- mpLE_rectime = ple6;
|
|
|
|
-
|
|
|
|
-
|
|
|
|
- QLabel * pl7 = new QLabel(this);
|
|
|
|
- pl7->setText("latence time");
|
|
|
|
- pl7->setFixedWidth(150);
|
|
|
|
-
|
|
|
|
- QLineEdit * ple7 = new QLineEdit(this);
|
|
|
|
- ple7->setFixedWidth(150);
|
|
|
|
-
|
|
|
|
- gl->addWidget(pl7,iRow,0);
|
|
|
|
- gl->addWidget(ple7,iRow,1);
|
|
|
|
- iRow++;
|
|
|
|
-
|
|
|
|
- mpLE_timediff = ple7;
|
|
|
|
-
|
|
|
|
QComboBox * pcb = new QComboBox(this);
|
|
QComboBox * pcb = new QComboBox(this);
|
|
pcb->setFixedWidth(150);
|
|
pcb->setFixedWidth(150);
|
|
gl->addWidget(pcb,iRow,0);
|
|
gl->addWidget(pcb,iRow,0);
|
|
@@ -539,6 +385,45 @@ void MainWindow::CreateStatusView(QGridLayout *gl)
|
|
}
|
|
}
|
|
connect(pcb,SIGNAL(currentIndexChanged(int)),this,SLOT(onSelectCamera(int)));
|
|
connect(pcb,SIGNAL(currentIndexChanged(int)),this,SLOT(onSelectCamera(int)));
|
|
|
|
|
|
|
|
+
|
|
|
|
+ iRow++;
|
|
|
|
+ iRow++;
|
|
|
|
+
|
|
|
|
+ pl = new QLabel(this);
|
|
|
|
+ pl->setText("Width:");
|
|
|
|
+ pl->setFixedWidth(150);
|
|
|
|
+ ple = new QLineEdit(this);
|
|
|
|
+ ple->setFixedWidth(150);
|
|
|
|
+ gl->addWidget(pl,iRow,0);
|
|
|
|
+ gl->addWidget(ple,iRow,1);
|
|
|
|
+ mpLE_Width = ple;
|
|
|
|
+
|
|
|
|
+ iRow++;
|
|
|
|
+ pl = new QLabel(this);
|
|
|
|
+ pl->setText("Height:");
|
|
|
|
+ pl->setFixedWidth(150);
|
|
|
|
+ ple = new QLineEdit(this);
|
|
|
|
+ ple->setFixedWidth(150);
|
|
|
|
+ gl->addWidget(pl,iRow,0);
|
|
|
|
+ gl->addWidget(ple,iRow,1);
|
|
|
|
+ mpLE_Height = ple;
|
|
|
|
+
|
|
|
|
+ iRow++;
|
|
|
|
+ pl = new QLabel(this);
|
|
|
|
+ pl->setText("Frame Rate:");
|
|
|
|
+ pl->setFixedWidth(150);
|
|
|
|
+ ple = new QLineEdit(this);
|
|
|
|
+ ple->setFixedWidth(150);
|
|
|
|
+ gl->addWidget(pl,iRow,0);
|
|
|
|
+ gl->addWidget(ple,iRow,1);
|
|
|
|
+ mpLE_FrameRate = ple;
|
|
|
|
+
|
|
|
|
+ iRow++;
|
|
|
|
+
|
|
|
|
+ mpLE_Width->setText(QString::number(mnwidth));
|
|
|
|
+ mpLE_Height->setText(QString::number(mnheight));
|
|
|
|
+ mpLE_FrameRate->setText(QString::number(mnFrameRate));
|
|
|
|
+
|
|
QSpacerItem * xpsi2 = new QSpacerItem(400,1000,QSizePolicy::Maximum);
|
|
QSpacerItem * xpsi2 = new QSpacerItem(400,1000,QSizePolicy::Maximum);
|
|
|
|
|
|
gl->addItem(xpsi2,iRow,0);
|
|
gl->addItem(xpsi2,iRow,0);
|
|
@@ -591,29 +476,12 @@ void MainWindow::onSelectFolder()
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
-void MainWindow::SaveOnePic(QString strpath,int index)
|
|
|
|
-{
|
|
|
|
- mMutex.lock();
|
|
|
|
-
|
|
|
|
- cv::Mat mat(mrawpics[index].height(),mrawpics[index].width(),mrawpics[index].mattype());
|
|
|
|
- if(mrawpics[index].type() == 1)
|
|
|
|
- memcpy(mat.data,mrawpics[index].picdata().data(),mat.rows*mat.cols*mat.elemSize());
|
|
|
|
- else
|
|
|
|
- {
|
|
|
|
-
|
|
|
|
- qDebug("save jpg");
|
|
|
|
- std::vector<unsigned char> buff(mrawpics[index].picdata().data(),mrawpics[index].picdata().data()+mrawpics[index].picdata().size());
|
|
|
|
- mat = cv::imdecode(buff,1);//mat = cv::imdecode(buff,CV_LOAD_IMAGE_COLOR);
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- cv::imwrite(strpath.toStdString(),mat);
|
|
|
|
-
|
|
|
|
- mMutex.unlock();
|
|
|
|
-}
|
|
|
|
|
|
|
|
void MainWindow::onSelectCamera(int index)
|
|
void MainWindow::onSelectCamera(int index)
|
|
{
|
|
{
|
|
- mCurCameraIndex = index;
|
|
|
|
|
|
+ mnwidth = mpLE_Width->text().toInt();
|
|
|
|
+ mnheight = mpLE_Height->text().toInt();
|
|
|
|
+ mnFrameRate = mpLE_FrameRate->text().toInt();
|
|
if((index>=0)&&(index < static_cast<int>(mvectorusbport.size()))){
|
|
if((index>=0)&&(index < static_cast<int>(mvectorusbport.size()))){
|
|
mpLE_DevName->setText(QString::fromStdString(mvectorcameras[index]));
|
|
mpLE_DevName->setText(QString::fromStdString(mvectorcameras[index]));
|
|
mstrseldevname = mvectorcameras[index];
|
|
mstrseldevname = mvectorcameras[index];
|
|
@@ -635,8 +503,8 @@ void MainWindow::threadcam(int index){
|
|
UsbCam::pixel_format pixel_format = UsbCam::pixel_format_from_string("mjpeg");
|
|
UsbCam::pixel_format pixel_format = UsbCam::pixel_format_from_string("mjpeg");
|
|
|
|
|
|
// start the camera
|
|
// start the camera
|
|
- camx.start(strdevname, io_method, pixel_format, 1920,
|
|
|
|
- 1080, 30);
|
|
|
|
|
|
+ camx.start(strdevname, io_method, pixel_format, mnwidth,
|
|
|
|
+ mnheight, mnFrameRate);
|
|
|
|
|
|
char * strbuf = new char[10000000];
|
|
char * strbuf = new char[10000000];
|
|
while(mbthreadrun)
|
|
while(mbthreadrun)
|
|
@@ -644,11 +512,43 @@ void MainWindow::threadcam(int index){
|
|
int nLen;
|
|
int nLen;
|
|
camx.grab_image(strbuf,&nLen,10000000);
|
|
camx.grab_image(strbuf,&nLen,10000000);
|
|
qDebug("time %ld len: %ld",QDateTime::currentMSecsSinceEpoch(),nLen);
|
|
qDebug("time %ld len: %ld",QDateTime::currentMSecsSinceEpoch(),nLen);
|
|
|
|
+
|
|
|
|
+ std::shared_ptr<char> pdata_ptr(new char[nLen],std::default_delete<char[]>());
|
|
|
|
+ memcpy(pdata_ptr.get(),strbuf,nLen);
|
|
|
|
+
|
|
|
|
+ mmutexpic.lock();
|
|
|
|
+ mppic_ptr = pdata_ptr;
|
|
|
|
+ mbupdate = true;
|
|
|
|
+ mnpicsize = nLen;
|
|
|
|
+ mmutexpic.unlock();
|
|
|
|
+
|
|
|
|
+ mnpiccount++;
|
|
|
|
+
|
|
|
|
+ emit updatepic();
|
|
|
|
+
|
|
|
|
+ if(mbSaveOne || mbSave)
|
|
|
|
+ {
|
|
|
|
+ QString strpath = mstrSavePath;
|
|
|
|
+ strpath = strpath+"/";
|
|
|
|
+ strpath = strpath + QDateTime::currentDateTime().toString("yyyy-MM-dd-hh-mm-ss-zzz") + ".jpg";
|
|
|
|
+ QFile xFile;
|
|
|
|
+ xFile.setFileName(strpath);
|
|
|
|
+ if(xFile.open(QIODevice::ReadWrite)){
|
|
|
|
+ xFile.write(pdata_ptr.get(),nLen);
|
|
|
|
+ xFile.close();
|
|
|
|
+ }
|
|
|
|
+ else
|
|
|
|
+ {
|
|
|
|
+ std::cout<<" open file "<<strpath.toStdString()<<" fail. "<<std::endl;
|
|
|
|
+ }
|
|
|
|
+ if(mbSaveOne)mnsaveone++;
|
|
|
|
+ else mnsave++;
|
|
|
|
+ mbSaveOne = false;
|
|
|
|
+ }
|
|
}
|
|
}
|
|
delete strbuf;
|
|
delete strbuf;
|
|
|
|
|
|
camx.stop_capturing();
|
|
camx.stop_capturing();
|
|
-
|
|
|
|
std::cout<<"thread capture close."<<std::endl;
|
|
std::cout<<"thread capture close."<<std::endl;
|
|
// check auto white balance
|
|
// check auto white balance
|
|
|
|
|