Open jenyak opened 1 year ago
I am also getting the same issue
This is happening for me as well, on a brand new rpi install. I found references to the function, but I can't see that library included anywhere. I tried installing the source, but I'm guessing I have issues with my include path? No matter what I've tried, it just won't compile. I'm not extremely good with C, though, so I'm not sure what I'm missing.
I have compiled pcl-pcl-1.12.0 but facing same issue.
Actually there are error in the code preview_pointcloud.cpp
I have tweaked the code and got success in compilatin :)
using namespace Arducam;
boost::shared_ptr
void getPreview(uint8_t preview_ptr, float depth_image_ptr, float amplitude_image_ptr) { auto len = 240 180; for (int i = 0; i < len; i++) { uint8_t mask = (amplitude_image_ptr + i) > 30 ? 254 : 0; float depth = ((1 - ((depth_image_ptr + i) / MAX_DISTANCE)) 255); uint8_t pixel = depth > 255 ? 255 : depth; (preview_ptr + i) = pixel & mask; } }
int main() { ArducamTOFCamera tof; ArducamFrameBuffer frame; char buff[60]; float depth_ptr; float amplitude_ptr; uint8_t preview_ptr = new uint8_t[43200]; if (tof.init(Connection::CSI)) { std::cerr << "initialization failed" << std::endl; exit(-1); } if (tof.start()) { std::cerr << "Failed to start camera" << std::endl; exit(-1); } tof.setControl(ControlID::RANGE, MAX_DISTANCE);
pcl::PointCloud<pcl::PointXYZ>::Ptr cloud_ptr(new pcl::PointCloud<pcl::PointXYZ>);
cloud_ptr->points.push_back(pcl::PointXYZ(10, 10, 4));
cloud_ptr->width = cloud_ptr->size();
cloud_ptr->height = 1;
cloud_ptr->is_dense = true;
vtkObject::GlobalWarningDisplayOff();
boost::shared_ptr<pcl::visualization::PCLVisualizer> viewer = simpleVis(cloud_ptr);
const float fx = 240 / (2 * tan(0.5 * M_PI * 64.3 / 180));
const float fy = 180 / (2 * tan(0.5 * M_PI * 50.4 / 180));
for (;;)
{
frame = tof.requestFrame(200);
if (frame != nullptr)
{
depth_ptr = (float *)frame->getData(FrameType::DEPTH_FRAME);
amplitude_ptr = (float *)frame->getData(FrameType::AMPLITUDE_FRAME);
getPreview(preview_ptr, depth_ptr, amplitude_ptr);
cv::Mat result_frame(180, 240, CV_8U, preview_ptr);
cv::Mat amplitude_frame(180, 240, CV_32F, amplitude_ptr);
cv::Mat depth_frame(180, 240, CV_32F, depth_ptr);
pcl::PointCloud<pcl::PointXYZ>::Ptr current_cloud(new pcl::PointCloud<pcl::PointXYZ>);
current_cloud->height = 180;
current_cloud->width = 240;
current_cloud->points.resize(current_cloud->height * current_cloud->width);
for (int v = 0; v < depth_frame.rows; ++v)
{
for (int u = 0; u < depth_frame.cols; ++u)
{
float z = depth_frame.at<float>(v, u);
float x = (u - depth_frame.cols / 2.0) * z / fx;
float y = (v - depth_frame.rows / 2.0) * z / fy;
current_cloud->points[v * depth_frame.cols + u].x = x;
current_cloud->points[v * depth_frame.cols + u].y = y;
current_cloud->points[v * depth_frame.cols + u].z = z;
}
}
viewer->updatePointCloud<pcl::PointXYZ>(current_cloud, "sample cloud");
viewer->spinOnce(1);
pcl::io::savePCDFileASCII("test_pcd.pcd", *current_cloud);
cv::imshow("Preview", result_frame);
cv::imshow("Amplitude", amplitude_frame);
cv::waitKey(1);
tof.releaseFrame(frame);
}
}
tof.stop();
delete[] preview_ptr;
return 0;
}
Fantastic! Your copy/paste didn't come over cleanly, but I diff'd between the old and new and figured out what was missing. I was able to compile and run it as well. Thanks so much!
preview_pointcloud.zip Here you go I have attached the file.
Hello, thank you for doing this! I'm getting similar errors, and tried using your modify script, but it won't build anymore. Currently, the original .cpp file builds, but I'm getting this error, and I'm wondering if you ever got the same.
raspi@raspi:~/Arducam_tof_camera/build/pcl_preview$ ./preview_pointcloud open camera with (240x180) with range 4000 [ WARN:0] global ./modules/highgui/src/window.cpp (703) createTrackbar UI/Trackbar(confidence@preview): Using 'value' pointer is unsafe and deprecated. Use NULL as value pointer. To fetch trackbar value setup callback. frame: (240x180) Segmentation fault (core dumped)
Both examples
and
fail with same error
On fresh RPI 4b 4GB