terzakig / gptam

PTAM with OpenCV : This is a deep code modification of the original PTAM by Klein and Murray to work only using OpenCV; Although the initial intention was to do the library adaptation for starters, I ended up having to modfy the code and some algorithms as well.
80 stars 22 forks source link

run the ptam with prerecorded video #13

Closed dorc23 closed 4 years ago

dorc23 commented 4 years ago

hey there is a way to run this algoritem with prerecorded video? thanks:)

terzakig commented 4 years ago

Hi,

Yes it could, but it needs a couple of modifications. First you need to specify the file in VideoSource.cpp so that the OpenCV capture object retrieves the frames from a file instead of a USB camera. Then you need to generate some sort of delay or pause between frame captures. You can introduce this pause inside the loop in System.cpp, just after the line that grabs the frame:

mVideoSource.GetAndFillFrameBWandRGB(mimFrameBW, mimFrameRGB);

Note that global bundle adjustment works asynchronously in a separate thread, but that should be of no concern.


From: dorc23 notifications@github.com Sent: Tuesday, September 10, 2019 8:53 PM To: terzakig/gptam gptam@noreply.github.com Cc: Subscribed subscribed@noreply.github.com Subject: [terzakig/gptam] run the ptam with prerecorded video (#13)

hey there is a way to run this algoritem with prerecorder video? thanks:)

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHubhttps://github.com/terzakig/gptam/issues/13?email_source=notifications&email_token=AACHSFQGUKO2FXL6XTPNJMLQI7NKFA5CNFSM4IVKYA72YY3PNVWWK3TUL52HS4DFUVEXG43VMWVGG33NNVSW45C7NFSM4HKQP22Q, or mute the threadhttps://github.com/notifications/unsubscribe-auth/AACHSFRPX5NNLKXB7Q3JUL3QI7NKFANCNFSM4IVKYA7Q.

dorc23 commented 4 years ago

hey , thanks for your help . i change in VideoSource.cpp to get input from file , and the video is showen when we run ./gptam , im also add u usleep(10000) after the line mVideoSource.GetAndFillFrameBWandRGB(mimFrameBW, mimFrameRGB); but still i get the same message : DEBUG: Essential matrix inliers too few! Could not init from stereo pair, try again. any idea?

terzakig commented 4 years ago

Hi, There are two possible reasons:

a) You haven't initialized SLAM properly. PTAM initializes manually through the GUI (I should change this someday and incorporate automatic initialization), so if you don't somehow do it properly (make sure that there is enough parallax-the coloured lines) as the frames are coming from the file, the initial reconstruction will fail.

b) Your camera is not calibrated. See the README if that is the case.


