return extract_edges->GetOutput();
}
- static vtkSmartPointer<vtkActor> projectImage(double fovy, double far_end_height, const Mat &image, double scale, const Color &color)
+ static vtkSmartPointer<vtkActor> projectImage(vtkSmartPointer<vtkPolyData> frustum, double far_end_height, const Mat &image, double scale, const Color &color)
{
- float aspect_ratio = float(image.cols)/float(image.rows);
+ Mat color_image = image;
+ if (color_image.channels() == 1)
+ {
+ color_image.create(image.size(), CV_8UC3);
+ Vec3b *drow = color_image.ptr<Vec3b>();
+ for(int y = 0; y < image.rows; ++y)
+ {
+ const unsigned char *srow = image.ptr<unsigned char>(y);
+ const unsigned char *send = srow + image.cols;
+ for(;srow < send;)
+ *drow++ = Vec3b::all(*srow++);
+ }
+ }
+
+
+ double aspect_ratio = color_image.cols/(double)color_image.rows;
// Create the vtk image
vtkSmartPointer<vtkImageMatSource> source = vtkSmartPointer<vtkImageMatSource>::New();
- source->SetImage(image);
+ source->SetImage(color_image);
source->Update();
vtkSmartPointer<vtkImageData> vtk_image = source->GetOutput();
- // Adjust a pixel of the vtk_image
- if(image.channels() == 1)
- {
- double gray = color[2] * 0.299 + color[1] * 0.578 + color[0] * 0.144;
- vtk_image->SetScalarComponentFromDouble(0, 0, 0, 0, gray);
- }
- else
- {
- vtk_image->SetScalarComponentFromDouble(0, 0, 0, 0, color[2]);
- vtk_image->SetScalarComponentFromDouble(0, 0, 0, 1, color[1]);
- vtk_image->SetScalarComponentFromDouble(0, 0, 0, 2, color[0]);
- }
+ vtk_image->SetScalarComponentFromDouble(0, 0, 0, 0, color[2]);
+ vtk_image->SetScalarComponentFromDouble(0, 0, 0, 1, color[1]);
+ vtk_image->SetScalarComponentFromDouble(0, 0, 0, 2, color[0]);
Vec3d plane_center(0.0, 0.0, scale);
transform_filter->SetInputConnection(texture_plane->GetOutputPort());
transform_filter->SetTransform(transform);
- vtkSmartPointer<vtkPolyData> frustum = createFrustum(aspect_ratio, fovy, scale);
+
// Frustum needs to be textured or else it can't be combined with image
vtkSmartPointer<vtkTextureMapToPlane> frustum_texture = vtkSmartPointer<vtkTextureMapToPlane>::New();
cv::viz::WCameraPosition::WCameraPosition(const Matx33d &K, const Mat &image, double scale, const Color &color)
{
CV_Assert(!image.empty() && image.depth() == CV_8U);
-
double f_y = K(1,1), c_y = K(1,2);
-
// Assuming that this is an ideal camera (c_y and c_x are at the center of the image)
double fovy = 2.0 * atan2(c_y, f_y) * 180.0 / CV_PI;
double far_end_height = 2.00 * c_y * scale / f_y;
+ double aspect_ratio = image.cols/(double)image.rows;
+
+ vtkSmartPointer<vtkPolyData> frustum = CameraPositionUtils::createFrustum(aspect_ratio, fovy, scale);
- vtkSmartPointer<vtkActor> actor = CameraPositionUtils::projectImage(fovy, far_end_height, image, scale, color);
+ vtkSmartPointer<vtkActor> actor = CameraPositionUtils::projectImage(frustum, far_end_height, image, scale, color);
WidgetAccessor::setProp(*this, actor);
}
CV_Assert(!image.empty() && image.depth() == CV_8U);
double fovy = fov[1] * 180.0 / CV_PI;
double far_end_height = 2.0 * scale * tan(fov[1] * 0.5);
+ double aspect_ratio = image.cols/(double)image.rows;
+
+ vtkSmartPointer<vtkPolyData> frustum = CameraPositionUtils::createFrustum(aspect_ratio, fovy, scale);
- vtkSmartPointer<vtkActor> actor = CameraPositionUtils::projectImage(fovy, far_end_height, image, scale, color);
+ vtkSmartPointer<vtkActor> actor = CameraPositionUtils::projectImage(frustum, far_end_height, image, scale, color);
WidgetAccessor::setProp(*this, actor);
}
viz.showWidget("sub1", WTrajectory(sub1, WTrajectory::PATH, 0.2, Color::brown()));
viz.showWidget("sub2", WTrajectory(sub2, WTrajectory::FRAMES, 0.2));
viz.showWidget("sub3", WTrajectory(sub3, WTrajectory::BOTH, 0.2, Color::green()));
- viz.showWidget("sub4", WTrajectoryFrustums(sub4, K, 0.3));
+ viz.showWidget("sub4", WTrajectoryFrustums(sub4, K, 0.3, Color::yellow()));
viz.showWidget("sub5", WTrajectoryFrustums(sub5, Vec2d(0.78, 0.78), 0.15));
int i = 0;
}
Viz3d viz("show_camera_positions");
- viz.showWidget("sphe", WSphere(Point3d(0,0,0), 1.0));
+ viz.showWidget("sphe", WSphere(Point3d(0,0,0), 1.0, 10, Color::orange_red()));
viz.showWidget("coos", WCoordinateSystem(1.5));
viz.showWidget("pos1", WCameraPosition(0.75), poses[0]);
viz.showWidget("pos2", WCameraPosition(Vec2d(0.78, 0.78), lena, 2.2, Color::green()), poses[0]);