Forum

Author Topic: I'm newbie trying to get chunk.model.renderImage to work (image is 0 by 0)  (Read 2713 times)

Dan K

  • Newbie
  • *
  • Posts: 3
    • View Profile
Hello all,

  I'm trying to render an image of a point cloud seen from a pose, with certain intrinsics. However, I'm getting an image of zero width and height. I already loaded successfully the point cloud and also created a mesh for it. What am I doing wrong? Here's the code I'm using:


# running on GUI's console
# point cloud already imported into chunk1

doc = Metashape.app.document
chunks = doc.chunks
my_chunk = chunks[0]
sz = my_chunk.region.size
sz_new = sz

sz_new[0] = 20
sz_new[1] = 20
sz_new[2] = 20

my_chunk.region.size = sz_new

# create mesh via GUI

# point cloud is contained in: my_chunk.dense_cloud

# identity pose
my_pose = Metashape.Matrix( [[1, 0, 0, 0], [0, 1, 0, 0], [0, 0, 1, 0], [0, 0, 0, 1]] )

my_calib = Metashape.Calibration()
my_calib.f = 1000
my_calib.cx = 500
my_calib.cy = 500
# my_calib.b1 = 0
# my_calib.b2 = 0   
my_calib.k1 = 0
my_calib.k2 = 0
my_calib.k3 = 0
my_calib.k4 = 0
# my_calib.p1 = 0
# my_calib.p2 = 0
my_calib.width = 1000
my_calib.height = 1000
# my_calib.type = Metashape.Sensor.Type.Frame

img = my_chunk.model.renderImage(my_pose, my_calib)

print(img.width, img.height)

# This last statement returns 0, 0!!


Thanks for any help,
   ~ Dan

Paulo

  • Hero Member
  • *****
  • Posts: 1320
    • View Profile
Dan,

i think your ideal camera should have PP coordinates at image center i.e. cx = cy = 0 and not 500 ....

Then depending on your pose rotation and position, you should get an image 1000 by 1000
Best Regards,
Paul Pelletier,
Surveyor

Alexey Pasumansky

  • Agisoft Technical Support
  • Hero Member
  • *****
  • Posts: 14847
    • View Profile
Hello Dan,

I've used same code for calibration and pose estimation on a random project and it resulted in the image with the proper dimensions (although, the image is blank due to wrond orientation).

Which version of Metashape you are using and whether there are any error messages in the Console pane, when you run your code?
Best regards,
Alexey Pasumansky,
Agisoft LLC

Dan K

  • Newbie
  • *
  • Posts: 3
    • View Profile
I tried changing cx and cy to 0. And also tried looking in 4 different directions. I always get a black image. So actually, it's not 0 by 0. It's 1000 by 1000 but black. Maybe I need to double-click on either cloud or mesh before running this?

Paulo

  • Hero Member
  • *****
  • Posts: 1320
    • View Profile
Dan,

i think you should look at your pose position.. Right now in your code it is defined as 0,0,0... Maybe this position is way off your model and thus never captures any piece of model... maybe try set the pose position as top of your region.center?

And note that pose orientation as  Metashape.Matrix( [1, 0, 0], [0, 1, 0], [0, 0, 1] ) may be looking up instead of down to model... so maybe inverting some of the axes (-1) could do the trick...
Best Regards,
Paul Pelletier,
Surveyor

Paulo

  • Hero Member
  • *****
  • Posts: 1320
    • View Profile
Looking at example from following screen capture. I used for origin of Pose, camera.center for some selected camera hovering over the model. And the Y and Z axes of pose orientation were inverted... This gave a rendered image (render.jpg) with non blank pixels....
« Last Edit: August 10, 2019, 04:45:47 AM by Paulo »
Best Regards,
Paul Pelletier,
Surveyor

Dan K

  • Newbie
  • *
  • Posts: 3
    • View Profile
Thank you Paul. I guess I have to learn how to use cameras. Is there a good guide written for Metashape? Like a tutorial with lots of examples? Another thing: I read in my point cloud through the GUI. Is that what you did for your points? Or did you do through python console?

Thanks,
   Dan

Paulo

  • Hero Member
  • *****
  • Posts: 1320
    • View Profile
Dan,

if you are interested to render for each actual camera pose in your project then look at : https://github.com/agisoft-llc/metashape-scripts/blob/master/src/render_photos_for_cameras.py....

As for generating a pose from any defined position, you just have to set your pose position to these coordinates and then apply your code and bingo you get a new render from new position and same attitude. In another example, I set the camera pose position to top of region.center and see what i get....

For your question about reading point cloud thru GUI, I don't really understand... In my example project, alignment, point cloud and model were all generated with GUI....

« Last Edit: August 11, 2019, 07:23:10 PM by Paulo »
Best Regards,
Paul Pelletier,
Surveyor