Skip to content

Commit

Permalink
Lint fix
Browse files Browse the repository at this point in the history
Signed-off-by: Wendell Hom <whom@nvidia.com>
  • Loading branch information
whom3 committed Jan 23, 2025
1 parent dc3d632 commit 1bc9233
Show file tree
Hide file tree
Showing 9 changed files with 98 additions and 89 deletions.
2 changes: 1 addition & 1 deletion applications/stereo_vision/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ using. This can be found using `v4l2-ctl --list-devices`.

## Models

This demo requires the ESS DNN Stereo Disparity availible from the NGC catalog for disparity and the
This demo requires the ESS DNN Stereo Disparity available from the NGC catalog for disparity and the
YOLOv8 onnx model for object detection. Both models are downloaded when you build the application.

### ESS DNN
Expand Down
4 changes: 2 additions & 2 deletions applications/stereo_vision/cpp/crop.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,14 +53,14 @@ void CropOp::compute(InputContext& op_input, OutputContext& op_output, Execution
int element_size = nvidia::gxf::PrimitiveTypeSize(data_type);

if (x_ < 0 || y_ < 0 || width_ <= 0 || height_ <= 0) {
throw std::runtime_error("Invalide crop dimensions");
throw std::runtime_error("Invalid crop dimensions");
}

if ((x_ + width_) > orig_width || (y_ + height_) > orig_height) {
std::cout << "orig_width " << orig_width << std::endl;
std::cout << "orig_height " << orig_height << std::endl;
std::cout << "nChannels " << nChannels << std::endl;
throw std::runtime_error("Crop exceeds image boundries");
throw std::runtime_error("Crop exceeds image boundaries");
}

auto pointer = std::shared_ptr<void*>(new void*, [](void** pointer) {
Expand Down
26 changes: 13 additions & 13 deletions applications/stereo_vision/cpp/crop.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,18 +24,18 @@

namespace holoscan::ops {

class CropOp : public Operator{
public:
HOLOSCAN_OPERATOR_FORWARD_ARGS(CropOp);
CropOp() = default;
void setup(OperatorSpec& spec) override;
void compute(InputContext&, OutputContext& op_output, ExecutionContext&) override;
private:
Parameter<int> x_;
Parameter<int> y_;
Parameter<int> width_;
Parameter<int> height_;
};
class CropOp : public Operator{
public:
HOLOSCAN_OPERATOR_FORWARD_ARGS(CropOp);
CropOp() = default;
void setup(OperatorSpec& spec) override;
void compute(InputContext&, OutputContext& op_output, ExecutionContext&) override;
private:
Parameter<int> x_;
Parameter<int> y_;
Parameter<int> width_;
Parameter<int> height_;
};

}
} // namespace holoscan::ops
#endif
2 changes: 1 addition & 1 deletion applications/stereo_vision/cpp/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ class StereoDepthApp : public holoscan::Application {
std::string stereo_calibration_;

public:
StereoDepthApp(std::string file) : stereo_calibration_(file) {};
explicit StereoDepthApp(std::string file) : stereo_calibration_(file) {}
void compose() override {
using namespace holoscan;
YAML::Node calibration = YAML::LoadFile(stereo_calibration_);
Expand Down
4 changes: 2 additions & 2 deletions applications/stereo_vision/cpp/split_video.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ void SplitVideoOp::setup(OperatorSpec& spec) {
spec.param(stereo_video_layout_,
"stereo_video_layout",
"Stereo Video Layout",
"Horizontal or Vertical Concatination of Stereo Video Frames",
"Horizontal or Vertical Concatenation of Stereo Video Frames",
STEREO_VIDEO_HORIZONTAL);
}

Expand Down Expand Up @@ -142,7 +142,7 @@ void MergeVideoOp::setup(OperatorSpec& spec) {
spec.param(stereo_video_layout_,
"stereo_video_layout",
"Stereo Video Layout",
"Horizontal or Vertical Concatination of Stereo Video Frames",
"Horizontal or Vertical Concatenation of Stereo Video Frames",
STEREO_VIDEO_HORIZONTAL);
}

Expand Down
2 changes: 1 addition & 1 deletion applications/stereo_vision/cpp/tracking_postprocessor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ void TrackingPostprocessor::compute(InputContext& op_input, OutputContext& op_ou
int scores_N = detection_boxes->shape()[1];

if (!(boxes_batch == 1 && scores_batch == 1 && boxes_N == scores_N && boxes_coord == 4)) {
throw std::runtime_error("Wrong input dimentions for yolo input");
throw std::runtime_error("Wrong input dimensions for yolo input");
}

auto maybe_tensormap = op_input.receive<holoscan::TensorMap>("image");
Expand Down
2 changes: 1 addition & 1 deletion applications/stereo_vision/cpp/tracking_postprocessor.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ class TrackingPostprocessor : public Operator {
void setup(OperatorSpec& spec) override;
void compute(InputContext&, OutputContext& op_output, ExecutionContext&) override;

private:
private:
Parameter<float> score_threshold_;
Parameter<int> bb_width_;
Parameter<int> bb_height_;
Expand Down
4 changes: 2 additions & 2 deletions applications/stereo_vision/cpp/undistort_rectify.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ class UndistortRectifyOp : public Operator {
public:
class RectificationMap {
public:
RectificationMap() {};
RectificationMap() {}
RectificationMap(float* M, float* d, float* R, float* P, int width, int height);
~RectificationMap();
void setParameters(float* M, float* d, float* R, float* P, int width, int height);
Expand All @@ -55,7 +55,7 @@ class UndistortRectifyOp : public Operator {
void compute(InputContext&, OutputContext& op_output, ExecutionContext&) override;
void setRectificationMap(std::shared_ptr<RectificationMap> rectification_map) {
rectification_map_ = rectification_map;
};
}

private:
std::shared_ptr<RectificationMap> rectification_map_;
Expand Down
141 changes: 75 additions & 66 deletions applications/stereo_vision/scripts/get_zed_calibration.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,105 +13,114 @@
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
"""
"""

import os
import argparse
import configparser
import os

import numpy as np
from scipy.spatial.transform import Rotation
import yaml
from scipy.spatial.transform import Rotation

rez = "FHD"
calibration_file = "calibration.yaml"

parser = argparse.ArgumentParser(description='Get factory ZED calibration')
required = parser.add_argument_group('required arguments')
required.add_argument('-s','--serial_number', help='serial number of the ZED camera', required=True)
required.add_argument('-o','--output', help='output calibration file (default: stereo_calibration.yaml)', default="stereo_calibration.yaml")
required.add_argument('-r','--resoution', help='resolution setting (default: FHD)', default="FHD")
parser = argparse.ArgumentParser(description="Get factory ZED calibration")
required = parser.add_argument_group("required arguments")
required.add_argument(
"-s", "--serial_number", help="serial number of the ZED camera", required=True
)
required.add_argument(
"-o",
"--output",
help="output calibration file (default: stereo_calibration.yaml)",
default="stereo_calibration.yaml",
)
required.add_argument("-r", "--resolution", help="resolution setting (default: FHD)", default="FHD")
args = parser.parse_args()

serial_number=args.serial_number
rez = args.resoution
serial_number = args.serial_number
rez = args.resolution
calibration_file = args.output
if rez == "2K":
width = 2208
height = 1242
width = 2208
height = 1242
elif rez == "FHD":
width = 1920
height = 1080
width = 1920
height = 1080
elif rez == "HD":
width = 1280
height = 720
width = 1280
height = 720
elif rez == "VGA":
width = 672
height = 376
width = 672
height = 376
else:
raise NameError("resolution not supported")
raise NameError("resolution not supported")


tmp_file = str(serial_number)+".tmp"
url = "http://calib.stereolabs.com/?SN="+str(serial_number)
os.system("wget -O"+ tmp_file +" "+url)
tmp_file = str(serial_number) + ".tmp"
url = "http://calib.stereolabs.com/?SN=" + str(serial_number)
os.system("wget -O" + tmp_file + " " + url)

calib = configparser.ConfigParser()
calib.read(tmp_file)
M1 = np.zeros([3,3])
M1[0,0]=calib['LEFT_CAM_'+rez]['fx']
M1[0,2]=calib['LEFT_CAM_'+rez]['cx']
M1[1,1]=calib['LEFT_CAM_'+rez]['fy']
M1[1,2]=calib['LEFT_CAM_'+rez]['cy']
M1[2,2] = 1.0
M1 = np.zeros([3, 3])
M1[0, 0] = calib["LEFT_CAM_" + rez]["fx"]
M1[0, 2] = calib["LEFT_CAM_" + rez]["cx"]
M1[1, 1] = calib["LEFT_CAM_" + rez]["fy"]
M1[1, 2] = calib["LEFT_CAM_" + rez]["cy"]
M1[2, 2] = 1.0

d1 = np.zeros(5)
d1[0] = calib['LEFT_CAM_'+rez]['k1']
d1[1] = calib['LEFT_CAM_'+rez]['k2']
d1[2] = calib['LEFT_CAM_'+rez]['p1']
d1[3] = calib['LEFT_CAM_'+rez]['p2']
d1[4] = calib['LEFT_CAM_'+rez]['k3']

M2 = np.zeros([3,3])
M2[0,0]=calib['RIGHT_CAM_'+rez]['fx']
M2[0,2]=calib['RIGHT_CAM_'+rez]['cx']
M2[1,1]=calib['RIGHT_CAM_'+rez]['fy']
M2[1,2]=calib['RIGHT_CAM_'+rez]['cy']
M2[2,2]=1.0
d1[0] = calib["LEFT_CAM_" + rez]["k1"]
d1[1] = calib["LEFT_CAM_" + rez]["k2"]
d1[2] = calib["LEFT_CAM_" + rez]["p1"]
d1[3] = calib["LEFT_CAM_" + rez]["p2"]
d1[4] = calib["LEFT_CAM_" + rez]["k3"]

M2 = np.zeros([3, 3])
M2[0, 0] = calib["RIGHT_CAM_" + rez]["fx"]
M2[0, 2] = calib["RIGHT_CAM_" + rez]["cx"]
M2[1, 1] = calib["RIGHT_CAM_" + rez]["fy"]
M2[1, 2] = calib["RIGHT_CAM_" + rez]["cy"]
M2[2, 2] = 1.0

d2 = np.zeros(5)
d2[0] = calib['RIGHT_CAM_'+rez]['k1']
d2[1] = calib['RIGHT_CAM_'+rez]['k2']
d2[2] = calib['RIGHT_CAM_'+rez]['p1']
d2[3] = calib['RIGHT_CAM_'+rez]['p2']
d2[4] = calib['RIGHT_CAM_'+rez]['k3']
d2[0] = calib["RIGHT_CAM_" + rez]["k1"]
d2[1] = calib["RIGHT_CAM_" + rez]["k2"]
d2[2] = calib["RIGHT_CAM_" + rez]["p1"]
d2[3] = calib["RIGHT_CAM_" + rez]["p2"]
d2[4] = calib["RIGHT_CAM_" + rez]["k3"]

t = np.zeros(3)
t[0] = -float(calib['STEREO']['Baseline'])
t[1] = calib['STEREO']['TY']
t[2] = calib['STEREO']['TZ']
t[0] = -float(calib["STEREO"]["Baseline"])
t[1] = calib["STEREO"]["TY"]
t[2] = calib["STEREO"]["TZ"]

r = np.zeros(3)
r[0] = calib['STEREO']["RX_"+rez]
r[1] = calib['STEREO']["CV_"+rez]
r[2] = calib['STEREO']["RZ_"+rez]
r[0] = calib["STEREO"]["RX_" + rez]
r[1] = calib["STEREO"]["CV_" + rez]
r[2] = calib["STEREO"]["RZ_" + rez]
R = Rotation.from_rotvec(r).as_matrix()

calibration = dict(
SN = serial_number,
M1 = str(M1.flatten().tolist()),
d1 = str(d1.tolist()),
M2 = str(M2.flatten().tolist()),
d2 = str(d2.tolist()),
t = str(t.tolist()),
R = str(R.flatten().tolist()),
width = width,
height = height
calibration = dict(
SN=serial_number,
M1=str(M1.flatten().tolist()),
d1=str(d1.tolist()),
M2=str(M2.flatten().tolist()),
d2=str(d2.tolist()),
t=str(t.tolist()),
R=str(R.flatten().tolist()),
width=width,
height=height,
)

output_yaml = yaml.dump(calibration, default_style=None, default_flow_style=False, sort_keys=False).replace("'","")
output_yaml = yaml.dump(
calibration, default_style=None, default_flow_style=False, sort_keys=False
).replace("'", "")
print("Writing calibration to: " + calibration_file)
with open(calibration_file,'w') as f:
f.write(output_yaml)

os.system("rm "+tmp_file)
with open(calibration_file, "w") as f:
f.write(output_yaml)

os.system("rm " + tmp_file)

0 comments on commit 1bc9233

Please sign in to comment.