zivid / zivid-python-samples

Python code samples for Zivid
https://zivid.com
BSD 3-Clause "New" or "Revised" License
38 stars 14 forks source link

'PointCloud' object is not subscriptable #41

Closed pbermell closed 4 years ago

pbermell commented 4 years ago

Hello, I am wondering if there is a bug here. After running this code:

import os
import numpy as np
import cv2
import zivid
import matplotlib.pyplot as plt

app = zivid.Application()

ZDFs_directory = 'cameraOutput'
last_ZDF_dir = max([os.path.join(ZDFs_directory,d) for d in os.listdir(ZDFs_directory)], key=os.path.getmtime)
print(last_ZDF_dir)

first_ZDF_file = os.listdir(last_ZDF_dir)[0]

print(first_ZDF_file)

filename_zdf = first_ZDF_file

print(f"Reading {filename_zdf} point cloud")
frame = zivid.Frame(last_ZDF_dir + '/' + filename_zdf )

point_cloud = frame.get_point_cloud()
print(point_cloud)

depth_map = np.dstack([point_cloud["z"]])

I get this error:

/home/xtcdev/DEV/defectnet/venv/bin/python /home/xtcdev/DEV/defectnet/ZDF_processor.py
cameraOutput/20191016-141214_sample
shot_20191016-141725.zdf
Reading shot_20191016-141725.zdf point cloud
<zivid.point_cloud.PointCloud object at 0x7f80a15b9c88>
Traceback (most recent call last):
  File "/home/xtcdev/DEV/defectnet/ZDF_processor.py", line 28, in <module>
    depth_map = np.dstack([point_cloud["z"]])
TypeError: 'PointCloud' object is not subscriptable

this seems to be what is instructed in: https://github.com/zivid/python-samples/blob/master/zdf_with_opencv.py

thanks

SatjaSivcev commented 4 years ago

You are right, we made a change to zivid-python API. This will be fixed shortly.

For your code to work, you need to modify it to:

point_cloud = frame.get_point_cloud().to_array()

Sorry about that.

SatjaSivcev commented 4 years ago

We've implemented the required changes on the master branch. I will close this issue.

pbermell commented 4 years ago

thanks Satja, I am also having issues to save data as ply or pcd via python. Do those changes affect the ability to export ply or pcd? thanks

SatjaSivcev commented 4 years ago

The changes should not affect it. Can you provide the error message you get?

I assume you are talking about:

For .pcd you should check out c++ samples at: https://github.com/zivid/cpp-extra-samples/tree/master/ZividPCL

Please make another issue or email us at customersuccess@zivid.com as this is not related to this issue.

BIG-DD commented 2 years ago

The changes should not affect it. Can you provide the error message you get?

I assume you are talking about:

  • capture_save_ply.py (you can change the file name internally to .pcd)
  • convert_zdf (this works only with .ply)

For .pcd you should check out c++ samples at: https://github.com/zivid/cpp-extra-samples/tree/master/ZividPCL

Please make another issue or email us at customersuccess@zivid.com as this is not related to this issue.

Only get unordered point cloud

SatjaSivcev commented 2 years ago

From the SDK, supported extensions are .zdf, .ply (ordered), .xyz and .pcd. You can save unordered .ply from Zivid Studio only.

This article could be useful: https://support.zivid.com/latest/reference-articles/point-cloud-structure-and-output-formats.html#zivid-output-formats

SatjaSivcev commented 2 years ago

@pbermell, @BIG-DD, have I answered your questions? Also, please let me know if you have a specific feature request. In other words, is there a specific function that would be useful for you and is currently missing in the Zivid SDK?