Skip to content

Commit

Permalink
Add flip method
Browse files Browse the repository at this point in the history
  • Loading branch information
seanavery committed Apr 2, 2024
1 parent 28447d5 commit ab11248
Show file tree
Hide file tree
Showing 6 changed files with 15 additions and 4 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ On the new component panel, copy and paste the following attribute template into
"width_px": <int>,
"height_px": <int>,
"frame_rate": <int>,
"flip_method": <string>,
"debug": <bool>
}
```
Expand All @@ -60,6 +61,7 @@ The following attributes are available for `viam:camera:csi` cameras:
| `height_px` | int | Optional | Height of the image this camera captures in pixels. <br> Default: `1080` |
| `frame_rate` | int | Optional | The image capture frame rate this camera should use. <br> Default: `30` |
| `video_path` | string | Optional | The filepath to the input sensor of this camera on your board. If none is given, your robot will attempt to detect the video path automatically. <br> Default: `"0"` </br> |
| `flip_method` | string | Optional | The flip method this camera should use. See flip method options [here](https://gstreamer.freedesktop.org/documentation/videofilter/videoflip.html?gi-language=c#members). <br> Default: `none` |
| `debug` | boolean | Optional | Whether or not you want debug input from this camera in your robot's logs. <br> Default: `false` |

Once configured, check the [Logs tab](https://docs.viam.com/program/debug/) of your robot in the Viam app to make sure your camera has connected and no errors are being raised.
Expand Down
2 changes: 2 additions & 0 deletions constraints.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@
#define DEFAULT_VIDEO_CONVERTER "videoconvert"
#define DEFAULT_OUTPUT_ENCODER "nvjpegenc"
#define DEFAULT_OUTPUT_MIMETYPE "image/jpeg"
#define DEFAULT_FLIP "videoflip"
#define DEFAULT_FLIP_METHOD "none"

// Jetson
#define JETSON_API_SUBTYPE "csi"
Expand Down
6 changes: 4 additions & 2 deletions csi_camera.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ void CSICamera::validate_attrs(const AttributeMap attrs) {
set_attr<int>(attrs, "height_px", &CSICamera::height_px, DEFAULT_INPUT_HEIGHT);
set_attr<int>(attrs, "frame_rate", &CSICamera::frame_rate, DEFAULT_INPUT_FRAMERATE);
set_attr<std::string>(attrs, "video_path", &CSICamera::video_path, DEFAULT_INPUT_SENSOR);
set_attr<std::string>(attrs, "flip_method", &CSICamera::flip_method, DEFAULT_FLIP_METHOD);
set_attr<bool>(attrs, "debug", &CSICamera::debug, false);
}

Expand Down Expand Up @@ -299,8 +300,9 @@ std::string CSICamera::create_pipeline() const {
<< " ! " << device_params.input_format
<< ",width=" << std::to_string(width_px)
<< ",height=" << std::to_string(height_px)
<< ",framerate=" << std::to_string(frame_rate)
<< "/1 ! " << device_params.video_converter
<< ",framerate=" << std::to_string(frame_rate) << "/1"
<< " ! " << device_params.flipper << " method=" << flip_method
<< " ! " << device_params.video_converter
<< " ! " << device_params.output_encoder
<< " ! " << "image/jpeg"
<< " ! appsink name=appsink0 sync=false max-buffers=1 drop=true";
Expand Down
1 change: 1 addition & 0 deletions csi_camera.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ class CSICamera : public Camera {
int height_px = 0;
int frame_rate = 0;
std::string video_path;
std::string flip_method;

// GST
GstElement *pipeline = nullptr;
Expand Down
6 changes: 4 additions & 2 deletions utils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,14 +35,16 @@ device_params get_device_params(device_type device) {
.input_source = JETSON_INPUT_SOURCE,
.input_format = JETSON_INPUT_FORMAT,
.video_converter = JETSON_VIDEO_CONVERTER,
.output_encoder = JETSON_OUTPUT_ENCODER
.output_encoder = JETSON_OUTPUT_ENCODER,
.flipper = DEFAULT_FLIP
};
case device_type::pi:
return device_params {
.input_source = PI_INPUT_SOURCE,
.input_format = PI_INPUT_FORMAT,
.video_converter = PI_VIDEO_CONVERTER,
.output_encoder = PI_OUTPUT_ENCODER
.output_encoder = PI_OUTPUT_ENCODER,
.flipper = DEFAULT_FLIP
};
default:
return device_params {
Expand Down
2 changes: 2 additions & 0 deletions utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ struct device_params {
std::string input_format;
std::string video_converter;
std::string output_encoder;
std::string flipper;
std::string flip_method;
};

device_type get_device_type();
Expand Down

0 comments on commit ab11248

Please sign in to comment.