From: dorc23 notifications@github.com Sent: Saturday, September 14, 2019 11:47 AM To: terzakig/gptam gptam@noreply.github.com Cc: George terzakig@hotmail.com; Comment comment@noreply.github.com Subject: Re: [terzakig/gptam] run the ptam with prerecorded video (#13)

hey , thanks for your help . i change in VideoSource.cpp to get input from file , and the video is showen when we run ./gptam , im also add u usleep(10000) after the line mVideoSource.GetAndFillFrameBWandRGB(mimFrameBW, mimFrameRGB); but still i get the same message : DEBUG: Essential matrix inliers too few! Could not init from stereo pair, try again. any idea?

— You are receiving this because you commented. Reply to this email directly, view it on GitHubhttps://github.com/terzakig/gptam/issues/13?email_source=notifications&email_token=AACHSFQVRKFBQIRVMSKXXD3QJSQKFA5CNFSM4IVKYA72YY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOD6WXTEA#issuecomment-531462544, or mute the threadhttps://github.com/notifications/unsubscribe-auth/AACHSFQZIHT6O2YOSTCNRTDQJSQKFANCNFSM4IVKYA7Q.

dorc23 commented 4 years ago

Thanks for your help , I try to run this algorithm with prerecorded with video , so I have two question

  1. If im not using camera im still need to calibrate camera ?
  2. How im initialized SLAM properly ? what i need to do in the recorded video to make it initialized?
terzakig commented 4 years ago

Hi,

To briefly answer your questions:

  1. Yes, you need to know the calibration parameters of the camera used to record the video. If you can connect the same camera to a usb and run the calibration, you should have the camera parameters as described in the README.
  2. You need to press space once, wait until the tracked points have enough parallax (colored lines) and press space again to stop the tracking and if the tracking quality is good, PTAM should start mapping. But of course, for this to happen, it is important to have a correct calibration in place.

From: dorc23 notifications@github.com Sent: Saturday, September 14, 2019 1:19 PM To: terzakig/gptam gptam@noreply.github.com Cc: George terzakig@hotmail.com; Comment comment@noreply.github.com Subject: Re: [terzakig/gptam] run the ptam with prerecorded video (#13)

Thanks for your help , I try to run this algorithm with prerecorded with video , so I have two question

  1. If im not using camera im still need to calibrate camera ?
  2. How im initialized SLAM properly ? what i need to do in the recorded video to make it initialized?

— You are receiving this because you commented. Reply to this email directly, view it on GitHubhttps://github.com/terzakig/gptam/issues/13?email_source=notifications&email_token=AACHSFV5G6RYE5VSORDVEPLQJS3C7A5CNFSM4IVKYA72YY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOD6WY7KA#issuecomment-531468200, or mute the threadhttps://github.com/notifications/unsubscribe-auth/AACHSFXBY5E4G6ZMTAY45XTQJS3C7ANCNFSM4IVKYA7Q.

dorc23 commented 4 years ago

Thanks for your help . There is any way to calibration the camera manually ? becuse im working on linux virtual machine in azure and i want to use with prerecorded video.

terzakig commented 4 years ago

Hi,

You can modify CameraCalibrator.cpp in exactly the same way you modified System.cpp. If you have already switched the code to do capturing from file in VideoSource.cpp, then, the calibrator will also capture from the specified file. You just need to add a delay after the statement: // Grab new video frame... mVideoSource.GetAndFillFrameBWandRGB(imFrameBW, imFrameRGB);

in the CameraCalibrator.cpp. So, you can record a chessboard sequence and run the calibrator on it. As the frames will be coming, you will have to use the interface to grab at least 8 images (i.e. click on grab image) for calibration.


From: dorc23 notifications@github.com Sent: Saturday, September 21, 2019 12:32 PM To: terzakig/gptam gptam@noreply.github.com Cc: George terzakig@hotmail.com; Comment comment@noreply.github.com Subject: Re: [terzakig/gptam] run the ptam with prerecorded video (#13)

Thanks for your help . There is any way to calibration the camera manually ? becuse im working on linux virtual machine in azure and i want to use with prerecorded video.

— You are receiving this because you commented. Reply to this email directly, view it on GitHubhttps://github.com/terzakig/gptam/issues/13?email_source=notifications&email_token=AACHSFU56EMTXQML6O4PYXLQKXS33A5CNFSM4IVKYA72YY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOD7IOIEI#issuecomment-533783569, or mute the threadhttps://github.com/notifications/unsubscribe-auth/AACHSFSXIIGV62E7L47KBPDQKXS33ANCNFSM4IVKYA7Q.

dorc23 commented 4 years ago

Thank you very much!!!! its work now i have the initial map on the screen but i get those massages DEBUG: Adding Keyframe from top of queue. DEBUG: Adjusting recent DEBUG: Attempting to refind newlymade DEBUG: Now Bundle adjusting ALL. DEBUG: Refinding from Failure Queue. DEBUG: Handling bad points again.... you have any idea why its happend and how i can fix it ?

terzakig commented 4 years ago

These are just debug messages that I planted in the code and never bothered to remove, so if the SLAM works, you should not be alarmed. On the other hand, if things don't turn up as expected, then these messages can be informative


From: dorc23 notifications@github.com Sent: Saturday, September 21, 2019 1:49 PM To: terzakig/gptam gptam@noreply.github.com Cc: George terzakig@hotmail.com; Comment comment@noreply.github.com Subject: Re: [terzakig/gptam] run the ptam with prerecorded video (#13)

Thank you very much!!!! its work now i have the initial map on the screen but i get those massages DEBUG: Adding Keyframe from top of queue. DEBUG: Adjusting recent DEBUG: Attempting to refind newlymade DEBUG: Now Bundle adjusting ALL. DEBUG: Refinding from Failure Queue. DEBUG: Handling bad points again.... you have any idea why its happend and how i can fix it ?

— You are receiving this because you commented. Reply to this email directly, view it on GitHubhttps://github.com/terzakig/gptam/issues/13?email_source=notifications&email_token=AACHSFU6GKFQX7LPRLPGZW3QKX32NA5CNFSM4IVKYA72YY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOD7IPLRQ#issuecomment-533788102, or mute the threadhttps://github.com/notifications/unsubscribe-auth/AACHSFWYJC76MEZIHGLJ3G3QKX32NANCNFSM4IVKYA7Q.

dorc23 commented 4 years ago

Thanks you again my friend :) after running the algorithm i want to save the Map and the keyFrames to a file , i see the option in the code but i cant see the button that run that function. my main goal is reciving frame information and classify by the location. thanks again ;)

terzakig commented 4 years ago

Hi,

happy to be of assistance. Unfortunately I never added code to save the map and/or the keyframes. however, it is very easy to add code that for this yourself. Since OpenCV is the main library behind gPTAM, you can easily add code that saves the map in a yaml file. What you need to do is to loop over the points in the map and create a cv:;Mat with dimensions 3xN (or Nx3) and store them in its rows in [Xi, Yi, Zi] fashion. You can do exactly the same with the list of keyframes using a cv::Mat of 6xM (if you use a 3 Degree-of-freedom parametrization for orientation) or 15 x M (if you store the entire rotation matrix as 9 numbers) and use the cv::FileStorage class (https://docs.opencv.org/master/da/d56/classcv_1_1FileStorage.html) to store then in a yaml file. OpenCV: cv::FileStorage Class Referencehttps://docs.opencv.org/master/da/d56/classcv_1_1FileStorage.html Enumerator; READ value, open the file for reading . WRITE value, open the file for writing . APPEND value, open the file for appending . MEMORY returned by FileStorage::release) . flag, read data from source or write data to the internal buffer (which is docs.opencv.org


From: dorc23 notifications@github.com Sent: Saturday, September 28, 2019 11:17 AM To: terzakig/gptam gptam@noreply.github.com Cc: George terzakig@hotmail.com; Comment comment@noreply.github.com Subject: Re: [terzakig/gptam] run the ptam with prerecorded video (#13)

Thanks you again my friend :) after running the algorithm i want to save the Map and the keyFrames to a file , i see the option in the code but i cant see the button that run that function. my main goal is reciving frame information and classify by the location. thanks again ;)

— You are receiving this because you commented. Reply to this email directly, view it on GitHubhttps://github.com/terzakig/gptam/issues/13?email_source=notifications&email_token=AACHSFQFQUZYTG5JSAZIPADQL4HLPA5CNFSM4IVKYA72YY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOD72TWMI#issuecomment-536165169, or mute the threadhttps://github.com/notifications/unsubscribe-auth/AACHSFVK3YVBBETYJXYHEL3QL4HLPANCNFSM4IVKYA7Q.

dorc23 commented 4 years ago

image i found this code in the project , but seem that the UI dont show the button to save the Map so i think you remove it , thanks for you help again you was very halpfull :)

terzakig commented 4 years ago

Oh, OK! You are correct! This is basically original PTAM code by Georg klein which I converted, but never even used (and had forgotten about it 🙂 ). By all accounts, it should work (bear in mind I never actually tested it, but I think it should work)!

Now in terms of the GUI, It seems that it is not added the the menu in system.cpp for some reason. if you really want to add it to the interface, you need to go to system.cpp and have gui parse an add button command, i.e., something like,

GUI.ParseLine("Menu.AddMenuButton Root SaveMap SaveMap Root");

In theory, this should do the job for you.. .The callback is then liked inside the Mapmaker.cpp cinstructor, so, all being well, this should be all you need to do. Bear in mind that this interface was designed by Georg Klein and I just adopted it for this project, so the GUI class may not behave exactly as you expect it would.


From: dorc23 notifications@github.com Sent: Saturday, September 28, 2019 5:35 PM To: terzakig/gptam gptam@noreply.github.com Cc: George terzakig@hotmail.com; Comment comment@noreply.github.com Subject: Re: [terzakig/gptam] run the ptam with prerecorded video (#13)

[image]https://user-images.githubusercontent.com/35142668/65818010-0dc9d600-e216-11e9-89d0-6cc0db1a3a49.png i found this code in the project , but seem that the UI dont show the button to save the Map so i think you remove it , thanks for you help again you was very halpfull :)

— You are receiving this because you commented. Reply to this email directly, view it on GitHubhttps://github.com/terzakig/gptam/issues/13?email_source=notifications&email_token=AACHSFUWLF24KZIHYNRSZW3QL5TSHA5CNFSM4IVKYA72YY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOD7227JA#issuecomment-536194980, or mute the threadhttps://github.com/notifications/unsubscribe-auth/AACHSFXZPSTFWLUOOAVTY5TQL5TSHANCNFSM4IVKYA7Q.

dorc23 commented 4 years ago

great ! thanks again ;)

inga890 commented 4 years ago

Hey, Stumbled on the same issue, was able to call the save method, but the save_image code is missing. Also having issues to use the imwrite method it the cv, is there a better way to do it from your expirience? Thanks for the help in advance 🙂

terzakig commented 4 years ago

Hi,

Can you give a few more details on what you would like to do? I am not sure what images you are referring to. Are they related to the map?


From: inga890 notifications@github.com Sent: Saturday, October 12, 2019 3:55 PM To: terzakig/gptam gptam@noreply.github.com Cc: George terzakig@hotmail.com; Comment comment@noreply.github.com Subject: Re: [terzakig/gptam] run the ptam with prerecorded video (#13)

Hey, Stumbled on the same issue, was able to call the save method, but the save_image code is missing. Also having issues to use the imwrite method it the cv, is there a better way to do it from your expirience? Thanks for the help in advance 🙂

— You are receiving this because you commented. Reply to this email directly, view it on GitHubhttps://github.com/terzakig/gptam/issues/13?email_source=notifications&email_token=AACHSFRLIK46DA3U5PEOJLTQOHCNFA5CNFSM4IVKYA72YY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOEBB6Z6A#issuecomment-541322488, or unsubscribehttps://github.com/notifications/unsubscribe-auth/AACHSFVPQLVJGHDFKARTYDDQOHCNFANCNFSM4IVKYA7Q.

inga890 commented 4 years ago

Hey, Im talking about the keyframes. I want to save them in addition to the map, as i understood i suppost to be able to do it with the imwrite method but i have issuses there also, Maybe you have some other ideas? Thank you!!!!

inga890 commented 4 years ago

Hey again!

Managed to save the keyframes! Now im trying to go a bit deeper and understand the difference between the map info and the keyframes info, already read the documentation and yet cant put a finger on it, maybe you can help?

Thanks again!

terzakig commented 4 years ago

I would recommend reading the visual SLAM basics, but to give a brief description:

The keyframe structures contain specially chosen images from the sequence so that the tracked points are good and geometrically reliable matches particularly for triangulation and bundle adjustment. So, except images, keyframes also contain FAST features that were either detected at the current keyframe, or tracked from previous ones. These point features when triangulated (loosely speaking) , will produce the 3D points contained in the map.

Visual SLAM pipeline does that in several stages: a) Feature detection, b) Tracking, c) Triangulation, d) Bundle adjustment, e) Feature tracking and Detection and back to (c)


From: inga890 notifications@github.com Sent: Saturday, October 19, 2019 12:42 PM To: terzakig/gptam gptam@noreply.github.com Cc: George terzakig@hotmail.com; Comment comment@noreply.github.com Subject: Re: [terzakig/gptam] run the ptam with prerecorded video (#13)

Hey again!

Managed to save the keyframes! Now im trying to go a bit deeper and understand the difference between the map info and the keyframes info, already read the documentation and yet cant put a finger on it, maybe you can help?

Thanks again!

— You are receiving this because you commented. Reply to this email directly, view it on GitHubhttps://github.com/terzakig/gptam/issues/13?email_source=notifications&email_token=AACHSFXCQLZ3OR7AG5GMQ2DQPLJALA5CNFSM4IVKYA72YY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOEBXKCWY#issuecomment-544121179, or unsubscribehttps://github.com/notifications/unsubscribe-auth/AACHSFXOD4V2NKJWMYWITITQPLJALANCNFSM4IVKYA7Q.

inga890 commented 4 years ago

Thank you so much! Will read the SLAM documantation now.