perfanalytics / pose2sim

Markerless kinematics with any cameras — From 2D Pose estimation to 3D OpenSim motion
https://perfanalytics.github.io/pose2sim/
BSD 3-Clause "New" or "Revised" License
242 stars 46 forks source link

Wrong Calibration file #26

Closed ClarkGrif closed 1 year ago

ClarkGrif commented 1 year ago

Hello,

First of all, thanks for sharing your work with us!

I am trying to follow the steps mentioned in the README file, and I have reached the camera calibration. However, my calibration file is a .cal because I am using Optitrack PrimeColor cameras, which can be calibrated and synchronized through Optitrack Motive. How can I make it work?

Thanks, Clara

davidpagnon commented 1 year ago

Hello, I don't know these files, can you send me a sample so that I can see if I can translate it to the OpenCV format?

ClarkGrif commented 1 year ago

I cannot send it to you because the file type is not recognized. Do you have an email or any other means through which I can send it to you?

davidpagnon commented 1 year ago

Sure, you can send it to contact@david-pagnon.com, or preferably if it is not a binary file, you can simply copy-paste its content here.

ClarkGrif commented 1 year ago

Thank you for your answer, I have sent it by email.

davidpagnon commented 1 year ago

I received it, thanks! Unfortunately, this is a binary file and I cannot read it. Is there an option to export it as a txt file? You may need to contact your support center if this is not natively possible, they might be able to do something about it.

ClarkGrif commented 1 year ago

I contacted the support center to see if they can do something about it. Thank you !

claraaudap commented 1 year ago

Hello,

I gace up with the calibration file .cal because they cannot or don't want to give me an other type of calibration file so I want to do the calibration with a chessboard.

I followed the steps mentioned in the README file, and I have reached the camera calibration. I'm trying to do the calibration with the chessboard, so I took videos of a checkerboard with the 8 cameras I have and put them in a different folder for each camera but when I run the following script : Pose2Sim.calibrateCams() an error appears :

Capture d’écran 2023-06-05 140131

I don't understand what I'm doing wrong Can someone help me

Thank you, Clara

PS : Attached, you will see an example of the chessboard video

claraaudap commented 1 year ago

Attached, you will find my config file

Config1.txt

davidpagnon commented 1 year ago

Hi, this is a shame because converting a calibration would have been much easier than doing the calibration yourself...

I cannot see the attached example of the chessboard video. If you want me to test it, you can send me your whole project folder (my email address: contact@david-pagnon.com).

From the error you sent, it seems like no images are found, which could be caused by

Not sure this is connected, but if I were you I would name my projet folder something different from "Pose2Sim" since it is the exact name of the package: it could confuse the system and make it look for files in the wrong folder.

Also, and although this should not have anything to do with the error, I would recommend calibrating with images rather than with videos. This way, you can choose the best ones for calibration. You can extract frames from a video with ffmpeg for example.

ClarkGrif commented 1 year ago

Thank you for your answer. I have sent you my file by email. As for me, I am trying what you advised me.

davidpagnon commented 1 year ago

Thank you Clara, I got the files.

There are 2 minor issues with your Config.toml file:

The way you do it, intrinsic parameters will be pretty well estimated, at least as long as you use 10 or more checkerboard images for each camera. These correspond to the camera properties, and usually need to be calculated only once. However, you also need to obtain extrinsic parameters, i.e. the position of all cameras as regards to your reference frame. This frame of reference can be set by putting the checkerboard down, in a way that it is visible to all cameras. In Config.toml, you can choose frame_for_origin so that it specifies whether the checkerboard is in place in the first or the last image.

Calibration should work with your checkerboard since it is relatively large, but I had more accurate results with using other more spaced reference points in the room. See this issue if you want to try out this method.

ClarkGrif commented 1 year ago

Thank you David for your help.

First, I'm gonna try with my checkerboard and after try the other method you gave me.

But I just didn't understang how to obtain extrinsic parameters. Do I need to take an other video with the checkerboard down in a way that it is visible to all cameras ? Or, am I just laying the checkerboard in a way that it is visible to all cameras and run calibrateCams() ?

claraaudap commented 1 year ago

When I run calibrateCams(), this message appears :

Capture d’écran 2023-06-07 092721

And this picture appears :

Capture d’écran 2023-06-07 092811

davidpagnon commented 1 year ago

Okay, perfect! To keep detecting corners on the next images, you can just close them one by one. This setting is mostly set to make sure corners are correctly detected, but it is annoying to close windows one by one. To disable it, you can set "show_corner_detection" to false in Config.toml

ClarkGrif commented 1 year ago

Will it pass by camera 2 on its own?

davidpagnon commented 1 year ago

