Skip to content

Commit

Permalink
Replaced all new/delete by vectors in exercises
Browse files Browse the repository at this point in the history
Resolved all clangd issues
  • Loading branch information
hudrima1 committed Nov 3, 2024
1 parent 3e6547e commit 548323b
Show file tree
Hide file tree
Showing 13 changed files with 1,108 additions and 1,053 deletions.
322 changes: 162 additions & 160 deletions apps/exercises/ch06_ColorCube/ColorCube.cpp

Large diffs are not rendered by default.

350 changes: 164 additions & 186 deletions apps/exercises/ch07_DiffuseCube/DiffuseCube.cpp

Large diffs are not rendered by default.

382 changes: 189 additions & 193 deletions apps/exercises/ch07_DiffuseSphere/DiffuseSphere.cpp

Large diffs are not rendered by default.

495 changes: 248 additions & 247 deletions apps/exercises/ch08_BlinnPhongLighting/BlinnPhongLighting.cpp

Large diffs are not rendered by default.

428 changes: 213 additions & 215 deletions apps/exercises/ch09_TextureMapping/TextureMapping.cpp

Large diffs are not rendered by default.

3 changes: 1 addition & 2 deletions apps/exercises/cv02_CalderonFilter/cv02_CalderonFilter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,8 @@
* \details Minimal OpenCV app for the Instagram Calderon filter
* \copyright Based on Satya Mallick's Tutorial at https://www.learnopencv.com
* \date Spring 2018
*/
*/

#include <math.h>
#include <opencv2/highgui.hpp>
#include <opencv2/opencv.hpp>

Expand Down
47 changes: 36 additions & 11 deletions apps/exercises/cv06_WarpTriangle/cv06_WarpTriangle.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* \brief Minimal OpenCV application that warps a triangle into another
* \copyright Based on Satya Mallick's Tutorial at https://www.learnopencv.com
* \date Spring 2018
*/
*/

