UTokyo-FieldPhenomics-Lab / EasyIDP

A handy tool for dealing with region of interest (ROI) on the image reconstruction (Metashape & Pix4D) outputs, mainly in agriculture applications
https://easyidp.readthedocs.io/en/latest/
MIT License
44 stars 6 forks source link

update the `raw_image_folder` docs description about the metashape default image path #95

Open bw4sz opened 1 year ago

bw4sz commented 1 year ago

I am working on a jupyter notebook that hopefully can serve to help others understand the workflow and provide some wording familiar to drone users for environmental surveys. I'll be making small issues, mostly related to docs that could help the next users access this great tool.

  1. How does rio.back2raw() determine the location of the raw images when specifying the save folder?
import easyidp as idp
import numpy as np
from deepforest import main
from deepforest import utilities
import glob
from matplotlib import pyplot

# Load a deepforest bird prediction module
m = main.deepforest()
m.use_bird_release()

# 1) Predict birds in orthomosaic for existing model
predictions = m.predict_tile("/Users/benweinstein/Dropbox/Weecology/everglades_species/Raw_versus_Ortho/Vacation_03_20_2023.tif", patch_size=2000, patch_overlap=0)

# 2) Export predictions to a shapefile
gdf = utilities.boxes_to_shapefile(df=predictions, root_dir="/Users/benweinstein/Dropbox/Weecology/everglades_species/Raw_versus_Ortho/")
gdf.to_file("/Users/benweinstein/Dropbox/Weecology/everglades_species/Raw_versus_Ortho/Vacation_03_20_2023_ortho_predictions.shp")

# 3) Read in Agisoft Project
ms = idp.Metashape("/Users/benweinstein/Dropbox/Weecology/everglades_species/Raw_versus_Ortho/Vacation/Vacation_03_20_2023.psx", chunk_id=0)

# 4 ) Read in shapefile as a 'region of interest', each bird will be a seperate ROI
roi = idp.ROI("/Users/benweinstein/Dropbox/Weecology/everglades_species/Raw_versus_Ortho/Vacation_03_20_2023_ortho_predictions.shp", name_field=None)

# 5) Get Digital Elevation Model exported from agisoft
dom = roi.get_z_from_dsm("/Users/benweinstein/Dropbox/Weecology/everglades_species/Raw_versus_Ortho/Vacation_03_20_2023_DEM.tif")

# 6) Backward Project to find each region of interest in raw imagery
img_dict = roi.back2raw(ms)

# Or save drawings of found images
img_dict = roi.back2raw(ms, save_folder="/Users/benweinstein/Dropbox/Weecology/everglades_species/Raw_versus_Ortho/results/")
builtins.FileNotFoundError: No such file: '/Users/benweinstein/Dropbox/Weecology/everglades_species/InspireRawData/Vacation/Vacation_03_20_2023/DJI_0093.JPG'

Which is fine, i can easily go and put the images there, but how was the location determined? Moving the photos to that location works great. Not obvious from the doc string. https://easyidp.readthedocs.io/en/latest/python_api/manualdoc/easyidp.roi.ROI.html#easyidp.roi.ROI.back2raw

57_DJI_0119_at_top_583_left_1036

HowcanoeWang commented 1 year ago

This is a problem happens at reading the raw image but could not find it using the metashape project recorded image path.

In the metashape project files, project.files/0/0/frames.zip/docs.xml

There is a path to parse the relative path between the raw image and metashape project. Take the previous ForestBirds() dataset as example:

<camera camera_id="17">
      <photo path="../../../../../Inspire Raw Data/Hidden_Little/Hidden_Little_03_24_2022/DJI_0126.JPG">
        <meta>
          <property name="DJI/AbsoluteAltitude" value="+42.43"/>
          <property name="DJI/FlightPitchDegree" value="-4.50"/>
          <property name="DJI/FlightRollDegree" value="+2.70"/>

So, did you change the path of raw image folder after finishing the reconstruction?

(PS: I also need to modify the ForestBirds dataset due to the same reason)

bw4sz commented 1 year ago

Got it. The original workflow had no intention of backwards projection, we didn't keep the projects together with the raw imagery. We are changing this now.

HowcanoeWang commented 1 year ago

Provide a folder changing function:

# how to change the demo detaset
ms = idp.Metashape(
    fb.metashape.project, chunk_id=0,
    raw_img_folder=fb.data_dir / "Hidden_Little_03_24_2022")

# the string like 'c:/path/to/new/folder/' should also work

Apologies no time for detailed documentation currently