Forum

Author Topic: Scale Bars Between Cameras  (Read 6812 times)

guicanarin

  • Newbie
  • *
  • Posts: 32
    • View Profile
Scale Bars Between Cameras
« on: May 15, 2018, 06:42:47 PM »
Hello Guys!
I have already wrote a python script to load two cameras in each chunk, só i had 80 cameras and 40 chunks.
But i want to create a scale bar between cameras, for example, i'll have, in the end, 40 scale bars.
Someone can help me??
The distance of all scale bars will be the same, because the cameras will be in a stereo system.

this is my code
Code: [Select]
import os, PhotoScan
doc = PhotoScan.app.document
path_photos = PhotoScan.app.getExistingDirectory("C:\\Users\lma\Documents\Fotos.jpg")
image_list = os.listdir(path_photos)
photo_list = list()
for photo in image_list:
    if photo.rsplit(".",1)[1].lower() in  ["jpg", "jpeg", "tif", "tiff"]:
        photo_list.append("/".join([path_photos, photo]))
start = 0
while (start +1 < len(photo_list)):
    chunk = doc.addChunk()
    chunk.addPhotos(photo_list[start:start+2])
    chunk.detectMarkers(type=PhotoScan.CircularTarget12bit)
    start += 2
PhotoScan.app.document.chunks[-1]
PhotoScan.app.document.mergeChunks()
merged_chunk = PhotoScan.app.document.chunks[-1]
merged_chunk.matchPhotos(accuracy=PhotoScan.HighAccuracy)
merged_chunk.alignCameras(adaptive_fitting=True)
merged_chunk.buildDepthMaps(quality=PhotoScan.UltraQuality, filter=PhotoScan.AggressiveFiltering)
merged_chunk.buildDenseCloud(point_colors=True)



Alexey Pasumansky

  • Agisoft Technical Support
  • Hero Member
  • *****
  • Posts: 14843
    • View Profile
Re: Scale Bars Between Cameras
« Reply #1 on: May 15, 2018, 07:45:52 PM »
Hello guicanarin,

In the merge chunk you can run the following:

Code: [Select]
DISTANCE = 0.5
for i in range(len(merged_chunk.cameras)-1):
    scalebar = chunk.addScalebar(merged_chunk.cameras[i], merged_chunk.cameras[i+1])
    scalebar.label = merged_chunk.cameras[i].label + " - " + merged_chunk.cameras[i+1].label
    scalebar.reference.distance = DISTANCE
Best regards,
Alexey Pasumansky,
Agisoft LLC

guicanarin

  • Newbie
  • *
  • Posts: 32
    • View Profile
Re: Scale Bars Between Cameras
« Reply #2 on: May 15, 2018, 08:53:45 PM »
Hi Alexey, thank you for supporting me, but it doesn't work.
Look, my script was this
Code: [Select]
import os, PhotoScan
doc = PhotoScan.app.document
path_photos = PhotoScan.app.getExistingDirectory("C:\\Users\lma\Documents\Fotos.jpg")
image_list = os.listdir(path_photos)
photo_list = list()
for photo in image_list:
    if photo.rsplit(".",1)[1].lower() in  ["jpg", "jpeg", "tif", "tiff"]:
        photo_list.append("/".join([path_photos, photo]))
start = 0
while (start +1 < len(photo_list)):
    chunk = doc.addChunk()
    chunk.addPhotos(photo_list[start:start+2])
    chunk.detectMarkers(type=PhotoScan.CircularTarget12bit)
    start += 2
PhotoScan.app.document.chunks[-1]
PhotoScan.app.document.mergeChunks()
DISTANCE = 200
 for i in range(len(merged_chunk.cameras)-1):
    scalebar = chunk.addScalebar(merged_chunk.cameras[i], merged_chunk.cameras[i+1])
    scalebar.label = merged_chunk.cameras[i].label + " - " + merged_chunk.cameras[i+1].label
    scalebar.reference.distance = DISTANCE
merged_chunk = PhotoScan.app.document.chunks[-1]
merged_chunk.matchPhotos(accuracy=PhotoScan.HighAccuracy)
merged_chunk.alignCameras(adaptive_fitting=True)
merged_chunk.buildDepthMaps(quality=PhotoScan.UltraQuality, filter=PhotoScan.AggressiveFiltering)
merged_chunk.buildDenseCloud(point_colors=True)



