blob: dc383520a0f6452be6c118ed495b1bfbdce6f8aa [file] [log] [blame]
Jim Ostrowskiba2edd12022-12-03 15:44:37 -08001#include "frc971/vision/visualize_robot.h"
2
3#include "aos/init.h"
4#include "aos/logging/logging.h"
5#include "glog/logging.h"
6
7#include "Eigen/Dense"
8
9#include <math.h>
10#include <opencv2/aruco.hpp>
11#include <opencv2/aruco/charuco.hpp>
12#include <opencv2/calib3d.hpp>
13#include <opencv2/core/eigen.hpp>
14#include <opencv2/highgui/highgui.hpp>
15#include <opencv2/imgproc.hpp>
16#include "aos/time/time.h"
17
18namespace frc971 {
19namespace vision {
20
21// Show / test the basics of visualizing the robot frames
22void Main(int /*argc*/, char ** /* argv */) {
23 VisualizeRobot vis_robot;
24
25 int image_width = 500;
26 cv::Mat image_mat =
27 cv::Mat::zeros(cv::Size(image_width, image_width), CV_8UC3);
28 vis_robot.SetImage(image_mat);
29
30 // 10 meters above the origin, rotated so the camera faces straight down
31 Eigen::Translation3d camera_trans(0, 0, 10.0);
32 Eigen::AngleAxisd camera_rot(M_PI, Eigen::Vector3d::UnitX());
33 Eigen::Affine3d camera_viewpoint = camera_trans * camera_rot;
34 vis_robot.SetViewpoint(camera_viewpoint);
35
36 cv::Mat camera_mat;
37 double focal_length = 1000.0;
38 double intr[] = {focal_length, 0.0, image_width / 2.0,
39 0.0, focal_length, image_width / 2.0,
40 0.0, 0.0, 1.0};
41 camera_mat = cv::Mat(3, 3, CV_64FC1, intr);
42 vis_robot.SetCameraParameters(camera_mat);
43
44 Eigen::Affine3d offset_rotate_origin(Eigen::Affine3d::Identity());
45
46 cv::Mat dist_coeffs = cv::Mat(1, 5, CV_64F, 0.0);
47 vis_robot.SetDistortionCoefficients(dist_coeffs);
48
49 // Go around the clock and plot the coordinate frame at different rotations
50 for (int i = 0; i < 12; i++) {
51 double angle = M_PI * double(i) / 6.0;
52 Eigen::Vector3d trans;
53 trans << 1.0 * cos(angle), 1.0 * sin(angle), 0.0;
54
55 offset_rotate_origin = Eigen::Translation3d(trans) *
56 Eigen::AngleAxisd(angle, Eigen::Vector3d::UnitX());
57
58 vis_robot.DrawFrameAxes(offset_rotate_origin, std::to_string(i));
59 }
60
61 // Display the result
62 cv::imshow("Display", image_mat);
63 cv::waitKey();
64}
65} // namespace vision
66} // namespace frc971
67
68int main(int argc, char **argv) {
69 aos::InitGoogle(&argc, &argv);
70
71 frc971::vision::Main(argc, argv);
72}