#include <opencv2/opencv.hpp>
#include <stdlib.h>
Expand All @@ -27,11 +27,14 @@ void warpTriangle(Mat& img1,
vector<Point> tri2CroppedInt;
for (uint i = 0; i < 3; i++)
{
tri1Cropped.push_back(Point2f(tri1[i].x - rect1.x, tri1[i].y - rect1.y));
tri2Cropped.push_back(Point2f(tri2[i].x - rect2.x, tri2[i].y - rect2.y));
tri1Cropped.push_back(Point2f(tri1[i].x - (float)rect1.x,
tri1[i].y - (float)rect1.y));
tri2Cropped.push_back(Point2f(tri2[i].x - (float)rect2.x,
tri2[i].y - (float)rect2.y));

// fillConvexPoly needs a vector of int Point and not Point2f
tri2CroppedInt.push_back(Point((int)tri2Cropped[i].x, (int)tri2Cropped[i].y));
tri2CroppedInt.push_back(Point((int)tri2Cropped[i].x,
(int)tri2Cropped[i].y));
}

// Apply warpImage to small rectangular patches
Expand All @@ -42,7 +45,9 @@ void warpTriangle(Mat& img1,
Mat warpMat = getAffineTransform(tri1Cropped, tri2Cropped);

// Apply the Affine Transform just found to the src image
Mat img2Cropped = Mat::zeros(rect2.height, rect2.width, img1Cropped.type());
Mat img2Cropped = Mat::zeros(rect2.height,
rect2.width,
img1Cropped.type());
warpAffine(img1Cropped,
img2Cropped,
warpMat,
Expand All @@ -51,14 +56,24 @@ void warpTriangle(Mat& img1,
BORDER_REFLECT_101);

// Create white triangle mask
Mat mask = Mat::zeros(rect2.height, rect2.width, CV_32FC3);
fillConvexPoly(mask, tri2CroppedInt, Scalar(1.0, 1.0, 1.0), LINE_AA, 0);
Mat mask = Mat::zeros(rect2.height,
rect2.width,
CV_32FC3);
fillConvexPoly(mask,
tri2CroppedInt,
Scalar(1.0, 1.0, 1.0),
LINE_AA,
0);

// Delete all outside of warped triangle
multiply(img2Cropped, mask, img2Cropped);
multiply(img2Cropped,
mask,
img2Cropped);

// Delete all inside the target triangle
multiply(img2(rect2), Scalar(1.0, 1.0, 1.0) - mask, img2(rect2));
multiply(img2(rect2),
Scalar(1.0, 1.0, 1.0) - mask,
img2(rect2));

// Add warped triangle to target image
img2(rect2) = img2(rect2) + img2Cropped;
Expand Down Expand Up @@ -119,8 +134,18 @@ int main()
}

// Draw triangles in input and output images
polylines(imgIn, triInInt, true, color, 1, LINE_AA);
polylines(imgOut, triOutInt, true, color, 1, LINE_AA);
polylines(imgIn,
triInInt,
true,
color,
1,
LINE_AA);
polylines(imgOut,
triOutInt,
true,
color,
1,
LINE_AA);

string title1 = "Input";
imshow(title1, imgIn);
Expand Down
50 changes: 38 additions & 12 deletions apps/exercises/cv07_MeshWarping/cv07_MeshWarping.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* \copyright Based on Satya Mallick's Tutorial:
* https://www.learnopencv.com/warp-one-triangle-to-another-using-opencv-c-python
* \date Spring 2018
*/
*/

#include <iostream>
#include <opencv2/highgui/highgui.hpp>
Expand Down Expand Up @@ -134,11 +134,14 @@ void warpTriangle(Mat& img1,
vector<Point> tri2CroppedInt;
for (uint i = 0; i < 3; i++)
{
tri1Cropped.push_back(Point2f(tri1[i].x - rect1.x, tri1[i].y - rect1.y));
tri2Cropped.push_back(Point2f(tri2[i].x - rect2.x, tri2[i].y - rect2.y));
tri1Cropped.push_back(Point2f(tri1[i].x - (float)rect1.x,
tri1[i].y - (float)rect1.y));
tri2Cropped.push_back(Point2f(tri2[i].x - (float)rect2.x,
tri2[i].y - (float)rect2.y));

// fillConvexPoly needs a vector of int Point and not Point2f
tri2CroppedInt.push_back(Point((int)tri2Cropped[i].x, (int)tri2Cropped[i].y));
tri2CroppedInt.push_back(Point((int)tri2Cropped[i].x,
(int)tri2Cropped[i].y));
}

// Apply warpImage to small rectangular patches
Expand All @@ -149,7 +152,9 @@ void warpTriangle(Mat& img1,
Mat warpMat = getAffineTransform(tri1Cropped, tri2Cropped);

// Apply the Affine Transform just found to the src image
Mat img2Cropped = Mat::zeros(rect2.height, rect2.width, img1Cropped.type());
Mat img2Cropped = Mat::zeros(rect2.height,
rect2.width,
img1Cropped.type());
warpAffine(img1Cropped,
img2Cropped,
warpMat,
Expand All @@ -159,13 +164,19 @@ void warpTriangle(Mat& img1,

// Create white triangle mask
Mat mask = Mat::zeros(rect2.height, rect2.width, CV_32FC3);
fillConvexPoly(mask, tri2CroppedInt, Scalar(1.0, 1.0, 1.0), LINE_AA, 0);
fillConvexPoly(mask,
tri2CroppedInt,
Scalar(1.0, 1.0, 1.0),
LINE_AA,
0);

// Delete all outside of warped triangle
multiply(img2Cropped, mask, img2Cropped);

// Delete all inside the target triangle
multiply(img2(rect2), Scalar(1.0, 1.0, 1.0) - mask, img2(rect2));
multiply(img2(rect2),
Scalar(1.0, 1.0, 1.0) - mask,
img2(rect2));

// Add warped triangle to target image
img2(rect2) = img2(rect2) + img2Cropped;
Expand Down Expand Up @@ -230,8 +241,8 @@ int main()
// Keep bounding rectangle around face points
Size size = img_orig.size();
Rect rectFace = boundingRect(points);
Point2f center(rectFace.x + rectFace.width * 0.5f,
rectFace.y + rectFace.height * 0.5f);
Point2f center((float)rectFace.x + (float)rectFace.width * 0.5f,
(float)rectFace.y + (float)rectFace.height * 0.5f);

// Add image border points
points.push_back(Point2d(0, 0));
Expand All @@ -249,12 +260,22 @@ int main()

// Create and draw the Delaunay triangulation
vector<vector<uint>> triIndexes1;
createDelaunay(img1, subdiv, points, true, triIndexes1);
createDelaunay(img1,
subdiv,
points,
true,
triIndexes1);
// drawDelaunay(img1, subdiv, Scalar(255, 255, 255));

// Draw all points red
for (Point2f p : points)
circle(img1, p, 3, Scalar(0, 0, 255), FILLED, LINE_AA, 0);
circle(img1,
p,
3,
Scalar(0, 0, 255),
FILLED,
LINE_AA,
0);

// Allocate space for voronoi Diagram
Mat img_voronoi = Mat::zeros(img1.rows, img1.cols, CV_8UC3);
Expand Down Expand Up @@ -285,7 +306,12 @@ int main()
wPoints[i] = ((points[i] - center) * scale) + center;

// Warp all triangles
warpImage(img_orig, imgW, points, wPoints, triIndexes1);
warpImage(img_orig,
imgW,
points,
wPoints,
triIndexes1);

imshow("Warped Image", imgW);

// Wait for key to exit loop
Expand Down
24 changes: 16 additions & 8 deletions apps/exercises/cv08_MeshMorphing/cv08_MeshMorphing.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* \brief Minimal OpenCV application that morphs two triangular meshes
* \copyright Based on Satya Mallick's Tutorial at https://www.learnopencv.com
* \date Spring 2018
*/
*/

#include <iostream>
#include <opencv2/highgui/highgui.hpp>
Expand Down Expand Up @@ -157,10 +157,10 @@ void morphTriangle(Mat& img1,
vector<Point2i> tMRectInt; // for fillConvexPoly we need ints
for (uint i = 0; i < 3; i++)
{
tMRectFlt.push_back(Point2f(tM[i].x - rM.x, tM[i].y - rM.y));
tMRectInt.push_back(Point2i((int)(tM[i].x - rM.x), (int)(tM[i].y - rM.y)));
t1RectFlt.push_back(Point2f(t1[i].x - r1.x, t1[i].y - r1.y));
t2RectFlt.push_back(Point2f(t2[i].x - r2.x, t2[i].y - r2.y));
tMRectFlt.push_back(Point2f(tM[i].x - (float)rM.x, tM[i].y - (float)rM.y));
tMRectInt.push_back(Point2i((int)(tM[i].x - (float)rM.x), (int)(tM[i].y - (float)rM.y)));
t1RectFlt.push_back(Point2f(t1[i].x - (float)r1.x, t1[i].y - (float)r1.y));
t2RectFlt.push_back(Point2f(t2[i].x - (float)r2.x, t2[i].y - (float)r2.y));
}

// Create white triangle mask
Expand All @@ -175,8 +175,14 @@ void morphTriangle(Mat& img1,
Mat warpImage1 = Mat::zeros(rM.height, rM.width, img1Rect.type());
Mat warpImage2 = Mat::zeros(rM.height, rM.width, img2Rect.type());

applyAffineTransform(warpImage1, img1Rect, t1RectFlt, tMRectFlt);
applyAffineTransform(warpImage2, img2Rect, t2RectFlt, tMRectFlt);
applyAffineTransform(warpImage1,
img1Rect,
t1RectFlt,
tMRectFlt);
applyAffineTransform(warpImage2,
img2Rect,
t2RectFlt,
tMRectFlt);

// Alpha blend rectangular patches into new image
Mat imgRect = (1.0f - alpha) * warpImage1 + alpha * warpImage2;
Expand All @@ -185,7 +191,9 @@ void morphTriangle(Mat& img1,
multiply(imgRect, mask, imgRect);

// Delete all inside the target triangle
multiply(imgM(rM), Scalar(1.0f, 1.0f, 1.0f) - mask, imgM(rM));
multiply(imgM(rM),
Scalar(1.0f, 1.0f, 1.0f) - mask,
imgM(rM));

// Add morphed triangle to target image
imgM(rM) = imgM(rM) + imgRect;
Expand Down
13 changes: 9 additions & 4 deletions apps/exercises/cv13_FaceTracking/cv13_FaceTracking.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,12 @@
* \brief Minimal OpenCV application for face Tracking in video
* \copyright Based on Satya Mallick's Tutorial at https://www.learnopencv.com
* \date Authumn 2017
*/
*/

#include <opencv2/highgui.hpp>
#include <opencv2/imgproc.hpp>
#include <opencv2/objdetect.hpp>

#include <iostream>
#include <stdio.h>

using namespace std;
Expand Down Expand Up @@ -46,7 +45,10 @@ void detectFaceAndDisplay(Mat frame)

for (size_t i = 0; i < faces.size(); i++)
{
rectangle(frame, faces[i], Scalar(255, 0, 255), 2);
rectangle(frame,
faces[i],
Scalar(255, 0, 255),
2);

Mat faceROI = frame_gray(faces[i]);
std::vector<Rect> eyes;
Expand All @@ -63,7 +65,10 @@ void detectFaceAndDisplay(Mat frame)
{
eyes[j].x += faces[i].x;
eyes[j].y += faces[i].y;
rectangle(frame, eyes[j], Scalar(255, 0, 0), 2);
rectangle(frame,
eyes[j],
Scalar(255, 0, 0),
2);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* \brief Minimal OpenCV app for facial landmark detection without dlib
* \copyright Based on Satya Mallick's Tutorial at https://www.learnopencv.com
* \date Authumn 2017
*/
*/

#include <opencv2/face.hpp>
#include <opencv2/opencv.hpp>
Expand Down Expand Up @@ -44,11 +44,17 @@ int main()

// Detect faces
vector<Rect> faces;
int min = (int)(frame.rows * 0.4f); // the bigger min the faster
int max = (int)(frame.rows * 0.8f); // the smaller max the faster
int min = (int)((float)frame.rows * 0.4f); // the bigger min the faster
int max = (int)((float)frame.rows * 0.8f); // the smaller max the faster
cv::Size minSize(min, min);
cv::Size maxSize(max, max);
faceDetector.detectMultiScale(gray, faces, 1.1, 3, 0, minSize, maxSize);
faceDetector.detectMultiScale(gray,
faces,
1.1,
3,
0,
minSize,
maxSize);

// Variable for landmarks.
// Landmarks for one face is a vector of points
Expand All @@ -63,9 +69,16 @@ int main()
{
for (uint i = 0; i < landmarks.size(); i++)
{
rectangle(frame, faces[i], cv::Scalar(255, 0, 0), 2);
rectangle(frame,
faces[i],
cv::Scalar(255, 0, 0),
2);
for (auto& j : landmarks[i])
circle(frame, j, 3, cv::Scalar(0, 0, 255), -1);
circle(frame,
j,
3,
cv::Scalar(0, 0, 255),
-1);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* \brief Minimal OpenCV app for head pose estimation
* \copyright Based on Satya Mallick's Tutorial at https://www.learnopencv.com
* \date Authumn 2017
*/
*/

#include <opencv2/opencv.hpp>

Expand Down Expand Up @@ -84,7 +84,11 @@ int main()

// Draw red dots on all image points
for (auto& image_point : image_points)
circle(image, image_point, 3, Scalar(0, 0, 255), -1);
circle(image,
image_point,
3,
Scalar(0, 0, 255),
-1);

// Draw blue nose line
line(image,
Expand Down
Loading

0 comments on commit 548323b

Please sign in to comment.