Skip to content

Commit a704f41

Browse files
committed
fix: remove verification
1 parent 783241c commit a704f41

File tree

1 file changed

+12
-33
lines changed

1 file changed

+12
-33
lines changed

src/apps/2024day4/src/main.cpp

Lines changed: 12 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -141,25 +141,6 @@ std::vector<Pattern> createPatterns() {
141141
return patterns;
142142
}
143143

144-
bool verifyMatch(
145-
const cv::Mat& grid, const Pattern& pattern, const cv::Point& location
146-
) {
147-
for (const auto& [color, offset] : pattern.pattern_def) {
148-
cv::Point pixelLoc(location.x + offset.x, location.y + offset.y);
149-
150-
if (pixelLoc.x < 0 || pixelLoc.x >= grid.cols || pixelLoc.y < 0 ||
151-
pixelLoc.y >= grid.rows) {
152-
return false;
153-
}
154-
155-
cv::Vec3b gridColor = grid.at<cv::Vec3b>(pixelLoc);
156-
if (gridColor != color) {
157-
return false;
158-
}
159-
}
160-
return true;
161-
}
162-
163144
struct Match {
164145
cv::Point location;
165146
std::string patternType;
@@ -178,7 +159,7 @@ std::vector<Match> findMatches(
178159
grid,
179160
pattern.template_image,
180161
result,
181-
cv::TM_CCOEFF_NORMED,
162+
cv::TM_CCORR_NORMED,
182163
pattern.mask
183164
);
184165

@@ -189,18 +170,16 @@ std::vector<Match> findMatches(
189170
cv::findNonZero(matches_mask, locations);
190171

191172
for (const auto& loc : locations) {
192-
if (verifyMatch(grid, pattern, loc)) {
193-
std::string matchKey;
194-
for (const auto& [color, offset] : pattern.pattern_def) {
195-
cv::Point pixelLoc(loc.x + offset.x, loc.y + offset.y);
196-
matchKey += std::to_string(pixelLoc.x) + "," +
197-
std::to_string(pixelLoc.y) + ";";
198-
}
199-
200-
if (uniqueMatches.find(matchKey) == uniqueMatches.end()) {
201-
matches.push_back({loc, pattern.name});
202-
uniqueMatches.insert(matchKey);
203-
}
173+
std::string matchKey;
174+
for (const auto& [color, offset] : pattern.pattern_def) {
175+
cv::Point pixelLoc(loc.x + offset.x, loc.y + offset.y);
176+
matchKey += std::to_string(pixelLoc.x) + "," +
177+
std::to_string(pixelLoc.y) + ";";
178+
}
179+
180+
if (uniqueMatches.find(matchKey) == uniqueMatches.end()) {
181+
matches.push_back({loc, pattern.name});
182+
uniqueMatches.insert(matchKey);
204183
}
205184
}
206185
}
@@ -250,7 +229,7 @@ cv::Mat visualizeMatches(
250229
}
251230

252231
int main() {
253-
const std::string filePath = "assets/input-example-1.txt";
232+
const std::string filePath = "assets/input.txt";
254233
const int VISUALIZATION_PIXEL_SIZE =
255234
30; // This is now only for visualization
256235

0 commit comments

Comments
 (0)