But I just didn't understang how to obtain extrinsic parameters. Do I need to take an other video with the checkerboard down in a way that it is visible to all cameras ? Or, am I just laying the checkerboard in a way that it is visible to all cameras and run calibrateCams() ?

Hi Clark, No, only one video per camera is enough for both intrinsic and extrinsic calibration.

I would recommend filming with all cameras together, showing the checkerboard to each of them carefully (exactly the way you already did), and then stepping back and laying it down to set your reference frame (i.e., your extrinisic parameters). Alternatively, you can do the opposite: first lay the checkerboard down, and then show it to each of your cameras. In this case, frame_for_origin should be set to 0 instead of -1.

It will do all cameras on its own.

claraaudap commented 1 year ago

Great, thank you I get it ! And last thing, what does it means :

Capture d’écran 2023-06-07 101203

I'm sorry for all this questions !

davidpagnon commented 1 year ago

Oh, so this is a different problem! It seems like a numpy function I was using just got deprecated. I just solved it, could you type pip install pose2sim --upgrade to implement the change?

(Sorry this is just curiosity, but am I answering to two people, or to one person with two different accounts? 😅)

claraaudap commented 1 year ago

Sorry ahah, you are answering to one people with two accounts !

So I upgrade pose2sim and the error disappears!

davidpagnon commented 1 year ago

Awesome! Tell me if you experience any other errors, especially with extrinsic parameters.

claraaudap commented 1 year ago

Hello,

I tried to film with all cameras together, showing the checkerboard to each of them carefully and then stepping back and laying it down but I think it's not working well. I sent you an email with an example of my video. Can you check what I am doing wrong please. And is it normal that the calibration takes a lot of time for a 3minutes video ?

Thanks Clara

davidpagnon commented 1 year ago

Hi Clara,

First of all, your coverage of the camera field by the checkerboard is good.

Then, it takes long because you optimize calibration over a ton of detected points. Considering the number of points in your checkerboard, I would say you need between 10, and maximum 30 images of the checkerboard. There are two solutions to it:

This is tedious, but this has to be done only once for each kind of camera. Actually, are they all the same kind, with the same lenses? If so, check the Calib.toml file you obtained: are all intrinsic parameters (especially matrix) roughly the same? If so, you don't need to do it again, intrinsic calibration has worked.

Then there is extrinsic calibration. What I suspect is that the corner #1 in each video does not correspond to the same one on the checkerboard, when it is laid on the floor. Can you check this by setting show_corner_detection to true? This is the problem when cameras are all around the subject, and not in the same semi-circle (and this is why I should implement the possibility to work with a Charuco board, but that's another subject).

There is another option for extrinsics though, which is to use the temporary script I wrote and explained there: https://github.com/perfanalytics/pose2sim/issues/23#issuecomment-1493291952 The idea is to point by hand each point you want to use for calibrating extrinsic (whether it is the checkerboard or anything in the environment), in the right order.

ClarkGrif commented 1 year ago

The problem is that when the checkerboard is on the ground, the cameras do not detect the corners. And for the second option, I didn't understand what I'm doing with the script, where I put it ?

claraaudap commented 1 year ago

I finished the calibration and this is the file I've got Capture d’écran 2023-06-20 165337

claraaudap commented 1 year ago

Do you think the data are good ?

claraaudap commented 1 year ago

And second question, is it normal to have 'nan px' for the 2D tracking of person ? track

davidpagnon commented 1 year ago

Okay, so there are several things:

I would really advise you to use the script I linked there. The main difference is that in the original function, extrinsic parameters are calculated from the detected corners on the last image; with the proposed script, they would be calculated from points you would point by hand (see image for example points you could label). Have a look, I edited the post to give more details about how to use the script.

image

ClarkGrif commented 1 year ago

The above calibration file was generated for another video. On the other video, it detects the corners well. So do you think the data of the calibration are good? I'm gonna try with the script.

And for the 2D tracking of person, is it normal to have 'nan px' ?

davidpagnon commented 1 year ago

No, it's not normal to have Nan px nor to have to exclude the maximum number of cameras on every frame. It means that it cannot find a correct triangulation of your neck point.

There are 2 questions:

I just managed to find a little time to work on making an easier calibration solution this morning, but I won't be able to work on it everyday so I would not expect it to be ready before mid-July.

Two other options if you can't make it work:

ClarkGrif commented 1 year ago

Thnk you for your time ! I'm gonna try what you gave me

davidpagnon commented 1 year ago

I don't know why I cannot see your last messages here but I got them per email, so I am going to answer what I can anyway. Can you see them?

ClarkGrif commented 1 year ago

