Format code
Signed-off-by: Jacki <jacki@thejackimonster.de>
This commit is contained in:
parent
d2ba6cbdf6
commit
4fe426913c
1 changed files with 231 additions and 233 deletions
|
@ -1,18 +1,18 @@
|
||||||
|
|
||||||
#include <stdio.h>
|
|
||||||
#include <opencv2/opencv.hpp>
|
#include <opencv2/opencv.hpp>
|
||||||
#include <opencv2/videoio.hpp>
|
#include <opencv2/videoio.hpp>
|
||||||
|
#include <stdio.h>
|
||||||
|
|
||||||
const uint8_t chunk_map [128] = {
|
const uint8_t chunk_map[128] = {
|
||||||
119, 54, 21, 0, 108, 22, 51, 63, 93, 99, 67, 7, 32, 112, 52, 43,
|
119, 54, 21, 0, 108, 22, 51, 63, 93, 99, 67, 7, 32, 112, 52,
|
||||||
14, 35, 75, 116, 64, 71, 44, 89, 18, 88, 26, 61, 70, 56, 90, 79,
|
43, 14, 35, 75, 116, 64, 71, 44, 89, 18, 88, 26, 61, 70, 56,
|
||||||
87, 120, 81, 101, 121, 17, 72, 31, 53, 124, 127, 113, 111, 36, 48,
|
90, 79, 87, 120, 81, 101, 121, 17, 72, 31, 53, 124, 127, 113, 111,
|
||||||
19, 37, 83, 126, 74, 109, 5, 84, 41, 76, 30, 110, 29, 12, 115, 28,
|
36, 48, 19, 37, 83, 126, 74, 109, 5, 84, 41, 76, 30, 110, 29,
|
||||||
102, 105, 62, 103, 20, 3, 68, 49, 77, 117, 125, 106, 60, 69, 98, 9,
|
12, 115, 28, 102, 105, 62, 103, 20, 3, 68, 49, 77, 117, 125, 106,
|
||||||
16, 78, 47, 40, 2, 118, 34, 13, 50, 46, 80, 85, 66, 42, 123, 122,
|
60, 69, 98, 9, 16, 78, 47, 40, 2, 118, 34, 13, 50, 46, 80,
|
||||||
96, 11, 25, 97, 39, 6, 86, 1, 8, 82, 92, 59, 104, 24, 15, 73, 65,
|
85, 66, 42, 123, 122, 96, 11, 25, 97, 39, 6, 86, 1, 8, 82,
|
||||||
38, 58, 10, 23, 33, 55, 57, 107, 100, 94, 27, 95, 45, 91, 4, 114
|
92, 59, 104, 24, 15, 73, 65, 38, 58, 10, 23, 33, 55, 57, 107,
|
||||||
};
|
100, 94, 27, 95, 45, 91, 4, 114};
|
||||||
|
|
||||||
#define CHUNK_SIZE 2400
|
#define CHUNK_SIZE 2400
|
||||||
#define CHUNK_AMOUNT 128
|
#define CHUNK_AMOUNT 128
|
||||||
|
@ -43,7 +43,7 @@ const float s2 = -0.0003866048077984273F;
|
||||||
const float s3 = +0.007856725692160133F;
|
const float s3 = +0.007856725692160133F;
|
||||||
const float s4 = +0.0003370697673688772F;
|
const float s4 = +0.0003370697673688772F;
|
||||||
|
|
||||||
typedef cv::Point2f (*apply_variant_func) (float xn, float yn);
|
typedef cv::Point2f (*apply_variant_func)(float xn, float yn);
|
||||||
|
|
||||||
cv::Point2f apply_intrinsic_only(float xn, float yn) {
|
cv::Point2f apply_intrinsic_only(float xn, float yn) {
|
||||||
cv::Point2f p;
|
cv::Point2f p;
|
||||||
|
@ -71,15 +71,15 @@ cv::Point2f apply_radial_only(float xn, float yn) {
|
||||||
th = atanf(r);
|
th = atanf(r);
|
||||||
th_dist = th;
|
th_dist = th;
|
||||||
|
|
||||||
const float th2 = th*th;
|
const float th2 = th * th;
|
||||||
const float th3 = th*th*th;
|
const float th3 = th * th * th;
|
||||||
|
|
||||||
th_dist += k1 * th3;
|
th_dist += k1 * th3;
|
||||||
th_dist += k2 * th2 * th3;
|
th_dist += k2 * th2 * th3;
|
||||||
th_dist += k3 * th2*th2 * th3;
|
th_dist += k3 * th2 * th2 * th3;
|
||||||
th_dist += k4 * th3*th3 * th3;
|
th_dist += k4 * th3 * th3 * th3;
|
||||||
th_dist += k5 * th3*th3*th2 * th3;
|
th_dist += k5 * th3 * th3 * th2 * th3;
|
||||||
th_dist += k6 * th3*th3*th2*th2 * th3;
|
th_dist += k6 * th3 * th3 * th2 * th2 * th3;
|
||||||
|
|
||||||
xn = th_dist * cp;
|
xn = th_dist * cp;
|
||||||
yn = th_dist * sp;
|
yn = th_dist * sp;
|
||||||
|
@ -108,15 +108,15 @@ cv::Point2f apply_radial_tangential(float xn, float yn) {
|
||||||
th = atanf(r);
|
th = atanf(r);
|
||||||
th_dist = th;
|
th_dist = th;
|
||||||
|
|
||||||
const float th2 = th*th;
|
const float th2 = th * th;
|
||||||
const float th3 = th*th*th;
|
const float th3 = th * th * th;
|
||||||
|
|
||||||
th_dist += k1 * th3;
|
th_dist += k1 * th3;
|
||||||
th_dist += k2 * th2 * th3;
|
th_dist += k2 * th2 * th3;
|
||||||
th_dist += k3 * th2*th2 * th3;
|
th_dist += k3 * th2 * th2 * th3;
|
||||||
th_dist += k4 * th3*th3 * th3;
|
th_dist += k4 * th3 * th3 * th3;
|
||||||
th_dist += k5 * th3*th3*th2 * th3;
|
th_dist += k5 * th3 * th3 * th2 * th3;
|
||||||
th_dist += k6 * th3*th3*th2*th2 * th3;
|
th_dist += k6 * th3 * th3 * th2 * th2 * th3;
|
||||||
|
|
||||||
xn = th_dist * cp;
|
xn = th_dist * cp;
|
||||||
yn = th_dist * sp;
|
yn = th_dist * sp;
|
||||||
|
@ -153,17 +153,17 @@ cv::Point2f apply_fisheye624(float xn, float yn) {
|
||||||
th = atanf(r);
|
th = atanf(r);
|
||||||
th_dist = th;
|
th_dist = th;
|
||||||
|
|
||||||
const float th2 = th*th;
|
const float th2 = th * th;
|
||||||
const float th3 = th*th*th;
|
const float th3 = th * th * th;
|
||||||
const float th5 = th3*th2;
|
const float th5 = th3 * th2;
|
||||||
const float th6 = th3*th3;
|
const float th6 = th3 * th3;
|
||||||
|
|
||||||
th_dist += k1 * th3;
|
th_dist += k1 * th3;
|
||||||
th_dist += k2 * th5;
|
th_dist += k2 * th5;
|
||||||
th_dist += k3 * th5*th2;
|
th_dist += k3 * th5 * th2;
|
||||||
th_dist += k4 * th6*th3;
|
th_dist += k4 * th6 * th3;
|
||||||
th_dist += k5 * th6*th5;
|
th_dist += k5 * th6 * th5;
|
||||||
th_dist += k6 * th6*th5*th2;
|
th_dist += k6 * th6 * th5 * th2;
|
||||||
|
|
||||||
xn = th_dist * cp;
|
xn = th_dist * cp;
|
||||||
yn = th_dist * sp;
|
yn = th_dist * sp;
|
||||||
|
@ -185,7 +185,8 @@ cv::Point2f apply_fisheye624(float xn, float yn) {
|
||||||
return p;
|
return p;
|
||||||
}
|
}
|
||||||
|
|
||||||
cv::Mat build_maps_variant(apply_variant_func func, uint32_t width, uint32_t height) {
|
cv::Mat build_maps_variant(apply_variant_func func, uint32_t width,
|
||||||
|
uint32_t height) {
|
||||||
cv::Mat map = cv::Mat(cv::Size(height, width), CV_16SC2);
|
cv::Mat map = cv::Mat(cv::Size(height, width), CV_16SC2);
|
||||||
cv::Point2f p;
|
cv::Point2f p;
|
||||||
cv::Vec2s v;
|
cv::Vec2s v;
|
||||||
|
@ -208,7 +209,7 @@ cv::Mat build_maps_variant(apply_variant_func func, uint32_t width, uint32_t hei
|
||||||
return map;
|
return map;
|
||||||
}
|
}
|
||||||
|
|
||||||
void remap(const cv::Mat& input, cv::Mat& output, const cv::Mat& map) {
|
void remap(const cv::Mat &input, cv::Mat &output, const cv::Mat &map) {
|
||||||
cv::Vec2s v;
|
cv::Vec2s v;
|
||||||
size_t x, y;
|
size_t x, y;
|
||||||
|
|
||||||
|
@ -221,17 +222,13 @@ void remap(const cv::Mat& input, cv::Mat& output, const cv::Mat& map) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
int main(int argc, const char** argv) {
|
int main(int argc, const char **argv) {
|
||||||
cv::VideoCapture cap;
|
cv::VideoCapture cap;
|
||||||
cv::Mat frame;
|
cv::Mat frame;
|
||||||
|
|
||||||
cv::Ptr<cv::StereoBM> stereo = cv::StereoBM::create(16, 15);
|
cv::Ptr<cv::StereoBM> stereo = nullptr; // cv::StereoBM::create(16, 15);
|
||||||
|
|
||||||
if (!stereo) {
|
cap.open(0, cv::CAP_V4L2);
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
cap.open(4, cv::CAP_V4L2);
|
|
||||||
if (!cap.isOpened()) {
|
if (!cap.isOpened()) {
|
||||||
return 2;
|
return 2;
|
||||||
}
|
}
|
||||||
|
@ -243,7 +240,8 @@ int main(int argc, const char** argv) {
|
||||||
cv::Mat left = cv::Mat(cv::Size(CAM_HEIGHT, CAM_WIDTH), CV_8UC1);
|
cv::Mat left = cv::Mat(cv::Size(CAM_HEIGHT, CAM_WIDTH), CV_8UC1);
|
||||||
cv::Mat right = cv::Mat(cv::Size(CAM_HEIGHT, CAM_WIDTH), CV_8UC1);
|
cv::Mat right = cv::Mat(cv::Size(CAM_HEIGHT, CAM_WIDTH), CV_8UC1);
|
||||||
|
|
||||||
cv::Mat map_fisheye624 = build_maps_variant(apply_fisheye624, CAM_WIDTH, CAM_HEIGHT);
|
cv::Mat map_fisheye624 =
|
||||||
|
build_maps_variant(apply_fisheye624, CAM_WIDTH, CAM_HEIGHT);
|
||||||
|
|
||||||
cv::Mat undist_left = cv::Mat(left.size(), left.type());
|
cv::Mat undist_left = cv::Mat(left.size(), left.type());
|
||||||
cv::Mat undist_right = cv::Mat(right.size(), right.type());
|
cv::Mat undist_right = cv::Mat(right.size(), right.type());
|
||||||
|
@ -258,15 +256,15 @@ int main(int argc, const char** argv) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
uint8_t* blocks = frame.ptr();
|
uint8_t *blocks = frame.ptr();
|
||||||
uint8_t* data = img.ptr();
|
uint8_t *data = img.ptr();
|
||||||
|
|
||||||
const uint8_t* header = blocks + CAM_IMAGE_DATA_SIZE;
|
const uint8_t *header = blocks + CAM_IMAGE_DATA_SIZE;
|
||||||
|
|
||||||
uint64_t t_ns = *((const uint64_t*) (header + 0x00));
|
uint64_t t_ns = *((const uint64_t *)(header + 0x00));
|
||||||
uint64_t t_ms = *((const uint64_t*) (header + 0x3E));
|
uint64_t t_ms = *((const uint64_t *)(header + 0x3E));
|
||||||
|
|
||||||
uint16_t seq = *((const uint16_t*) (header + 0x12));
|
uint16_t seq = *((const uint16_t *)(header + 0x12));
|
||||||
uint8_t is_right = *(header + 0x3B);
|
uint8_t is_right = *(header + 0x3B);
|
||||||
|
|
||||||
size_t offset = 0;
|
size_t offset = 0;
|
||||||
|
@ -309,7 +307,7 @@ int main(int argc, const char** argv) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
//cv::remap(left, undist, map_intrinsic, cv::noArray(), cv::INTER_LINEAR);
|
// cv::remap(left, undist, map_intrinsic, cv::noArray(), cv::INTER_LINEAR);
|
||||||
remap(left, undist_left, map_fisheye624);
|
remap(left, undist_left, map_fisheye624);
|
||||||
remap(right, undist_right, map_fisheye624);
|
remap(right, undist_right, map_fisheye624);
|
||||||
|
|
||||||
|
|
Reference in a new issue