And the problem is

ValueError                                Traceback (most recent call last)
<ipython-input-11-44277582cab8> in <module>()
     17 DISTANCE = 200
     18 for i in range(len(merged_chunk.cameras)-1):
---> 19     scalebar = chunk.addScalebar(merged_chunk.cameras, merged_chunk.cameras[i+1])
     20     scalebar.label = merged_chunk.cameras.label + " - " + merged_chunk.cameras[i+1].label
     21     scalebar.reference.distance = DISTANCE

ValueError: sequence element is not a Camera or Marker object

Alexey Pasumansky

  • Agisoft Technical Support
  • Hero Member
  • *****
  • Posts: 14843
    • View Profile
Re: Scale Bars Between Cameras
« Reply #3 on: May 15, 2018, 08:55:07 PM »
Hello guicanarin,

You are using merged_chunk variable before it it actually initialized.
Best regards,
Alexey Pasumansky,
Agisoft LLC

guicanarin

  • Newbie
  • *
  • Posts: 32
    • View Profile
Re: Scale Bars Between Cameras
« Reply #4 on: May 15, 2018, 09:52:12 PM »
Hello Alexey, sorry foi this..
But i'm still having problems
look...
Code: [Select]
import os, PhotoScan
doc = PhotoScan.app.document
path_photos = PhotoScan.app.getExistingDirectory("C:\\Users\lma\Documents\Fotos.jpg")
image_list = os.listdir(path_photos)
photo_list = list()
for photo in image_list:
    if photo.rsplit(".",1)[1].lower() in  ["jpg", "jpeg", "tif", "tiff"]:
        photo_list.append("/".join([path_photos, photo]))
start = 0
while (start +1 < len(photo_list)):
    chunk = doc.addChunk()
    chunk.addPhotos(photo_list[start:start+2])
    chunk.detectMarkers(type=PhotoScan.CircularTarget12bit)
    start += 2
PhotoScan.app.document.chunks[-1]
PhotoScan.app.document.mergeChunks()
merged_chunk = PhotoScan.app.document.chunks[-1]
DISTANCE = 200
for i in range(len(merged_chunk.cameras)-1):
    scalebar = chunk.addScalebar(merged_chunk.cameras[i], merged_chunk.cameras[i+1])
    scalebar.label = merged_chunk.cameras[i].label + " - " + merged_chunk.cameras[i+1].label
    scalebar.reference.distance = DISTANCE
merged_chunk.matchPhotos(accuracy=PhotoScan.HighAccuracy)
merged_chunk.alignCameras(adaptive_fitting=True)
merged_chunk.buildDepthMaps(quality=PhotoScan.UltraQuality, filter=PhotoScan.AggressiveFiltering)
merged_chunk.buildDenseCloud(point_colors=True)




And the problem

---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)
<ipython-input-16-11d873c156ac> in <module>()
     18 DISTANCE = 200
     19 for i in range(len(merged_chunk.cameras)-1):
---> 20     scalebar = chunk.addScalebar(merged_chunk.cameras, merged_chunk.cameras[i+1])
     21     scalebar.label = merged_chunk.cameras.label + " - " + merged_chunk.cameras[i+1].label
     22     scalebar.reference.distance = DISTANCE

ValueError: sequence element is not a Camera or Marker object

Alexey Pasumansky

  • Agisoft Technical Support
  • Hero Member
  • *****
  • Posts: 14843
    • View Profile
Re: Scale Bars Between Cameras
« Reply #5 on: May 15, 2018, 10:12:38 PM »
Hello guicanarin,

Sorry, there's a typo in the line 20 of you latest code. Should be:
 scalebar = merged_chunk.addScalebar(merged_chunk.cameras, merged_chunk.cameras[i+1])
Best regards,
Alexey Pasumansky,
Agisoft LLC

guicanarin

  • Newbie
  • *
  • Posts: 32
    • View Profile
