osu-capstone-afrl / photogrammetry-capture-motion

ROS Package for Reconstruction Motion (moves camera on robot)
2 stars 0 forks source link

Add DSLR Camera Control #5

Open acbuynak opened 3 years ago

acbuynak commented 3 years ago

@tijaci Demonstrated ability to control a DSLR camera via command line.

2021_03_16 I’ve taken a picture and downloaded it to my computer using the terminal.

Creating this issue to track the creation a control script and addition of this ability to the repo.

acbuynak commented 3 years ago

Info from @tijaci. Copied from external discussion for archive here.

I got it to work in two ways using Python. There is a gphoto2 module already written that is downloadable. The only thing is that it is very opaque to me in how it works. Either because the documentation/examples are limited or there is some implied knowledge I don't have. There are some functions and example programs that work but don't do what I want--so I should be able to write my own from that module once I figure out how that works. This might be something I hit you or Andrew up later if I can't figure it out.

The other method is just using subprocess calls to the command line. This seems pretty janky to me and probably not a good idea, but that's just a guess on my part being new to Linux.

acbuynak commented 3 years ago

Quick thoughts..

The other method is just using subprocess calls to the command line. This seems pretty janky to me and probably not a good idea, but that's just a guess on my part being new to Linux.

This doesn't sound too bad to me. I agree that a direct gphoto2 module may be best suited for our project needs, but if it's complicated enough for the month remaining in this project... then let's go with subprocess calls.

I'm personally cool with subprocess calls if they are low CPU usage and execute quickly. If really necessary we could just use athreading package to push it onto it's own thread.

acbuynak commented 3 years ago

Big Picture wise, I'm imagining that if we can have a class that set's up the setting's like...

camera = CameraClass( settings )

And then in the code we use a single API call that we input a name for the to-be-saved photo and it returns the absolute file path of the saved photo. like this..

new_photo_filepath = camera.take_single_photo( )

I think that's all we need for an MVP.

acbuynak commented 3 years ago

@Schellenberg3 & I reviewed the camera.py control code and just wanted to ask for a few changes.

https://github.com/osu-capstone-afrl/photogrammetry-capture-motion/blob/2e0f676a31e5839547bee5d2d614632138241179/camera/camera.py#L19-L25

1 - As included in the main function, this looks like the API we would want to import and call in the main motion loop. I think we'll just need input variables added. Can you include the below:

2 - I'd also like to document here the file naming structure if we can start that discussion as well.

Side Note, A long term goal is to record the location, pose, filename, etc for each photo taken. So that's why we want log that information.

tijaci commented 3 years ago

@acbuynak is this the sort of change you're looking for?


    def __init__(self, filename, directory):
        self.filename = filename
        file_name = " --filename " + filename  # make sure this doesn't repeat names
        gphoto2 = "gphoto2"
        self.directory = directory  # directory photos are downloaded to
        file_name = " --filename " + filename  # make sure this doesn't repeat names
        capture = " --capture-image-and-download"
        overwrite = " --force-overwrite"
        process_call = gphoto2 + file_name + capture + overwrite  # can remove overwrite if file_name is iterative "%n"

        def subprocess_cmd(command):  # allows multiple commands at once
            process = subprocess.Popen(command, stdout=subprocess.PIPE, shell=True)
            proc_stdout = process.communicate()[0].strip()

        def capture_photo():  # capture photo and download
            # Use a breakpoint in the code line below to debug your script.
            os.chdir(directory)
            # subprocess.call([gphoto2, process_call])
            # subprocess_cmd("gphoto2 --filename %H.%M.%S --capture-image-and-download --force-overwrite")
            subprocess_cmd(process_call)
            # call("lsusb")
            return directory
acbuynak commented 3 years ago

I think this looks good. @Schellenberg3 and I will test it tomorrow in the lab.

Thanks!

acbuynak commented 3 years ago

@tijaci Can you write up some instructions on what base libraries and package(s) we need to install on linux to run this?

acbuynak commented 3 years ago

@Schellenberg3 was able to get the commands working via terminal so we know the connection should work now. We just need to purchase a cable long enough for the robot.

@tijaci Can you implement the proposed code above into a PR? Or directly into code, either way works.