10 #include <vtkSmartPointer.h>
11 #include <vtkPolyData.h>
12 #include <vtkCellArray.h>
13 #include <vtkPolyDataMapper.h>
14 #include <vtkPoints.h>
16 #include <vtkTriangle.h>
17 #include <vtkProperty.h>
18 #include <vtkImageData.h>
19 #include <vtkTexture.h>
20 #include <vtkFloatArray.h>
21 #include <vtkPointData.h>
22 #include <vtkCellData.h>
31 imgpose->
image = image;
35 cv::Mat intrinsics = (cv::Mat_<float>(3,3) << kinfu.
params()->
intr.
fx*2, 0, 1280/2-0.5f + 3,
48 KinFuParams* params = KinFuParams::default_params();
54 if(device.find_first_not_of(
"0123456789") == std::string::npos)
61 std::cout << std::endl <<
"Kinfu does not support pre-Fermi GPU architectures, and is not built for them by default. Exiting..." << std::endl;
77 connect(m_pbStart, SIGNAL(pressed()),
m_timer, SLOT(start()));
79 connect(m_pbStop, SIGNAL(pressed()),
this, SLOT(
finalizeMesh()));
96 m_renderer->AddActor(actor);
98 m_renderer->ResetCamera();
99 m_renderer->ResetCameraClippingRange();
100 this->qvtkWidget->GetRenderWindow()->Render();
101 this->qvtkWidget->update();
156 m_kinfu->performLastScan();
165 m_renderer = vtkSmartPointer<vtkRenderer>::New();
166 vtkSmartPointer<vtkRenderWindow> renderWindow = this->qvtkWidget->GetRenderWindow();
168 m_renderWindowInteractor = this->qvtkWidget->GetInteractor();
169 m_renderWindowInteractor->Initialize();
172 renderWindow->AddRenderer(m_renderer);
173 m_renderer->GradientBackgroundOn();
174 m_renderer->SetBackground(0.0, 0.0, 0.8);
175 m_renderer->SetBackground2(1.0, 1.0, 1.0);
176 m_renderer->TwoSidedLightingOn();
178 m_axes = vtkSmartPointer<vtkAxesActor>::New();
180 m_axesWidget = vtkSmartPointer<vtkOrientationMarkerWidget>::New();
181 m_axesWidget->SetOutlineColor( 0.9300, 0.5700, 0.1300 );
182 m_axesWidget->SetOrientationMarker( m_axes );
183 m_axesWidget->SetInteractor( m_renderer->GetRenderWindow()->GetInteractor() );
184 m_axesWidget->SetDefaultRenderer(m_renderer);
185 m_axesWidget->SetViewport( 0.0, 0.0, 0.3, 0.3 );
186 m_axesWidget->SetEnabled( 1 );
187 m_axesWidget->InteractiveOff();
193 KinFu& kinfu = *m_kinfu;
194 cv::Mat depth, image, image_copy;
195 static int has_image = 0;
196 static int image_count = 0;
197 static int frame_count = 0;
199 static std::vector<Affine3f> posen;
200 static std::vector<cv::Mat> rvecs;
203 static cv::Mat best_rvec,best_image;
204 static float best_dist=0.0;
206 if(!(m_kinfu->hasShifted() && m_kinfu->isLastScan()))
208 int has_frame = m_openNISource->grab(depth, image);
209 cv::flip(depth, depth, 1);
210 cv::flip(image, image, 1);
214 std::cout <<
"Can't grab" << std::endl;
221 m_kinfu->performLastScan();
223 m_depth_device.upload(depth.data, depth.step, depth.rows, depth.cols);
224 has_image = kinfu(m_depth_device);
225 if(has_image) frame_count++;
229 if (!(m_kinfu->hasShifted() && m_kinfu->isLastScan()) && has_image)
233 double ref_timer = cv::getTickCount();
236 image.copyTo(image_copy);
249 for(
size_t z=0;z<rvecs.size();z++){
250 dist +=
norm(mom_rvec-rvecs[z]);
252 if(dist > best_dist){
256 best_rvec = mom_rvec.clone();
257 best_image = image.clone();
262 if(
true && (frame_count % 7 == 0))
264 cout <<
"STORE!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!" << endl;
266 rvecs.push_back(best_rvec);
267 posen.push_back(best_pose);
271 sample_poses_.push_back(m_kinfu->getCameraPose());
272 std::cout <<
"image taken "<< image_count++ <<
", time: "<< time << std::endl;
285 m_kinfu->renderImage(m_viewImage, mode);
286 m_deviceImg.create(m_viewImage.rows(), m_viewImage.cols(), CV_8UC4);
287 m_viewImage.download(m_deviceImg.ptr<
void>(), m_deviceImg.step);
290 m_displayRaycastLabel->setPixmap(
292 QImage((
unsigned char*) m_deviceImg.data,
295 QImage::Format_RGB32)));
297 m_displayImageLabel->setPixmap(
299 QImage((
unsigned char*) image.data,
302 QImage::Format_RGB888).rgbSwapped()));
320 delete m_openNISource;
325 m_meshThread->quit();
326 m_meshThread->wait();