Re: Scale Bars Between Cameras
« Reply #6 on: May 15, 2018, 10:27:27 PM »
Hello Alexey, that seems funny (or not), but still not working =(
look
Code: [Select]
import os, PhotoScan
doc = PhotoScan.app.document
path_photos = PhotoScan.app.getExistingDirectory("C:\\Users\lma\Documents\Fotos.jpg")
image_list = os.listdir(path_photos)
photo_list = list()
for photo in image_list:
    if photo.rsplit(".",1)[1].lower() in  ["jpg", "jpeg", "tif", "tiff"]:
        photo_list.append("/".join([path_photos, photo]))
start = 0
while (start +1 < len(photo_list)):
    chunk = doc.addChunk()
    chunk.addPhotos(photo_list[start:start+2])
    chunk.detectMarkers(type=PhotoScan.CircularTarget12bit)
    start += 2
PhotoScan.app.document.chunks[-1]
PhotoScan.app.document.mergeChunks()
merged_chunk = PhotoScan.app.document.chunks[-1]
DISTANCE = 0.2
for i in range(len(merged_chunk.cameras)-1):
    scalebar = merged_chunk.addScalebar(merged_chunk.cameras, merged_chunk.cameras[i+1])
    scalebar.label = merged_chunk.cameras[i].label + " - " + merged_chunk.cameras[i+1].label
    scalebar.reference.distance = DISTANCE
merged_chunk.matchPhotos(accuracy=PhotoScan.HighAccuracy)
merged_chunk.alignCameras(adaptive_fitting=True)
merged_chunk.buildDepthMaps(quality=PhotoScan.UltraQuality, filter=PhotoScan.AggressiveFiltering)
merged_chunk.buildDenseCloud(point_colors=True)


The problem

---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)
<ipython-input-20-eb1a255791ff> in <module>()
     18 DISTANCE = 0.2
     19 for i in range(len(merged_chunk.cameras)-1):
---> 20     scalebar = merged_chunk.addScalebar(merged_chunk.cameras, merged_chunk.cameras[i+1])
     21     scalebar.label = merged_chunk.cameras.label + " - " + merged_chunk.cameras[i+1].label
     22     scalebar.reference.distance = DISTANCE

ValueError: sequence element is not a Camera or Marker object

Alexey Pasumansky

  • Agisoft Technical Support
  • Hero Member
  • *****
  • Posts: 14843
    • View Profile
Re: Scale Bars Between Cameras
« Reply #7 on: May 16, 2018, 12:46:09 AM »
It was merged_chunk.cameras, merged_chunk.cameras[i+1] in the original post, wasn't it?
Best regards,
Alexey Pasumansky,
Agisoft LLC

guicanarin

  • Newbie
  • *
  • Posts: 32
    • View Profile
Re: Scale Bars Between Cameras
« Reply #8 on: May 16, 2018, 03:16:02 AM »
Hello alexey, i was wondering and trying to solve this problem, and i noticed that the scale bars will be created in merged chunks.
And it is not that i want, i want to create the scale bars before this step.
For example.
I have 80 Photos, and my script will create 40 chunks with 2 photos each in it.
And is in this step, after create the chunk with 2 photos , that the script will create the scale bars, all with the same lenght. And, in the end i will have 40 scale bars.
So, i put the scale bars line in my script, to you understand where the script will create hah
TY

Code: [Select]
import os, PhotoScan
doc = PhotoScan.app.document
path_photos = PhotoScan.app.getExistingDirectory("C:\\Users\lma\Documents\Fotos.jpg")
image_list = os.listdir(path_photos)
photo_list = list()
for photo in image_list:
    if photo.rsplit(".",1)[1].lower() in  ["jpg", "jpeg", "tif", "tiff"]:
        photo_list.append("/".join([path_photos, photo]))
start = 0
while (start +1 < len(photo_list)):
    chunk = PhotoScan.app.document.chunk
    chunk = doc.addChunk()
    chunk.addPhotos(photo_list[start:start+2])
    chunk.detectMarkers(type=PhotoScan.CircularTarget12bit)
   [color=red][b] chunk.addScalebar(chunk.cameras[1],chunk.cameras[2]) [/b][/color]
    start += 2
PhotoScan.app.document.chunks[-1]
PhotoScan.app.document.mergeChunks()
merged_chunk = PhotoScan.app.document.chunks[-1]
merged_chunk.matchPhotos(accuracy=PhotoScan.HighAccuracy)
merged_chunk.alignCameras(adaptive_fitting=True)
merged_chunk.buildDepthMaps(quality=PhotoScan.UltraQuality, filter=PhotoScan.AggressiveFiltering)
merged_chunk.buildDenseCloud(point_colors=True)

