-
Notifications
You must be signed in to change notification settings - Fork 49
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add service to capture and save frame
It is very valuable to be able to save the frame as a ZDF file, or export to other formats. This commit introduces the service capture_and_save_frame which both captures and saves the frame. It takes a path as an argument. See README.md#capture_and_save_frame for more information. In order to show how to use this service we also add a sample, both for Python and C++. Closes #65
- Loading branch information
Showing
11 changed files
with
176 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
string file_path | ||
--- |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
#!/usr/bin/env python | ||
|
||
import rospy | ||
import rosnode | ||
import dynamic_reconfigure.client | ||
from zivid_camera.srv import * | ||
from std_msgs.msg import String | ||
|
||
|
||
class Sample: | ||
def __init__(self): | ||
rospy.init_node("sample_capture_and_save_frame_py", anonymous=True) | ||
|
||
rospy.loginfo("Starting sample_capture_and_save_frame.py") | ||
|
||
rospy.wait_for_service("/zivid_camera/capture_and_save_frame", 30.0) | ||
|
||
self.capture_and_save_frame_service = rospy.ServiceProxy( | ||
"/zivid_camera/capture_and_save_frame", CaptureAndSaveFrame | ||
) | ||
|
||
rospy.loginfo("Enabling the first acquisition") | ||
acquisition_0_client = dynamic_reconfigure.client.Client( | ||
"/zivid_camera/settings/acquisition_0" | ||
) | ||
acquisition_0_config = { | ||
"enabled": True, | ||
} | ||
acquisition_0_client.update_configuration(acquisition_0_config) | ||
|
||
def capture(self): | ||
rospy.loginfo("Calling capture_and_save_frame service") | ||
file_path = "/tmp/capture_py.zdf" | ||
self.capture_and_save_frame_service(file_path) | ||
|
||
|
||
if __name__ == "__main__": | ||
s = Sample() | ||
s.capture() | ||
rospy.spin() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
#include <zivid_camera/SettingsAcquisitionConfig.h> | ||
#include <zivid_camera/CaptureAndSaveFrame.h> | ||
#include <dynamic_reconfigure/Reconfigure.h> | ||
#include <dynamic_reconfigure/client.h> | ||
#include <ros/ros.h> | ||
|
||
#define CHECK(cmd) \ | ||
do \ | ||
{ \ | ||
if (!cmd) \ | ||
{ \ | ||
throw std::runtime_error{ "\"" #cmd "\" failed!" }; \ | ||
} \ | ||
} while (false) | ||
|
||
namespace | ||
{ | ||
const ros::Duration default_wait_duration{ 30 }; | ||
|
||
void capture_and_save_frame() | ||
{ | ||
ROS_INFO("Calling capture_and_save_frame service"); | ||
zivid_camera::CaptureAndSaveFrame capture_and_save_frame; | ||
std::string file_path = "/tmp/capture_cpp.zdf"; | ||
capture_and_save_frame.request.file_path = file_path; | ||
CHECK(ros::service::call("/zivid_camera/capture_and_save_frame", capture_and_save_frame)); | ||
} | ||
|
||
} // namespace | ||
|
||
int main(int argc, char** argv) | ||
{ | ||
ros::init(argc, argv, "sample_capture_and_save_frame_cpp"); | ||
ros::NodeHandle n; | ||
|
||
ROS_INFO("Starting sample_capture_and_save_frame.cpp"); | ||
|
||
CHECK(ros::service::waitForService("/zivid_camera/capture_and_save_frame", default_wait_duration)); | ||
|
||
ros::AsyncSpinner spinner(1); | ||
spinner.start(); | ||
|
||
dynamic_reconfigure::Client<zivid_camera::SettingsAcquisitionConfig> acquisition_0_client("/zivid_camera/settings/" | ||
"acquisition_0/"); | ||
|
||
// To initialize the acquisition_0_config object we need to load the default configuration from the server. | ||
// The default values of settings depends on which Zivid camera model is connected. | ||
zivid_camera::SettingsAcquisitionConfig acquisition_0_config; | ||
CHECK(acquisition_0_client.getDefaultConfiguration(acquisition_0_config, default_wait_duration)); | ||
|
||
ROS_INFO("Enabling the first acquisition"); | ||
acquisition_0_config.enabled = true; | ||
CHECK(acquisition_0_client.setConfiguration(acquisition_0_config)); | ||
|
||
ROS_INFO("Calling capture_and_save_frame"); | ||
|
||
capture_and_save_frame(); | ||
|
||
ros::waitForShutdown(); | ||
|
||
return 0; | ||
} |