I have a question : How to distinguish good calibration from bad calibration? Because I just finished setting up Pose2sim with 3 aligned cameras so that they all detect the checkerboard in the same direction. However, what I visualized in OpenSim had nothing to do with the recorded video. So, I was wondering if it could be due to the calibration or some other parameter.

ClarkGrif commented 1 year ago

I don't know why, me neither, I cannot see my previous messages. If you want I can send you by mail my folder of th project, it can be easier.

davidpagnon commented 1 year ago

Okay why not, send me your folder. I may not be able to work on it before next week, though.

There should be an output in the terminal that tells you about the calibration residual error (you can also find it in the log file that should be in your project folder). A good error is below a centimeter (2 or 3 cm should still give you coherent results)

ClarkGrif commented 1 year ago

Thank you!

I just checked and the résidual calibration errors are [3.357 , 4.672 , 4.069] mm. So the results should be coherent ! But for the Tracking of person, the mean reprojection error is 28.5px. So maybe it comes from there. I don't know. And for the triangulation, i've got this :

image

ClarkGrif commented 1 year ago

Hello, I just tried to calibrate using the script, and an error occurs when I do the 2D tracking of the person.

image

I have several questions regarding the script. When I write down its 3D coordinates of my checkerboard, 6x9 80 mm squares, should I write them in mm or m? And when I click point by point, should I do it in rows or columns? Does it matter?

Thank you

davidpagnon commented 1 year ago

Hello Clara,

I am sorry I am not very available these days. Among other projects, I am actually trying to make a better calibration tool that I would really like to release around mid-July (no promise, unfortunately).

Results are not completely incoherent (open your resulting TRC file with OpenSim: File -> Preview experimental results). But they are definitely not good enough for biomechanics. It is not normal that mean reprojection error is above the thresholds.

davidpagnon commented 1 year ago

Hello, I just tried to calibrate using the script, and an error occurs when I do the 2D tracking of the person.

image

I have several questions regarding the script. When I write down its 3D coordinates of my checkerboard, 6x9 80 mm squares, should I write them in mm or m? And when I click point by point, should I do it in rows or columns? Does it matter?

Thank you

The unit does not really matter, although it is more consistent to use the same as the square_size one (mm in your case). And you should click the image points in the same order as you defined the object points.

If your object points are like np.float32([[0,0,0], [80,0,0], [160,0,0], [80,0,0],[80,80,0],[80,160,0]]) Then your image points need to be the origin, one corner on the right, two corners on the right, and same thing one row above.

claraaudap commented 1 year ago

Thank you for your response. It'q fine if you cannot answers right away. It's already really helpful and nice to take time to read and reply all the time.

I just share with you my result. If you want to comment you can.

When I use the script. I get this calibration result :

image

I don't know if it looks fine.

But when I'm doing the 2D tracking of person; I still have "nan px" and a warning, I don't know where it comes from and I'm pretty sure it's not what I need to have.

image

For the triangulation, I have the same warning then for the tracking. And got this result

image

image

And for the filter3D, I have this kind of graph :

image

All of this, give me something really not workable on Opensim

davidpagnon commented 1 year ago

If track2D does not work, nothing else will. And in this case, it is most likely a calibration issue usually on extrinsic parameters.

I have the feeling that it would be much easier to talk through it by visioconference. I am not going to be available this week, but next week I'll be rather flexible.

ClarkGrif commented 1 year ago

I mean I'm sure I'm doing something wrong but I don't know why ! It would be great to do a visio to talk about it. Next week is perfect for me !

claraaudap commented 1 year ago

I can explain you how I use the script.

First, I write the coordinates in the objp matrix of my checkerboard. As I said it's a 6x9 80 mm squares : image

I extract from all my cameras and click on every point like this : image

After I replace the matrix and distortion found in my calib.toml file which give me : image

Finally, I put this in the terninal and I've got this result : image

This result looks really weird because all the data are kinf of the same but the cameras are in different position.

ClarkGrif commented 1 year ago

I found my mistake !! The result is still not workable but it's better.

davidpagnon commented 1 year ago

Solved after visioconference. The problem was the definition of the object points, a few of them were wrongly defined.

On another note, there may be an easier solution with Optitrack.

Please keep me updated if there is anything new!

davidpagnon commented 1 year ago

Actually @claraaudap @ClarkGrif , if you manage to make it work with Optitrack, would you mind posting a quick tutorial in a new issue so that I can add it to the documentation? 🙏

ClarkGrif commented 1 year ago

If it's working, I'll do that ! Thank you for your help with all my issues

ClarkGrif commented 1 year ago

Hello, just a last question, what is the difference between OpenPose and the track 2D ?

davidpagnon commented 1 year ago