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

stereo camera example #1352

Open
nesquik011 opened this issue Oct 8, 2024 · 6 comments
Open

stereo camera example #1352

nesquik011 opened this issue Oct 8, 2024 · 6 comments

Comments

@nesquik011
Copy link

nesquik011 commented Oct 8, 2024

hello is there anyone has a C++ code as stereo example ? i want to do visalizatio and build a dense map with loop detection and icp etc
the example i found says i need to pick one , so if i am using usb camera what should i do ? its not ZED , but it looks like ZED its stereo , with one stream feed
and i need to use opencv first to pick the resolution and forrce it to be MJPG so how can i do that

void showUsage()
{
	printf("\nUsage:\n"
			"rtabmap-rgbd_mapping driver\n"
			"  driver       Driver number to use: 0=OpenNI-PCL, 1=OpenNI2, 2=Freenect, 3=OpenNI-CV, 4=OpenNI-CV-ASUS, 5=Freenect2, 6=ZED SDK, 7=RealSense, 8=RealSense2 9=Kinect for Azure SDK 10=MYNT EYE S\n\n");
	exit(1);
}

using namespace rtabmap;
int main(int argc, char * argv[])
{
	ULogger::setType(ULogger::kTypeConsole);
	ULogger::setLevel(ULogger::kWarning);

#ifdef RTABMAP_PYTHON
	PythonInterface python; // Make sure we initialize python in main thread
#endif

	int driver = 0;
	if(argc < 2)
	{
		showUsage();
	}
	else
	{
		driver = atoi(argv[argc-1]);
		if(driver < 0 || driver > 10)
		{
			UERROR("driver should be between 0 and 10.");
			showUsage();
		}
	}

thanks in advance

@matlabbe
Copy link
Member

matlabbe commented Oct 9, 2024

Does the camera give you a side-by-side video stream in opencv? You could use this camera driver: https://github.com/introlab/rtabmap/blob/master/corelib/include/rtabmap/core/camera/CameraStereoVideo.h

You will need to calibrate the camera. If you have already the calibration, convert in the right format. Look at the yaml files in the example stereo data here: https://github.com/introlab/rtabmap/wiki/Stereo-mapping#process-a-directory-of-stereo-images

If the camera is not calibrated, you can calibrate from rtabmap main app. Go in Preferences->Source, select Stereo input then scroll down to select "Side-by-side video" driver, then click on calibrate. You can export a checkerboard from that screen and show it on a display/tv (then measure the size of the squares).

@nesquik011
Copy link
Author

@matlabbe thank you , so the example i am working on will do as i want right ?

examples/RGBDMapping/main.cpp

@matlabbe
Copy link
Member

Yeah, we don't really have other c++ examples :)

@nesquik011
Copy link
Author

@matlabbe i just built the lib and examples on windows 10 visual studio 2022 after suffering lol XD i will test the [CameraStereoVideo.h] with the example you shared and i will report back i hope nothing would break

thanks a lot

@nesquik011
Copy link
Author

nesquik011 commented Oct 11, 2024

@matlabbe may you kindly check the example , i modified the RGBD mapping example

Note: i posted the code at Pastebin because the comment would be too long
https://pastebin.com/hRNVCUhv

i had couple of problems but it fixed them anyway tell me what do you think of the code ? , it pop up a windows for 3D only and i cant see the camera feed

@nesquik011
Copy link
Author

nesquik011 commented Oct 12, 2024

@matlabbe i updated CameraStereoVideo.cpp with fourcc , but yet i cant manage to make it work , the camera is so laggy

		if (src_ == CameraVideo::kUsbDevice)
		{
			if (stereoModel_.isValidForProjection())
			{
				if (capture_.isOpened())
				{
					// Set FOURCC to MJPG for USB camera
					capture_.set(CV_CAP_PROP_FOURCC, CV_FOURCC('M', 'J', 'P', 'G'));

					capture_.set(CV_CAP_PROP_FRAME_WIDTH, stereoModel_.left().imageWidth() * (capture2_.isOpened() ? 1 : 2));
					capture_.set(CV_CAP_PROP_FRAME_HEIGHT, stereoModel_.left().imageHeight());
					if (capture2_.isOpened())
					{
						capture2_.set(CV_CAP_PROP_FOURCC, CV_FOURCC('M', 'J', 'P', 'G'));
						capture2_.set(CV_CAP_PROP_FRAME_WIDTH, stereoModel_.right().imageWidth());
						capture2_.set(CV_CAP_PROP_FRAME_HEIGHT, stereoModel_.right().imageHeight());
					}
				}
			}
			else if (_width > 0 && _height > 0)
			{
				if (capture_.isOpened())
				{
					// Set FOURCC to MJPG for USB camera
					capture_.set(CV_CAP_PROP_FOURCC, CV_FOURCC('M', 'J', 'P', 'G'));

					capture_.set(CV_CAP_PROP_FRAME_WIDTH, _width * (capture2_.isOpened() ? 1 : 2));
					capture_.set(CV_CAP_PROP_FRAME_HEIGHT, _height);
					if (capture2_.isOpened())
					{
						capture2_.set(CV_CAP_PROP_FOURCC, CV_FOURCC('M', 'J', 'P', 'G'));
						capture2_.set(CV_CAP_PROP_FRAME_WIDTH, _width);
						capture2_.set(CV_CAP_PROP_FRAME_HEIGHT, _height);
					}
				}
			}
		}

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

2 participants