-
-
Notifications
You must be signed in to change notification settings - Fork 56.2k
hal/riscv-rvv: implement FAST keypoint detection #27391
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
Open
Haosonn
wants to merge
24
commits into
opencv:4.x
Choose a base branch
from
Haosonn:pr-rvv-hal-fast
base: 4.x
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 11 commits
Commits
Show all changes
24 commits
Select commit
Hold shift + click to select a range
e0724db
Empty implementation for FAST function
a088804
CALL_HAL modification for cv_hal_fast
8dac44c
basic implementation of fast_9_16 for riscv
ca88641
debug test modification
1a1b2e8
Add features2d module in new rvv-hal
393ab4c
Merge branch 'github' into rvv-hal-fast
2147287
Test FAST.noNMS success
8d116fa
weird memory read
a15574f
Pass NMS test
09e0a44
delete debug messages
fa709c3
Add perf tests
3cfdf0a
Dead code deleted in test_fast.cpp
77a30d9
Fix requested changes
835176f
Disable sanity check
8f20b66
Delete trailing whitespace
96756ba
Rollback CALL_HAL
7f77a15
Requested changes in perf_fast.cpp
08414a4
Requested changes done
621a65f
Put memset in default branch & keypoint_cnt not initialized bug
7c40a56
feat: introduce new API for FAST hal
fengyuentau d137e0c
fix: fix bugs in the new API
fengyuentau a41f63b
feat: drop func typedef and use function ptr instead
fengyuentau 7f8e331
fix: fix build
fengyuentau 390bcf5
doc: add documentation for realloc_func
fengyuentau File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Haosonn marked this conversation as resolved.
Show resolved
Hide resolved
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,133 @@ | ||
// This file is part of OpenCV project. | ||
// It is subject to the license terms in the LICENSE file found in the top-level directory | ||
// of this distribution and at http://opencv.org/license.html. | ||
#ifndef OPENCV_RVV_UTILS_BUFFER_AREA_HPP | ||
#define OPENCV_RVV_UTILS_BUFFER_AREA_HPP | ||
|
||
#include <vector> | ||
|
||
namespace cv { namespace utils { | ||
|
||
//! @addtogroup core_utils | ||
//! @{ | ||
|
||
/** @brief Manages memory block shared by muliple buffers. | ||
|
||
This class allows to allocate one large memory block and split it into several smaller | ||
non-overlapping buffers. In safe mode each buffer allocation will be performed independently, | ||
this mode allows dynamic memory access instrumentation using valgrind or memory sanitizer. | ||
|
||
Safe mode can be explicitly switched ON in constructor. It will also be enabled when compiling with | ||
memory sanitizer support or in runtime with the environment variable `OPENCV_BUFFER_AREA_ALWAYS_SAFE`. | ||
|
||
Example of usage: | ||
@code | ||
int * buf1 = 0; | ||
double * buf2 = 0; | ||
cv::util::BufferArea area; | ||
area.allocate(buf1, 200); // buf1 = new int[200]; | ||
area.allocate(buf2, 1000, 64); // buf2 = new double[1000]; - aligned by 64 | ||
area.commit(); | ||
@endcode | ||
|
||
@note This class is considered private and should be used only in OpenCV itself. API can be changed. | ||
*/ | ||
class CV_EXPORTS BufferArea | ||
Haosonn marked this conversation as resolved.
Show resolved
Hide resolved
|
||
{ | ||
public: | ||
/** @brief Class constructor. | ||
|
||
@param safe Enable _safe_ operation mode, each allocation will be performed independently. | ||
*/ | ||
BufferArea(bool safe = false); | ||
|
||
/** @brief Class destructor | ||
|
||
All allocated memory well be freed. Each bound pointer will be reset to NULL. | ||
*/ | ||
~BufferArea(); | ||
|
||
/** @brief Bind a pointer to local area. | ||
|
||
BufferArea will store reference to the pointer and allocation parameters effectively owning the | ||
pointer and allocated memory. This operation has the same parameters and does the same job | ||
as the operator `new`, except allocation can be performed later during the BufferArea::commit call. | ||
|
||
@param ptr Reference to a pointer of type T. Must be NULL | ||
@param count Count of objects to be allocated, it has the same meaning as in the operator `new`. | ||
@param alignment Alignment of allocated memory. same meaning as in the operator `new` (C++17). | ||
Must be divisible by sizeof(T). Must be power of two. | ||
|
||
@note In safe mode allocation will be performed immediatly. | ||
*/ | ||
template <typename T> | ||
void allocate(T*&ptr, size_t count, ushort alignment = sizeof(T)) | ||
{ | ||
CV_Assert(ptr == NULL); | ||
CV_Assert(count > 0); | ||
CV_Assert(alignment > 0); | ||
CV_Assert(alignment % sizeof(T) == 0); | ||
CV_Assert((alignment & (alignment - 1)) == 0); | ||
allocate_((void**)(&ptr), static_cast<ushort>(sizeof(T)), count, alignment); | ||
#ifndef OPENCV_ENABLE_MEMORY_SANITIZER | ||
if (safe) | ||
#endif | ||
CV_Assert(ptr != NULL); | ||
} | ||
|
||
/** @brief Fill one of buffers with zeroes | ||
|
||
@param ptr pointer to memory block previously added using BufferArea::allocate | ||
|
||
BufferArea::commit must be called before using this method | ||
*/ | ||
template <typename T> | ||
void zeroFill(T*&ptr) | ||
{ | ||
CV_Assert(ptr); | ||
zeroFill_((void**)&ptr); | ||
} | ||
|
||
/** @brief Fill all buffers with zeroes | ||
|
||
BufferArea::commit must be called before using this method | ||
*/ | ||
void zeroFill(); | ||
|
||
/** @brief Allocate memory and initialize all bound pointers | ||
|
||
Each pointer bound to the area with the BufferArea::allocate will be initialized and will be set | ||
to point to a memory block with requested size and alignment. | ||
|
||
@note Does nothing in safe mode as all allocations will be performed by BufferArea::allocate | ||
*/ | ||
void commit(); | ||
|
||
/** @brief Release all memory and unbind all pointers | ||
|
||
All memory will be freed and all pointers will be reset to NULL and untied from the area allowing | ||
to call `allocate` and `commit` again. | ||
*/ | ||
void release(); | ||
|
||
private: | ||
BufferArea(const BufferArea &); // = delete | ||
BufferArea &operator=(const BufferArea &); // = delete | ||
void allocate_(void **ptr, ushort type_size, size_t count, ushort alignment); | ||
void zeroFill_(void **ptr); | ||
|
||
private: | ||
class Block; | ||
std::vector<Block> blocks; | ||
#ifndef OPENCV_ENABLE_MEMORY_SANITIZER | ||
void * oneBuf; | ||
size_t totalSize; | ||
const bool safe; | ||
#endif | ||
}; | ||
|
||
//! @} | ||
|
||
}} // cv::utils:: | ||
|
||
#endif |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
// This file is part of OpenCV project. | ||
// It is subject to the license terms in the LICENSE file found in the top-level directory | ||
// of this distribution and at http://opencv.org/license.html. | ||
|
||
#ifndef OPENCV_RVV_HAL_FEATURES2D_HPP | ||
#define OPENCV_RVV_HAL_FEATURES2D_HPP | ||
|
||
struct cvhalFilter2D; | ||
|
||
namespace cv { namespace rvv_hal { namespace features2d { | ||
|
||
#if CV_HAL_RVV_1P0_ENABLED | ||
int FAST(const uchar* src_data, size_t src_step, int width, int height, | ||
Haosonn marked this conversation as resolved.
Show resolved
Hide resolved
|
||
std::vector<KeyPoint>& keypoints, | ||
int threshold, bool nonmax_suppression, int detector_type); | ||
#undef cv_hal_FAST | ||
#define cv_hal_FAST cv::rvv_hal::features2d::FAST | ||
|
||
#endif // CV_HAL_RVV_1P0_ENABLED | ||
|
||
|
||
}}} // cv::rvv_hal::features2d | ||
|
||
#endif // OPENCV_RVV_HAL_IMGPROC_HPP |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
// This file is part of OpenCV project. | ||
// It is subject to the license terms in the LICENSE file found in the top-level directory | ||
// of this distribution and at http://opencv.org/license.html. | ||
// | ||
// Copyright (C) 2025, SpaceMIT Inc., all rights reserved. | ||
// Copyright (C) 2025, Institute of Software, Chinese Academy of Sciences. | ||
// Third party copyrights are property of their respective owners. | ||
|
||
#ifndef OPENCV_HAL_RVV_FEATURES2D_COMMON_HPP_INCLUDED | ||
#define OPENCV_HAL_RVV_FEATURES2D_COMMON_HPP_INCLUDED | ||
|
||
#include <riscv_vector.h> | ||
#include "opencv2/features2d/hal/interface.h" | ||
|
||
namespace cv { namespace rvv_hal { namespace features2d { namespace common { | ||
|
||
#if CV_HAL_RVV_1P0_ENABLED | ||
|
||
#endif // CV_HAL_RVV_1P0_ENABLED | ||
|
||
}}}} // cv::rvv_hal::core::common | ||
|
||
#endif // OPENCV_HAL_RVV_CORE_COMMON_HPP_INCLUDED |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.