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 to connect more than one camera with Thread? #7669

Closed
JANGSOONMYUN opened this issue Oct 29, 2020 · 3 comments
Closed

How to connect more than one camera with Thread? #7669

JANGSOONMYUN opened this issue Oct 29, 2020 · 3 comments

Comments

@JANGSOONMYUN
Copy link


Required Info
Camera Model D435
Operating System & Version Win (10)
Platform PC
Language C++ / MFC

I'm trying to connect multi-cameras with Thread.
But I don't use the example code of 'multicam'.

Here are functions that I used for camera connection and acquiring images.

void myRealSense::init(std::string cam_id)
{
	cfg.enable_stream(RS2_STREAM_COLOR, 1280, 720, RS2_FORMAT_BGR8, 30);
	cfg.enable_stream(RS2_STREAM_DEPTH, 1280, 720, RS2_FORMAT_Z16, 30);
	cfg.enable_stream(RS2_STREAM_INFRARED, 1280, 720, RS2_FORMAT_Y8, 30);
	cfg.enable_stream(RS2_STREAM_INFRARED, 1, 1280, 720, RS2_FORMAT_Y8, 30);
	cfg.enable_stream(RS2_STREAM_INFRARED, 2, 1280, 720, RS2_FORMAT_Y8, 30);

	cfg.enable_device(cam_id);
	serial_num = cam_id;
	selection = pipe.start(cfg);
}

void myRealSense::getDepthImage(Mat & img, Mat& ir_ima_for_show, Mat & d_img)
{
	frames = pipe.wait_for_frames();
	
	rs2::frame ir_frame = frames.get_infrared_frame(1);
	depth_frame = frames.get_depth_frame();

	color_frame = frames.get_color_frame();
	if (color_frame) {
		// Creating OpenCV Matrix from a color image
		img = Mat(Size(1280, 720), CV_8UC3, const_cast<void*>(color_frame.get_data()), Mat::AUTO_STEP);
	}
	if (depth_frame) {
		ir_ima_for_show = Mat(Size(1280, 720), CV_8UC1, (void*)ir_frame.get_data(), Mat::AUTO_STEP);
		d_img = Mat(Size(1280, 720), CV_16UC1, const_cast<void*>(depth_frame.get_data()), Mat::AUTO_STEP);
	}
}

It worked well when I only connect one camera.
But if I connect one more camera, image acquiring is very slow. And eventually, an error below occurs.

Unhandled exception at 0x00007FFFEC37D1D7 (opencv_world331d.dll) in MFC_3D_intelRelsense_D435_Panel_Aligment.exe: 0xC0000005: Access violation reading location 0x0000000000000024.

If there is a handler for this exception, the program may be safely continued.

Please help me to solve the problem.

@MartyG-RealSense
Copy link
Collaborator

Hi @JANGSOONMYUN I believe that you are asking how to put multiple cameras on multiple threads. Is that correct, please?

If so, and you do not wish to use the rs-multicam code, then the long discussion in the link below is an excellent reference about programming access to multiple cameras in C++.

#2219

In the middle of this discussion, @dorodnic the RealSense SDK Manager offers a script for processing with pipeline and threads:

#2219 (comment)

And finally at the end of the discussion, a finished script is posted by the RealSense user who created the discussion:

#2219 (comment)

@JANGSOONMYUN
Copy link
Author

@MartyG-RealSense Thanks to you I solved the problem. I appreciate.

@MartyG-RealSense
Copy link
Collaborator

Great to hear - thanks for the update!

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

No branches or pull requests

2 participants