Skip to content

Commit 253acb6

Browse files
author
C.V. Enthusiast
committed
Source codes for Jetson screencasts
Author: C.V. Enthusiast <[email protected]>
0 parents  commit 253acb6

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

84 files changed

+1153
-0
lines changed

0-cv-hello/CMakeLists.txt

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
cmake_minimum_required(VERSION 2.8)
2+
3+
project(cv_hello)
4+
5+
find_package(OpenCV REQUIRED)
6+
7+
include_directories(${OpenCV_INCLUDE_DIRS})
8+
9+
add_executable(cv_hello hello.cpp)
10+
11+
target_link_libraries(cv_hello ${OpenCV_LIBS})

0-cv-hello/hello.cpp

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
#include <opencv2/highgui/highgui.hpp>
2+
#include <iostream>
3+
4+
int main()
5+
{
6+
cv::Mat img(512, 512, CV_8UC3, cv::Scalar(0));
7+
8+
std::cout << img.data << std::endl;
9+
10+
cv::putText(img,
11+
"Hello, OpenCV on Jetson!",
12+
cv::Point(10, img.rows / 2),
13+
cv::FONT_HERSHEY_DUPLEX,
14+
1.0,
15+
CV_RGB(118, 185, 0),
16+
2);
17+
18+
cv::imshow("Hello!", img);
19+
cv::waitKey();
20+
}

1-cv-mat/CMakeLists.txt

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
cmake_minimum_required(VERSION 2.8)
2+
3+
project(cv_mat)
4+
5+
find_package(OpenCV REQUIRED)
6+
7+
include_directories(${OpenCV_INCLUDE_DIRS})
8+
9+
add_executable(cv_mat mat.cpp)
10+
11+
target_link_libraries(cv_mat ${OpenCV_LIBS})

1-cv-mat/mat.cpp

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
#include <opencv2/core/core.hpp>
2+
#include <opencv2/imgproc/imgproc.hpp>
3+
#include <opencv2/highgui/highgui.hpp>
4+
5+
int main()
6+
{
7+
cv::Mat image0;
8+
9+
image0.create(480, 640, CV_8UC1);
10+
image0.setTo(0);
11+
12+
cv::Point center(image0.cols / 2, image0.rows / 2);
13+
int radius = image0.rows / 2;
14+
15+
cv::circle(image0,
16+
center,
17+
radius,
18+
128,
19+
3);
20+
21+
cv::Mat image1 = image0;
22+
23+
cv::rectangle(image1,
24+
center - cv::Point(radius, radius),
25+
center + cv::Point(radius, radius),
26+
255,
27+
3);
28+
29+
cv::Mat image2;
30+
cv::cvtColor(image1, image2, CV_GRAY2BGR);
31+
32+
int inscribed_radius = radius / sqrt(2);
33+
cv::Rect rect(center - cv::Point(inscribed_radius, inscribed_radius),
34+
center + cv::Point(inscribed_radius, inscribed_radius));
35+
cv::Mat roi = image2(rect);
36+
roi.setTo(cv::Scalar(0, 185, 118));
37+
38+
for (int y = 0; y < image1.rows; y++)
39+
{
40+
uchar *row = image1.ptr<uchar>(y);
41+
for (int x = 0; x < image1.cols; x++)
42+
{
43+
if (row[x] == 128)
44+
row[x] = x * y * 255 / image1.total();
45+
}
46+
}
47+
48+
for (int y = 0; y < image2.rows; y++)
49+
{
50+
cv::Vec3b *row = image2.ptr<cv::Vec3b>(y);
51+
for (int x = 0; x < image2.cols; x++)
52+
{
53+
if (row[x][1] == 185)
54+
row[x] = cv::Vec3b(0, x * y * 255 / image1.total(), 118);
55+
}
56+
}
57+
58+
cv::imshow("image0", image0);
59+
cv::imshow("image1", image1);
60+
cv::imshow("image2", image2);
61+
cv::waitKey();
62+
}

10-cv-stereo/CMakeLists.txt

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
cmake_minimum_required(VERSION 2.8)
2+
3+
project(cv_stereo)
4+
5+
find_package(OpenCV REQUIRED)
6+
7+
include_directories(${OpenCV_INCLUDE_DIRS})
8+
9+
add_executable(cv_stereo stereo.cpp)
10+
11+
target_link_libraries(cv_stereo ${OpenCV_LIBS})

10-cv-stereo/left_right.mp4

10.2 MB
Binary file not shown.

10-cv-stereo/stereo.cpp

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
#include "opencv2/objdetect/objdetect.hpp"
2+
#include "opencv2/highgui/highgui.hpp"
3+
#include "opencv2/imgproc/imgproc.hpp"
4+
#include "opencv2/calib3d/calib3d.hpp"
5+
#include <iostream>
6+
7+
int main()
8+
{
9+
cv::Mat left_right, left, right;
10+
cv::Mat left_gray, right_gray;
11+
12+
cv::StereoBM bm(cv::StereoBM::BASIC_PRESET, 64);
13+
cv::Mat disparity;
14+
15+
cv::Matx33f P(573.835, 0, 306,
16+
0, 573.835, 256,
17+
0, 0, 1);
18+
float baseline = 0.18;
19+
20+
cv::VideoCapture left_right_video("left_right.mp4");
21+
22+
for (;;)
23+
{
24+
if (!left_right_video.read(left_right))
25+
break;
26+
27+
left = left_right(cv::Rect(0, 0, left_right.cols / 2, left_right.rows));
28+
right = left_right(cv::Rect(left_right.cols / 2, 0, left_right.cols / 2, left_right.rows));
29+
30+
cv::cvtColor(left, left_gray, CV_BGR2GRAY);
31+
cv::cvtColor(right, right_gray, CV_BGR2GRAY);
32+
33+
bm(left_gray, right_gray, disparity, CV_32F);
34+
35+
for (int y = 0; y < left.rows; y++)
36+
{
37+
for (int x = 0; x < left.cols; x++)
38+
{
39+
float d = disparity.ptr<float>(y)[x];
40+
float distance = P(0, 0) * baseline / d;
41+
42+
cv::Vec3f point_3d = P.inv() * cv::Vec3f(x, y, 1) * distance;
43+
44+
if (d > 0 && std::abs(point_3d[1] - 0.4) < 0.2)
45+
{
46+
float safe_distance = 30;
47+
float alpha = distance / (float)safe_distance;
48+
left.ptr<cv::Vec3b>(y)[x] =
49+
(1 - alpha) * cv::Vec3b(0, 0, 255) +
50+
alpha * cv::Vec3b(0, 255, 0);
51+
}
52+
}
53+
}
54+
55+
cv::imshow("disparity", disparity / 64);
56+
cv::imshow("left", left);
57+
char c = cv::waitKey(1);
58+
if (c == 27) // 27 is ESC code
59+
break;
60+
}
61+
}

11-cv-perf/CMakeLists.txt

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
cmake_minimum_required(VERSION 2.8)
2+
3+
project(cv_perf)
4+
5+
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")
6+
7+
find_package(OpenCV REQUIRED)
8+
9+
include_directories(${OpenCV_INCLUDE_DIRS})
10+
11+
add_executable(cv_perf perf.cpp)
12+
13+
target_link_libraries(cv_perf ${OpenCV_LIBS})

11-cv-perf/cars-0.jpg

165 KB
Loading

11-cv-perf/cars-1.jpg

260 KB
Loading

0 commit comments

Comments
 (0)