Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

AM-78 Add depth of BFS search #109

Merged
merged 1 commit into from
Oct 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion analyze/algorithm/DiffObjectDetector.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ namespace am::analyze::algorithm
{
// optimized bfs depending to left/right borders for threads,
// every thread will search in defined area(column) of image
ObjectRectangle bfs(MatrixU16 &changes, Pixels &toCheck, ObjectRectangle &object, ImageRowSegment row)
ObjectRectangle bfs(MatrixU16 &changes, const Pixels &toCheck, ObjectRectangle &object, ImageRowSegment row)
{
Pixels nextCheck;

Expand Down
21 changes: 14 additions & 7 deletions analyze/algorithm/ObjectDetector.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,17 @@ namespace am::analyze::algorithm

// Time dependent execution, if max calculation time exceeded calculation should
// finalize processing, and show up collected objects(if found).
ObjectRectangle bfs(const ImagePair &pair, MatrixU16 &visited, Pixels &toCheck,
ObjectRectangle bfs(const ImagePair &pair, MatrixU16 &visited, const Pixels &toCheck,
ObjectRectangle &object, ImageRowSegment row,
std::chrono::steady_clock::time_point &startTime,
const Configuration &conf)
const Configuration &conf, size_t depth)
{
if(depth == 120 * 2) {
// limit depth of search, low step value can affect stack consuming on images with noise.
// depth can be modified or be configurable depending on HW.
printf("Depth limit exceeded(max value %zd).\n", depth);
return object;
}
auto timeNow = std::chrono::steady_clock::now();
std::chrono::duration<double> calcDuration = timeNow - startTime;
if (calcDuration.count() >= conf.CalculationTimeLimit)
Expand All @@ -34,7 +40,7 @@ namespace am::analyze::algorithm
}
Pixels nextCheck;

for (auto &position : toCheck)
for (const auto &position : toCheck)
{
if (visited(position.rowId, position.colId) != common::CHANGE &&
pair.getAbsoluteDiff(position.rowId, position.colId) >
Expand All @@ -47,8 +53,9 @@ namespace am::analyze::algorithm
object.addPixel(position.rowId, position.colId);
}
}
if (nextCheck.size())
bfs(pair, visited, nextCheck, object, row, startTime, conf);
if (nextCheck.size()){
bfs(pair, visited, nextCheck, object, row, startTime, conf, depth +1);
}

return object;
}
Expand Down Expand Up @@ -83,7 +90,7 @@ namespace am::analyze::algorithm
ObjectRectangle obj(rowId, colId);
auto conns = checkConnections(rowId, colId, pair.getWidth(), row, conf.PixelStep);

resultList.emplace_back(bfs(pair, changes, conns, obj, row, startTime, conf));
resultList.emplace_back(bfs(pair, changes, conns, obj, row, startTime, conf, 1));
}
}
}
Expand All @@ -98,7 +105,7 @@ namespace am::analyze::algorithm
mLogger->info("ObjectDetector::getObjectsRects pair threads:%d",
mThreadsCount);
// threadpool could be replaced with std::async calls
am::common::ThreadPool pool;
am::common::ThreadPool pool(mThreadsCount);
for (size_t rowId = 0; rowId < mThreadsCount - 1; ++rowId)
{
ImageRowSegment row{rowId * rowHeight, rowId * rowHeight + rowHeight};
Expand Down
4 changes: 2 additions & 2 deletions analyze/algorithm/ObjectDetector.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@ namespace am::analyze::algorithm
{

ObjectRectangle bfs(const ImagePair &pair, common::types::MatrixU16 &visited,
std::vector<Pixel> &toCheck, ObjectRectangle &object,
const std::vector<Pixel> &toCheck, ObjectRectangle &object,
ImageRowSegment row, std::chrono::steady_clock::time_point &startTime,
const Configuration &conf);
const Configuration &conf, size_t depth);

class ObjectDetector : public BfsObjectDetector
{
Expand Down
2 changes: 1 addition & 1 deletion analyze/algorithm/movement/MovementDetector.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ namespace am::analyze::algorithm::movement
{
ObjectRectangle pxs(rowId, colId);
auto conns = checkConnections(rowId, colId, pair->getHeight(), {0u, pair->getWidth()}, mConfiguration.PixelStep);
auto objFound = bfs(*pair, changes, conns, pxs, {0u, pair->getWidth()}, startTime, mConfiguration);
auto objFound = bfs(*pair, changes, conns, pxs, {0u, pair->getWidth()}, startTime, mConfiguration, 1);
found.emplace_back(objFound);
}
}
Expand Down
Loading