Skip to content

Commit

Permalink
feat: good enough circle clustering
Browse files Browse the repository at this point in the history
  • Loading branch information
tomiock committed Aug 14, 2024
1 parent e26d47b commit aa03a4e
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 20 deletions.
3 changes: 1 addition & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@ CC = clang++
CFLAGS = $(shell pkg-config --cflags opencv4)
LDFLAGS = $(shell pkg-config --libs opencv4)
TARGET = opencv_lol
SRCS = cpp/main.cpp cpp/detect_champ.cpp cpp/remove_terrain.cpp
# cpp/circle_priority.cpp
SRCS = cpp/main.cpp cpp/detect_champ.cpp cpp/remove_terrain.cpp cpp/circle_priority.cpp
OBJS = $(SRCS:.cpp=.o)
BUILD_DIR = build

Expand Down
4 changes: 2 additions & 2 deletions cpp/circle_priority.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ void cluster_circles(Circles &circles, CirclesCluster &clusters, float distanceT
float distance = std::sqrt(dx * dx + dy * dy); // euclidian distance used

if (distance < distanceThreshold) {
cluster.push_back(circle);
cluster.push_back(circle); // new element
addedToCluster = true;
break;
}
Expand All @@ -28,7 +28,7 @@ void cluster_circles(Circles &circles, CirclesCluster &clusters, float distanceT
break;
}
if (!addedToCluster) {
clusters.push_back({circle});
clusters.push_back({circle}); // new element
}
}
}
Expand Down
34 changes: 18 additions & 16 deletions cpp/detect_champ.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,39 +32,41 @@ std::vector<cv::Vec3f> detectCircles(cv::Mat &image, unsigned int radius,
}

void drawCircles(cv::Mat &src, std::vector<cv::Vec3f> &circles) {
for (size_t i = 0; i < circles.size(); i++) {
cv::Point center(cvRound(circles[i][0]), cvRound(circles[i][1]));
int radius = cvRound(circles[i][2]);
for (const cv::Vec3f & circle : circles) {
cv::Point center(cvRound(circle[0]), cvRound(circle[1]));
int radius = cvRound(circle[2]);
// circle center
cv::circle(src, center, 3, cv::Scalar(0, 255, 0), -1, 8, 0);
// circle outline
cv::circle(src, center, radius, cv::Scalar(255, 0, 255), 3, 8, 0);
}
}

void drawCirclesClusters(cv::Mat &src, CirclesCluster &clusters) {
for (Circles & circles : clusters) {

/*
void drawCirclesClusters(cv::Mat &src, CirclesCluster &circles) {
for (size_t i = 0; i < circles.size(); i++) {
cv::Point center(cv::cvRound(circles[i][0]), cv::cvRound(circles[i][1]));
int radius = cv::cvRound(circles[i][2]);
// circle center
cv::circle(src, center, 3, cv::Scalar(0, 255, 0), -1, 8, 0);
// circle outline
cv::circle(src, center, radius, cv::Scalar(255, 0, 255), 3, 8, 0);
cv::Scalar clusterColor(rand() % 256, rand() % 256, rand() % 256);

for (const cv::Vec3f & circle : circles) {
cv::Point center((cvRound(circle[0])), cvRound(circle[1]));
int radius = cvRound(circle[2]);
// circle center
cv::circle(src, center, 3, clusterColor, -1, 8, 0);
// circle outline
cv::circle(src, center, radius, clusterColor, 3, 8, 0);
}
}
}
*/

void detectChamp(cv::Mat &image) {
image = update_image(image);

std::vector<cv::Vec3f> circles = detectCircles(image, 29, 300, 15, 3);

//CirclesCluster clusters;
//cluster_circles(circles, clusters, 1);
CirclesCluster clusters;
cluster_circles(circles, clusters, 55); // issue here

drawCircles(image, circles);
drawCirclesClusters(image, clusters);

cv::imshow("Processed Image", image);
while ((cv::waitKey() & 0xEFFFFF) != 81);
Expand Down
Binary file modified opencv_lol
Binary file not shown.

0 comments on commit aa03a4e

Please sign in to comment.