Alexey Pasumansky

  • Agisoft Technical Support
  • Hero Member
  • *****
  • Posts: 14843
    • View Profile
Re: Scale Bars Between Cameras
« Reply #9 on: May 16, 2018, 04:01:11 PM »
Hello guicanarin,

Does the following modification work?

Code: [Select]
DISTANCE = 0.2
start = 0
while (start +1 < len(photo_list)):
    chunk = doc.addChunk()
    chunk.addPhotos(photo_list[start:start+2])
    chunk.detectMarkers(type=PhotoScan.CircularTarget12bit)
    scalebar = chunk.addScalebar(chunk.cameras[0],chunk.cameras[1])
    scalebar.label = chunk.cameras[0].label + " - " + chunk.cameras[1].label
    scalebar.reference.distance = DISTANCE
    start += 2
PhotoScan.app.document.mergeChunks()
merged_chunk = PhotoScan.app.document.chunks[-1]
Best regards,
Alexey Pasumansky,
Agisoft LLC

guicanarin

  • Newbie
  • *
  • Posts: 32
    • View Profile
Re: Scale Bars Between Cameras
« Reply #10 on: May 16, 2018, 04:42:24 PM »
OMG!!
It works!!
Thank You so much, alexey!!

jedfrechette

  • Full Member
  • ***
  • Posts: 130
  • Lidar Guys
    • View Profile
    • www.lidarguys.com
Re: Scale Bars Between Cameras
« Reply #11 on: May 23, 2018, 02:18:45 AM »
Is the latest version of the script in reply #9 actually working with the current version of Photoscan? Using version 1.4.2 if I try to do:

Code: [Select]
scalebar = chunk.addScalebar(chunk.cameras[0],chunk.cameras[1])
scalebar.reference.distance = 0.2

it throws an exception:

Code: [Select]
AttributeError: 'PhotoScan.Scalebar.Reference' object attribute 'distance' is read-only
If instead I try:

Code: [Select]
scalebar.Reference.distance = 0.5
that almost seems to work:

Code: [Select]
print(scalebar.reference.distance == scalebar.Reference.distance == 0.5)
True

However, if I look at the list of scale bars in the gui non of the scalebars that I've programmatically created have distance values assigned to them.

For my application I'm trying to create scale bars from markers, but the behavior is the same as described above.
Jed

Alexey Pasumansky

  • Agisoft Technical Support
  • Hero Member
  • *****
  • Posts: 14843
    • View Profile
Re: Scale Bars Between Cameras
« Reply #12 on: May 23, 2018, 08:50:33 PM »
Hello Jed,

I've used the source code:
Code: [Select]
scalebar = chunk.addScalebar(chunk.cameras[0],chunk.cameras[1])
scalebar.reference.distance = 0.2
and it worked find on a random project, so it seems that there might be some issues with your script. Are you using latest PhotoScan Pro version?
Best regards,
Alexey Pasumansky,
Agisoft LLC

James

  • Hero Member
  • *****
  • Posts: 748
    • View Profile
Re: Scale Bars Between Cameras
« Reply #13 on: May 24, 2018, 02:17:53 PM »
I found that i could intermittently recreate the problem using a minimal version of the script manually typing in the console

By setting a few scalebars' distances using scalebar.reference.distance = x i could set the distances with no problem and they immediately appeared in the reference pane, but after a combination of either clicking the 'update' button and/or setting scalebar.Reference.distance =y (with a capital R) i could no longer set scalebar.reference.distance = x without the exception mentioned, yet could still set scalebar.Reference.distance =y (with a capital R) although this did not show in the reference pane.

At that point i stopped playing and went back to work.

Alexey Pasumansky

  • Agisoft Technical Support
  • Hero Member
  • *****
  • Posts: 14843
    • View Profile
Re: Scale Bars Between Cameras
« Reply #14 on: May 24, 2018, 02:38:42 PM »
Hello James,

Using scalebar.Reference.distance assignment you are actually breaking the script.

By calling scalebar.Reference you are accessing type definition. And scalebar.Reference.distance - is general method, not something that is applied to certain scalebar.
Best regards,
Alexey Pasumansky,
Agisoft LLC