23 #include <opencv2/core/core.hpp>
24 #include <opencv2/imgproc/imgproc.hpp>
25 #include <opencv2/imgproc/types_c.h>
26 #include <opencv2/imgcodecs/imgcodecs.hpp>
27 #include <opencv2/calib3d/calib3d.hpp>
46 for (
int i = 0; i < (from->rows * from->cols); i++) {
47 ((img_dip_type *)to->
buf)[i] = from->at<img_dip_type>
54 for (
int i = 0; i < (from->rows * from->cols); i++) {
55 ((img_dip_type *)to->
buf)[i] = from->at<img_dip_type>
74 Mat M(img->
h, img->
w, CV_16SC1, img->
buf);
75 Mat Mcopy = M.clone();
77 imwrite(myString, Mcopy);
80 Mat M(img->
h, img->
w, CV_8UC1, img->
buf);
81 Mat Mcopy = M.clone();
83 imwrite(myString, Mcopy);
85 std::cout <<
"This function only worked with images of type IMAGE_GRAYSCALE and IAMGE_OPENCV_DISP. Leaving function." <<
97 Mat M(img->
h, img->
w, CV_8UC2, img->
buf);
102 cvtColor(M, image, CV_YUV2GRAY_Y422);
103 imwrite(myString, image);
139 Mat M(img->
h, img->
w, CV_16SC1, img->
buf);
140 Mat Mcopy = M.clone();
143 Mcopy.convertTo(Mcopy, CV_8UC1);
144 applyColorMap(Mcopy, Mcopy, heatmap);
146 imwrite(myString, Mcopy);
149 Mat M(img->
h, img->
w, CV_8UC1, img->
buf);
150 Mat Mcopy = M.clone();
152 applyColorMap(Mcopy, Mcopy, heatmap);
154 imwrite(myString, Mcopy);
156 std::cout <<
"This function only worked with images of type IMAGE_GRAYSCALE and IAMGE_OPENCV_DISP. Leaving function." <<
169 const int ndisparities,
const int SADWindowSize,
const bool cropped)
185 Ptr<StereoBM> sbm = StereoBM::create(ndisparities, SADWindowSize);
186 sbm->compute(img_left_OCV, img_right_OCV, img_disp_OCV);
197 for (
int i = 0; i < (img_disp_OCV.rows * img_disp_OCV.cols); i++) {
198 ((img_dip_type *)img_disp->
buf)[i] = img_disp_OCV.at<img_dip_type>
201 }
else if (cropped == 1) {
208 Mat img_cropped = img_disp_OCV(crop_area);
210 for (
int i = 0; i < (img_cropped.rows * img_cropped.cols); i++) {
211 ((img_dip_type *)img_disp->
buf)[i] = img_cropped.at<img_dip_type>
231 img_disp_OCV = img_disp_OCV / 16;
232 img_disp_OCV.convertTo(img_disp_OCV, CV_8UC1);
238 for (
int i = 0; i < (img_disp_OCV.rows * img_disp_OCV.cols); i++) {
239 ((img_dip_type *)img_disp->
buf)[i] = img_disp_OCV.data[i];
241 }
else if (cropped == 1) {
250 Mat img_cropped = img_disp_OCV(crop_area);
257 for (
int i = 0; i < (img_cropped.rows * img_cropped.cols); i++) {
258 ((img_dip_type *)img_disp->
buf)[i] = img_cropped.at<img_dip_type>
268 std::cout <<
"This function only worked with images of type IMAGE_GRAYSCALE and IAMGE_OPENCV_DISP. Leaving function." <<
281 Mat kernel = getStructuringElement(MORPH_RECT, Size(SE_size, SE_size));
284 img_input_OCV = Mat(img_input->
h, img_input->
w, CV_16S, img_input->
buf);
286 img_input_OCV = Mat(img_input->
h, img_input->
w, CV_8UC1, img_input->
buf);
288 std::cout <<
"This function only worked with images of type IMAGE_GRAYSCALE and IAMGE_OPENCV_DISP. Leaving function." <<
294 morphologyEx(img_input_OCV, img_output_OCV, CV_MOP_OPEN, kernel, Point(-1, -1), iteration);
296 transfer(&img_output_OCV, img_output);
308 Mat kernel = getStructuringElement(MORPH_RECT, Size(SE_size, SE_size));
311 img_input_OCV = Mat(img_input->
h, img_input->
w, CV_16S, img_input->
buf);
314 img_input_OCV = Mat(img_input->
h, img_input->
w, CV_8UC1, img_input->
buf);
316 std::cout <<
"This function only worked with images of type IMAGE_GRAYSCALE and IAMGE_OPENCV_DISP. Leaving function." <<
322 morphologyEx(img_input_OCV, img_output_OCV, CV_MOP_CLOSE, kernel, Point(-1, -1), iteration);
324 transfer(&img_output_OCV, img_output);
334 Mat kernel = getStructuringElement(MORPH_RECT, Size(SE_size, SE_size));
337 img_input_OCV = Mat(img_input->
h, img_input->
w, CV_16S, img_input->
buf);
340 img_input_OCV = Mat(img_input->
h, img_input->
w, CV_8UC1, img_input->
buf);
342 std::cout <<
"This function only worked with images of type IMAGE_GRAYSCALE and IAMGE_OPENCV_DISP. Leaving function." <<
347 dilate(img_input_OCV, img_output_OCV, kernel, Point(-1, -1), iteration);
349 transfer(&img_output_OCV, img_output);
359 Mat kernel = getStructuringElement(MORPH_RECT, Size(SE_size, SE_size));
362 img_input_OCV = Mat(img_input->
h, img_input->
w, CV_16S, img_input->
buf);
365 img_input_OCV = Mat(img_input->
h, img_input->
w, CV_8UC1, img_input->
buf);
367 std::cout <<
"This function only worked with images of type IMAGE_GRAYSCALE and IAMGE_OPENCV_DISP. Leaving function." <<
372 erode(img_input_OCV, img_output_OCV, kernel, Point(-1, -1), iteration);
374 transfer(&img_output_OCV, img_output);
384 Mat img_grad_x, img_grad_y, img_grad_mag;
392 img_input_OCV = Mat(img_input->
h, img_input->
w, CV_16S, img_input->
buf);
393 Sobel(img_input_OCV, img_grad_x, ddepth, 1, 0, kernel_size,
scale, delta, BORDER_DEFAULT);
395 Sobel(img_input_OCV, img_grad_y, ddepth, 0, 1, kernel_size,
scale, delta, BORDER_DEFAULT);
397 magnitude(img_grad_x, img_grad_y, img_grad_mag);
400 threshold(img_grad_mag, img_grad_mag, thr, 127, THRESH_BINARY);
403 img_input_OCV = Mat(img_input->
h, img_input->
w, CV_8UC1, img_input->
buf);
404 Sobel(img_input_OCV, img_grad_x, ddepth, 1, 0, kernel_size,
scale, delta, BORDER_DEFAULT);
406 Sobel(img_input_OCV, img_grad_y, ddepth, 0, 1, kernel_size,
scale, delta, BORDER_DEFAULT);
408 magnitude(img_grad_x, img_grad_y, img_grad_mag);
410 threshold(img_grad_mag, img_grad_mag, thr, 127, THRESH_BINARY);
412 std::cout <<
"This function only worked with images of type IMAGE_GRAYSCALE and IAMGE_OPENCV_DISP. Leaving function." <<
421 img_grad_mag.convertTo(img_grad_mag, CV_8UC1);
423 transfer(&img_grad_mag, img_output);
425 Mat(img_output->
h, img_output->
w, CV_8UC1, img_output->
buf);
static const float scale[]
uint16_t h
height of the cropped area
uint16_t w
Width of the cropped area.
void * buf
Image buffer (depending on the image_type)
uint16_t x
Start position x (horizontal)
uint16_t y
Start position y (vertical)
enum image_type type
The image type.
@ IMAGE_GRAYSCALE
Grayscale image with only the Y part (uint8 per pixel)
@ IMAGE_INT16
An image to hold disparity image data from openCV (int16 per pixel)
unsigned short uint16_t
Typedef defining 16 bit unsigned short type.
short int16_t
Typedef defining 16 bit short type.
unsigned char uint8_t
Typedef defining 8 bit unsigned char type.
struct crop_t img_cropped_info
struct image_t img_right
Image obtained from left camera (UYVY format)
void post_disparity_crop_rect(struct crop_t *_img_cropped_info, struct img_size_t *_original_img_dims, const int disp_n, const int block_size)
int SBM_OCV(struct image_t *img_disp, const struct image_t *img_left, const struct image_t *img_right, const int ndisparities, const int SADWindowSize, const bool cropped)
int closing_OCV(struct image_t *img_input, const struct image_t *img_output, const int SE_size, const int iteration)
int sobel_OCV(struct image_t *img_input, const struct image_t *img_output, const int kernel_size, const int thr)
int save_image_gray(struct image_t *img, char *myString)
int dilation_OCV(struct image_t *img_input, const struct image_t *img_output, const int SE_size, const int iteration)
int transfer(const Mat *from, const image_t *to)
int save_image_color(struct image_t *img, char *myString)
int erosion_OCV(struct image_t *img_input, const struct image_t *img_output, const int SE_size, const int iteration)
int opening_OCV(struct image_t *img_input, const struct image_t *img_output, const int SE_size, const int iteration)
int save_image_HM(struct image_t *img, char *myString, int const heatmap)