Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

how can i use export_to_ply functions to save ply as ascii format? #6677

Closed
wuhaoqi-hub opened this issue Jun 23, 2020 · 12 comments
Closed

how can i use export_to_ply functions to save ply as ascii format? #6677

wuhaoqi-hub opened this issue Jun 23, 2020 · 12 comments

Comments

@wuhaoqi-hub
Copy link

I want to export ply as ascii format,but i can't find some methods to slove this problem,so i want to consult this question,this is my code.
int main()
{
context ctx;
int ind(0);

for (auto&& dev : ctx.query_devices())
{
	pipeline pipe(ctx);
	config cfg;
	cfg.enable_device(dev.get_info(RS2_CAMERA_INFO_SERIAL_NUMBER));
	cfg.enable_stream(RS2_STREAM_ANY, 0, 640, 480, RS2_FORMAT_Z16, 30);
	cfg.enable_stream(RS2_STREAM_ANY, 1, 640, 480, RS2_FORMAT_Y8, 30);
	cfg.enable_stream(RS2_STREAM_ANY, 2, 640, 480, RS2_FORMAT_Y8, 30);
	pipeline_profile selection = pipe.start(cfg);
	device selected_device = selection.get_device();

	advanced_mode advanced_device(selected_device);

	depth_sensor depth_sensor = selected_device.first<rs2::depth_sensor>();
	//	option_range range = depth_sensor.get_option_range(RS2_OPTION_DEPTH_UNITS);
	depth_sensor.set_option(RS2_OPTION_DEPTH_UNITS, 0.001);

	STDepthTableControl depth_table = advanced_device.get_depth_table();
	depth_table.depthClampMax = 1000;
	depth_table.depthUnits = 1000;
	advanced_device.set_depth_table(depth_table);

	pointcloud pc;
	points points;

	frameset frames = pipe.wait_for_frames();
	video_frame infrared = frames.get_color_frame();
	if (!infrared)
		infrared = frames.get_infrared_frame();
	depth_frame depth = frames.get_depth_frame();

	pc.map_to(infrared);
	points = pc.calculate(depth);

	char path[200];
	sprintf_s(path, "F:\\20191024_%d.ply", ind);
	points.export_to_ply(path, infrared);

	++ind;
}
return EXIT_SUCCESS;

}

@dorodnic
Copy link
Contributor

Hi @wuhaoqi-hub
This is not possible with rs2::points::export_to_ply method but you can use save_to_ply class from rs_export.hpp -

rs2::save_to_ply exporter(path, pc);
exporter.set_option(rs2::save_to_ply::OPTION_PLY_BINARY, 0.f);
exporter.export_to_ply(points, infrared);

@wuhaoqi-hub
Copy link
Author

thank you very much

@wuhaoqi-hub
Copy link
Author

i use the method you answered for me,but the function "rs2::save_to_ply::export_to_ply" can't be visited.

@MartyG-RealSense
Copy link
Collaborator

MartyG-RealSense commented Jun 26, 2020

@wuhaoqi-hub I note that you included export_to_ply in your instruction. @dorodnic stated above that using export_to_ply was not possible. and suggested this code based on save_to_ply instead:

rs2::save_to_ply exporter(path, pc);
exporter.set_option(rs2::save_to_ply::OPTION_PLY_BINARY, 0.f);
exporter.export_to_ply(points, infrared);

Setting OPTION_PLY_BINARY to False with the '0' value instructs the program to save the ply in ASCII format instead of exporting a binary file.

#4906

@wuhaoqi-hub
Copy link
Author

I used the code exporter.export_to_ply(points, infrared);it has export_to_ply,but the export_to_ply is the private function ,the exporter object can't visit it.can you give me some example code?thanks

@MartyG-RealSense
Copy link
Collaborator

MartyG-RealSense commented Jun 27, 2020

@wuhaoqi-hub I could not find an example for saving ASCII to ply. @dorodnic will be able to provide better advice than I can about custom code that you can try in your project.

@ilyak93
Copy link

ilyak93 commented Apr 18, 2022

@wuhaoqi-hub I could not find an example for saving ASCII to ply. @dorodnic will be able to provide better advice than I can about custom code that you can try in your project.

The function works if you change its private to public, but I don't get the color mapped correctly to the points, just everything gray.

@MartyG-RealSense
Copy link
Collaborator

MartyG-RealSense commented Apr 18, 2022

Hi @ilyak93 Exporting color to ply usually does not work on Python (if you are using Python and not C++). The subject has been researched by me extensively over the years and the only script confirmed to work on Python is one at #6194 (comment) that exports color to ply but without vertex normals.

@ilyak93
Copy link

ilyak93 commented Apr 18, 2022

@MartyG-RealSense, thanks, I'm trying it on C++ both methods (using points and using the function proposed here) with no success. I'm using 2.34.0-0~realsense0.2250 SDK version. Any suggestions ? When I open the ply file, i see that there is a color, but its a gray color and it's the same for all the points.

            rs2::frame depth_frame2 = fs.get_depth_frame();
            rs2::frame color_frame2 = fs.get_color_frame();

            rs2::pointcloud pc;
            rs2::points points = pc.calculate(depth_frame2);
            //pc.map_to(color_frame2); // tried with this and without
            points.export_to_ply("G:/Vista_project/finish1/rs-ptc/"
                                 + to_string(pc_idx) + "1.ply", color_frame2);
            rs2::save_to_ply exporter("G:/Vista_project/finish1/rs-ptc/"
                                      + to_string(pc_idx) + ".ply", pc);
            exporter.set_option(rs2::save_to_ply::OPTION_PLY_BINARY, 0.f);
            exporter.set_option(rs2::save_to_ply::OPTION_IGNORE_COLOR, 0.f);
            exporter.export_to_ply(points, color_frame2);

I'm doing it with software-device.

The only solution I have now is to create a point cloud from the depth and the color using open3d library, but I wanted to get the original pointcloud as realsense construct it.

I saw that for other people worked the regular approach using points.export_to_ply, it's strange that I don't get the expected result using it.

P.S: alignment does work with all the registered intrinsics/extrinsics and etc.

@MartyG-RealSense
Copy link
Collaborator

@ilyak93 I will research your question tomorrow. Thanks again for your patience!

@ilyak93
Copy link

ilyak93 commented Apr 18, 2022

@MartyG-RealSense, ok thanks. Should I open a new issue or can we continue here ?

I have found (by using the function that the exporter exploits) that:
image
that texcoords[i] for each i (all the points) are all set to 0 (the cout << "here" loop is my code injected into real sense rs_export.hpp, which why probably I get only one color (the color of (u=0,v=0)), which means my pointcloud somehow doesn't know what is his texture coordinates. Maybe it is somehow connected to the fact it is software-device, some data maybe lost, I think the implementation of this function rs2::points points = pc.calculate(depth_frame2); (calculate) should give the answers if you can look around it.

Thank you in advance.

@MartyG-RealSense
Copy link
Collaborator

Given that this case was originally about exporting ASCII characters to ply instead of color, please start a new issue and link back to this one.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants