lab 2 - forsiden - universitetet i · pdf file𝒒= 27.3,−20.9, ... • samregistrer...

Post on 06-Feb-2018

227 Views

Category:

Documents

5 Downloads

Preview:

Click to see full reader

TRANSCRIPT

Lab 2

04.02.2016

Ressurser

β€’ OpenCV documentation: – http://opencv.org/documentation.html

β€’ Eigen documentation : – http://eigen.tuxfamily.org/dox/ – Quick reference quide: http://eigen.tuxfamily.org/dox/group__QuickRefPage.html

β€’ C++:

– http://en.cppreference.com/w/

β€’ Image Watch: An image debugger plug-in for Visual Studio – Download directly from Visual Studio:

Tools Extensions and Updates… Online Search for β€œImage Watch”

2

Litt om cv::Mat

3

Huskeliste

β€’ Lage prosjekt

β€’ Konstruere en cv::Mat – Datatyper, lage Β«vinduerΒ» – MatCommaInitializer

β€’ Hente og endre piksler

– at<…>() – forEach

β€’ Regne pΓ₯ matriser

– Operasjoner, MatExpr, …

4

Perspektivkameramodellen

5

The perspective camera model

6

𝐢

Vehicle

𝑄

π‘Š

𝑉

Perspective Camera

World

πœ‰π‘‰π‘Š

𝒒𝐢

πœ‰πΆπ‘‰

Point observed by the camera

π‘§π‘Š π‘¦π‘Š

π‘₯π‘Š

π‘₯𝑉

𝑦𝑉 𝑧𝑉

𝑧𝐢

π‘₯𝐢 𝑦𝐢

π‘Š is a local NED coordinate system (North East Down)

𝐢 is a standard coordinate system for a camera π‘₯𝐢 - Right 𝑦𝐢 - Down 𝑧𝐢 - Forward

𝑉 is a standard coordinate system for a vehicle π‘₯𝑉 - Forward 𝑦𝑉 - Right 𝑧𝑉 - Down

The perspective camera model

β€’ The point 𝑄 – Position π’’π‘Š = 27.3,βˆ’20.9,βˆ’11.5 𝑇

β€’ The vehicle

– 3m wide, 6m long – The origin of 𝑉 is chosen to be at

the center of the vehicle, 1m above the ground

– Pose relative to the world: π‘₯ = 6.7π‘š 𝑦 = βˆ’2.4π‘š 𝑧 = βˆ’14.0π‘š π‘Ÿπ‘Ÿπ‘Ÿπ‘Ÿ = 3.7Β° 𝑝𝑝𝑝𝑝𝑝 = βˆ’9.3Β° 𝑝𝑒𝑒𝑒𝑝𝑒𝑒 = 307.6Β°

β€’ The camera – The optical center is 2m in front of

and 1m to the left of the vehicles center

– The optical center is 4m above ground

– The y-axis of 𝐢 is perpendicular to the xy-plane of 𝑉

– The optical axis, i.e. the z-axis of 𝐢 , is rotated 4.7Β° to the right of the x-axis of 𝑉

– The camera calibration matrix is

𝐾 =1028 0 400

0 1028 3000 0 1

7

The perspective camera model

Problem In which pixel of the image will we observe the point 𝑄? Sub-problems 1. Represent πœ‰π‘‰π‘Š as a SE(3) object π‘‡π‘‰π‘Š 2. Represent πœ‰πΆπ‘‰ as a SE(3) object 𝑇𝐢𝑉 3. Represent πœ‰πΆπ‘Š as a SE(3) object π‘‡πΆπ‘Š 4. Determine the camera matrix 𝑃 = 𝐾 𝑅 𝒕 5. Determine the pixel 𝒖 = 𝑒,𝑣 that the

point 𝑄 projects to according to the perspective camera model

8

Sub-problem 1

Represent πœ‰π‘‰π‘Š as a SE(3) object π‘‡π‘‰π‘Š β€’ Sophus::SE3d objects can be initialized with a Eigen::Matrix3d rotation matrix 𝑅 and a

Eigen::Vector3d translation vector 𝒕 β€’ Roll, pitch, heading relates to the zyx-rotation sequence, so 𝑅 = 𝑅𝑧𝑅𝑦𝑅π‘₯ β€’ A basic rotation matrix like 𝑅π‘₯ πœƒ can be created by

Eigen::AngleAxisd(theta * M_PI / 180, Eigen::Vector3d::UnitX())

9

// Visualization of world and vehicle cv::Mat cv_t_W_V, cv_R_W_V; cv::eigen2cv(t_W_V, cv_t_W_V); cv::eigen2cv(R_W_V, cv_R_W_V); cv::Affine3d cv_T_W_V(cv_R_W_V, cv_t_W_V); cv::viz::Viz3d my_window("window 1"); my_window.showWidget("World-axes", cv::viz::WCoordinateSystem(3.0)); my_window.showWidget("vehicle-axes", cv::viz::WCoordinateSystem(3.0), cv_T_W_V); my_window.showWidget("vehicle", cv::viz::WCube(cv::Vec3d(-3.0, -1.5, -1), cv::Vec3d(3.0, 1.5, 1.0)), cv_T_W_V); my_window.spin();

Sub-problem 2 and 3

Represent πœ‰πΆπ‘‰ as a SE(3) object 𝑇𝐢𝑉 β€’ Which basic rotations must 𝑉 undergo in order to coincide with 𝐢 ? β€’ Two basic rotations is enough Represent πœ‰πΆπ‘Š as a SE(3) object π‘‡πΆπ‘Š β€’ Recall that π‘‡πΆπ‘Š = π‘‡π‘‰π‘Š 𝑇𝐢𝑉

10

// Visualization of camera frustum cv::Mat cv_t_W_C, cv_R_W_C, cv_K; cv::eigen2cv(K, cv_K); cv::eigen2cv(T_W_C.translation(), cv_t_W_C); cv::eigen2cv(T_W_C.rotationMatrix(), cv_R_W_C); cv::Affine3d cv_T_W_C(cv_R_W_C, cv_t_W_C); my_window.showWidget("camera_frustum", cv::viz::WCameraPosition(cv_K, 1.0, cv::viz::Color::red()), cv_T_W_C);

Sub-problem 4 and 5

Determine the camera matrix 𝑃 = 𝐾 𝑅 𝒕 β€’ Recall that in the perspective camera model 𝑅 = π‘…π‘ŠπΆ and 𝑝 = π‘π‘ŠπΆ , so we can not read 𝑅 and

𝒕 directly from π‘‡πΆπ‘Š Determine the pixel 𝒖 = 𝑒,𝑣 that the point 𝑄 projects to according to the perspective camera model β€’ Recall that 𝒖� = 𝑃𝑿�

11

// Visualization of point (as a small sphere) my_window.showWidget("Q", cv::viz::WSphere({ Q_W(0), Q_W(1), Q_W(2) }, 0.1));

Laplace blending

12

Steg 1: Lag nytt prosjekt og vis frem bilder

β€’ Kopier Β«opencv_project_templateΒ» og gi nytt navn – Husk Γ₯ endre Β«PROJECT_NAMEΒ» i CMakeLists.txt

β€’ Lag nytt prosjekt med Cmake

β€’ Skriv et program som leser to bilder

– img_1: free_cat.jpg – img_2: free_tiger.jpg – Bildene bΓΈr konverteres til flyttallsbilder:

cv::imread(…).convertTo(img_1, CV_32F, 1.0/255.0);

β€’ Vis bildene frem – cv::namedWindow() – cv::imshow()

13

Steg 2: Enkel blanding av bilder

β€’ Samregistrer bildene ved Γ₯ angi tre punktkorrespondanser

β€’ Lag maske med rampe

14

cv::Point2f pts_1[] = {{321, 200}, {647, 200}, {476, 509}}; cv::Point2f pts_2[] = {{441, 726}, {780, 711}, {615, 1142}}; cv::Mat trans_mat = cv::getAffineTransform(pts_2, pts_1); cv::warpAffine(img_2, img_2, trans_mat, img_1.size());

cv::Mat mask = cv::Mat::zeros(img_1.size(), CV_32FC1); cv::rectangle(mask, cv::Rect{img_1.cols/2, 0, img_1.cols/2 + 1, img_1.rows}, 1, CV_FILLED); cv::blur(mask, mask, cv::Size{3, 3});

Steg 2: Enkel blanding av bilder

β€’ Lag funksjon som gjΓΈr enkel blanding av to bilder vektet med masken

– Tips: cv::blendLinear()

β€’ Bruk funksjonen og vis frem resultatet – PrΓΈv med forskjellige masker

β€’ Andre sΓΈmmer, sirkler, stΓΈrre glattefilter

15

cv::Mat linear_blend(cv::Mat& img_1, cv::Mat& img_2, cv::Mat& mask)

Steg 3: Laplaceblanding

β€’ Lag funksjonen – cv::pyrDown()

16

std::vector<cv::Mat> construct_gaussian_pyramid(cv::Mat& img)

Steg 3: Laplaceblanding

β€’ Lag funksjonen – Bruk construct_gaussian_pyramid – cv::pyrUp()

17

std::vector<cv::Mat> construct_laplacian_pyramid(cv::Mat& img)

Steg 3: Laplaceblanding

β€’ Lag funksjonen – cv::pyrUp()

18

cv::Mat collapse_pyramid(std::vector<cv::Mat>& pyr)

Steg 3: Laplaceblanding

β€’ Lag funksjonen – For eksempel slik:

19

cv::Mat laplace_blending(cv::Mat& img_1, cv::Mat& img_2, cv::Mat& mask)

std::vector<cv::Mat> mask_pyr = construct_gaussian_pyramid(mask); std::vector<cv::Mat> img_1_pyr = construct_laplacian_pyramid(img_1); std::vector<cv::Mat> img_2_pyr = construct_laplacian_pyramid(img_2); std::vector<cv::Mat> blend_pyr(img_1_pyr.size()); for (int i = 0; i < img_1_pyr.size(); i++) { // TODO: Perform linear blend on each level. } return collapse_pyramid(blend_pyr);

Steg 3: Laplaceblanding

β€’ Bruk laplace_blending(img_1, img_2, mask) – Vis frem resultat – Sammenlign med enkel blending

20

Steg 4: Moroplukk

β€’ PrΓΈv andre bilder – Ta bilder med kameraet – Finn bilder pΓ₯ nett – Angi nye punkter for samregistrering

β€’ Andre masker

– Last ned GIMP for Γ₯ tegne finere masker

21

Steg 5: Dypdykk

β€’ Implementer pyramiden selv – Ikke bruk cv::pyrDown() eller cv::pyrUp()

β€’ Ta en titt pΓ₯ cv::seamlessClone()

β€’ PrΓΈv Γ₯ implementere warpingen selv

22

top related