Skip to content

Commit

Permalink
fix issue in the references and tests
Browse files Browse the repository at this point in the history
  • Loading branch information
xavierbrgt committed Jul 4, 2024
1 parent 9e3f01b commit 9424e4e
Show file tree
Hide file tree
Showing 40 changed files with 39 additions and 88 deletions.
8 changes: 4 additions & 4 deletions Include/cv/feature_detection.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ extern "C"
* @return Scratch size in bytes
*
*/
uint16_t arm_cv_get_scratch_size_canny_sobel(int width);
extern uint16_t arm_cv_get_scratch_size_canny_sobel(int width);

/**
* @brief Canny edge with sobel integrated
Expand All @@ -56,9 +56,9 @@ uint16_t arm_cv_get_scratch_size_canny_sobel(int width);
*/
extern void arm_cv_canny_edge_sobel(const arm_cv_image_gray8_t* ImageIn,
arm_cv_image_gray8_t* ImageOut,
q15_t* Buffer,
uint8_t low_threshold,
uint8_t high_threshold);
q15_t* scratch,
uint8_t lowThreshold,
uint8_t highThreshold);

#ifdef __cplusplus
}
Expand Down
28 changes: 15 additions & 13 deletions Source/FeatureDetection/arm_cannysobel.c
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/

#include "cv/feature_detection.h"
#include "dsp/basic_math_functions.h"
#include "dsp/fast_math_functions.h"
Expand Down Expand Up @@ -112,7 +111,7 @@ The different values of x are angle dependent see helper below, and relative to
} \
continue;

//Helpers for different decision
// Helpers for different decision
#define VERTICAL_CASE(threshold, width, datain, dataout, idx, mag, col, row) \
DECISION(2, 2, 3, 3, 3, 1, 1, 1, 1, threshold, width, datain, dataout, idx, mag, col, row)
#define DIAGONAL_45_CASE(threshold, width, datain, dataout, idx, mag, col, row) \
Expand Down Expand Up @@ -187,7 +186,7 @@ The different values of x are angle dependent see helper below, and relative to
*/
uint16_t arm_cv_get_scratch_size_canny_sobel(int width)
{
return ((NB_LINE_BUF + 2*NB_LINE_BUF + 2*NB_LINE_BUF) * width * sizeof(q15_t));
return ((NB_LINE_BUF + 2 * NB_LINE_BUF + 2 * NB_LINE_BUF) * width * sizeof(q15_t));
}

#if defined(ARM_MATH_MVEI) && !defined(ARM_MATH_AUTOVECTORIZE)
Expand Down Expand Up @@ -366,6 +365,7 @@ static void arm_cv_compute_buffer_line_canny_sobel(const arm_cv_image_gray8_t *i
uint8_t *data_in = imageIn->pData;
uint8_t *data_out = imageOut->pData;

grad2[xm * width].x = 0;
grad2[xm * width].y =
Q5_10_TO_Q15((data_in[(rowIdx - 1) * width] + (data_in[rowIdx * width] << 1) + data_in[(rowIdx + 1) * width]));
data_out[(rowIdx - 1) * width] = 0;
Expand All @@ -378,7 +378,6 @@ static void arm_cv_compute_buffer_line_canny_sobel(const arm_cv_image_gray8_t *i
grad2[xm * width + y].x =
Q5_10_TO_Q15(data_in[rowIdx * width + (y - 1)] + (data_in[rowIdx * width + (y)] << 1) +
data_in[rowIdx * width + (y + 1)]);

q15_t gradx = grad2[((rowIdx - 2) % NB_LINE_BUF) * width + y].x - grad2[(xm)*width + y].x;
q15_t grady = grad2[((rowIdx - 1) % NB_LINE_BUF) * width + (y - 1)].y -
grad2[((rowIdx - 1) % NB_LINE_BUF) * width + (y + 1)].y;
Expand All @@ -401,6 +400,7 @@ static void arm_cv_compute_buffer_line_canny_sobel(const arm_cv_image_gray8_t *i
grad1[(rowIdx - 1) % NB_LINE_BUF * width + y].x = gradx;
magOut[(rowIdx - 1) % NB_LINE_BUF * width + y] = (q15_t)out;
}
grad2[xm * width].x = 0;
grad2[xm * width + width - 1].y =
Q5_10_TO_Q15(data_in[(rowIdx - 1) * width + width - 1] + (data_in[rowIdx * width + width - 1] << 1) +
data_in[(rowIdx + 1) * width + width - 1]);
Expand All @@ -422,9 +422,9 @@ static void arm_cv_compute_buffer_line_canny_sobel(const arm_cv_image_gray8_t *i
*
* @par Temporary buffer sizing:
*
* Will use a temporary buffer to store intermediate values of gradient and magnitude.
*
* Size of temporary buffer is given by
* Will use a temporary buffer to store intermediate values of gradient and magnitude.
*
* Size of temporary buffer is given by
* arm_cv_get_scratch_size_canny_sobel(int width)
*/
#if defined(ARM_MATH_MVEI) && !defined(ARM_MATH_AUTOVECTORIZE)
Expand Down Expand Up @@ -502,7 +502,8 @@ void arm_cv_canny_edge_sobel(const arm_cv_image_gray8_t *imageIn, arm_cv_image_g
x = 1;
data_grad2[x * width].x = 0;
data_out[x * width] = 0;
data_grad2[x * width].y = (data_in[(x - 1) * width] + (data_in[x * width] << 1) + data_in[(x + 1) * width]) << 5;
data_grad2[x * width].y =
Q5_10_TO_Q15(data_in[(x - 1) * width] + (data_in[x * width] << 1) + data_in[(x + 1) * width]);
for (int y = 1; y < ((width) >> 4) + 1; y++)
{
int idx = width + ((y - 1) << 4) + 1;
Expand Down Expand Up @@ -691,9 +692,9 @@ void arm_cv_canny_edge_sobel(const arm_cv_image_gray8_t *imageIn, arm_cv_image_g
q31_t low_threshold = U8_TO_Q2_13(lowThreshold);
q31_t high_threshold = U8_TO_Q2_13(highThreshold);

arm_cv_gradient_q15_t *data_grad2 = (arm_cv_gradient_q15_t *)&scratch[NB_LINE_BUF * width];
q15_t *data_mag = scratch;
arm_cv_gradient_q15_t *data_grad1 = (arm_cv_gradient_q15_t *)&scratch[3 * NB_LINE_BUF * width];
arm_cv_gradient_q15_t *data_grad2 = (arm_cv_gradient_q15_t *)&scratch[NB_LINE_BUF * width];
q15_t *data_mag = scratch;
uint8_t *data_in = imageIn->pData;
uint8_t *data_out = imageOut->pData;
int x = 0;
Expand All @@ -713,7 +714,8 @@ void arm_cv_canny_edge_sobel(const arm_cv_image_gray8_t *imageIn, arm_cv_image_g
}
data_out[x * width + width - 1] = 0;
x = 1;
data_grad2[x * width].y = (data_in[(x - 1) * width] + (data_in[x * width] << 1) + data_in[(x + 1) * width]);
data_grad2[x * width].y =
Q5_10_TO_Q15(data_in[(x - 1) * width] + (data_in[x * width] << 1) + data_in[(x + 1) * width]);
data_out[x * width] = 0;
for (int y = 1; y < width - 1; y++)
{
Expand Down Expand Up @@ -755,7 +757,7 @@ void arm_cv_canny_edge_sobel(const arm_cv_image_gray8_t *imageIn, arm_cv_image_g
}
// last line
x = imageIn->height;
data_out[x * width] = 0;
data_out[(x - 1) * width] = 0;
for (int y = 1; y < width - 1; y++)
{
int idx = (x - 2) * width + y;
Expand All @@ -780,6 +782,6 @@ void arm_cv_canny_edge_sobel(const arm_cv_image_gray8_t *imageIn, arm_cv_image_g
THRESHOLDING_HYSTERESIS_BOTTOM_BORDER(angle, high_threshold, width, data_mag, data_out, idx, mag, x, y)
}
}
data_out[x * width + width - 1] = 0;
data_out[(x - 1) * width + width - 1] = 0;
}
#endif
Binary file modified Testing/board/RefPatterns/test_110_img_0.tiff
Binary file not shown.
Binary file modified Testing/board/RefPatterns/test_113_img_0.tiff
Binary file not shown.
Binary file modified Testing/board/RefPatterns/test_131_img_0.tiff
Binary file not shown.
Binary file modified Testing/board/RefPatterns/test_134_img_0.tiff
Binary file not shown.
Binary file modified Testing/board/RefPatterns/test_135_img_0.tiff
Binary file not shown.
Binary file modified Testing/board/RefPatterns/test_13_img_0.tiff
Binary file not shown.
Binary file modified Testing/board/RefPatterns/test_152_img_0.tiff
Binary file not shown.
Binary file modified Testing/board/RefPatterns/test_156_img_0.tiff
Binary file not shown.
Binary file modified Testing/board/RefPatterns/test_164_img_0.tiff
Binary file not shown.
Binary file modified Testing/board/RefPatterns/test_168_img_0.tiff
Binary file not shown.
Binary file modified Testing/board/RefPatterns/test_173_img_0.tiff
Binary file not shown.
Binary file modified Testing/board/RefPatterns/test_177_img_0.tiff
Binary file not shown.
Binary file modified Testing/board/RefPatterns/test_185_img_0.tiff
Binary file not shown.
Binary file modified Testing/board/RefPatterns/test_18_img_0.tiff
Binary file not shown.
Binary file modified Testing/board/RefPatterns/test_190_img_0.tiff
Binary file not shown.
Binary file modified Testing/board/RefPatterns/test_191_img_0.tiff
Binary file not shown.
Binary file modified Testing/board/RefPatterns/test_194_img_0.tiff
Binary file not shown.
Binary file modified Testing/board/RefPatterns/test_210_img_0.tiff
Binary file not shown.
Binary file modified Testing/board/RefPatterns/test_215_img_0.tiff
Binary file not shown.
Binary file modified Testing/board/RefPatterns/test_23_img_0.tiff
Binary file not shown.
Binary file modified Testing/board/RefPatterns/test_24_img_0.tiff
Binary file not shown.
Binary file modified Testing/board/RefPatterns/test_25_img_0.tiff
Binary file not shown.
Binary file modified Testing/board/RefPatterns/test_30_img_0.tiff
Binary file not shown.
Binary file modified Testing/board/RefPatterns/test_38_img_0.tiff
Binary file not shown.
Binary file modified Testing/board/RefPatterns/test_42_img_0.tiff
Binary file not shown.
Binary file modified Testing/board/RefPatterns/test_43_img_0.tiff
Binary file not shown.
Binary file modified Testing/board/RefPatterns/test_44_img_0.tiff
Binary file not shown.
Binary file modified Testing/board/RefPatterns/test_46_img_0.tiff
Binary file not shown.
Binary file modified Testing/board/RefPatterns/test_47_img_0.tiff
Binary file not shown.
Binary file modified Testing/board/RefPatterns/test_51_img_0.tiff
Binary file not shown.
Binary file modified Testing/board/RefPatterns/test_67_img_0.tiff
Binary file not shown.
Binary file modified Testing/board/RefPatterns/test_68_img_0.tiff
Binary file not shown.
Binary file modified Testing/board/RefPatterns/test_84_img_0.tiff
Binary file not shown.
Binary file modified Testing/board/RefPatterns/test_86_img_0.tiff
Binary file not shown.
Binary file modified Testing/board/RefPatterns/test_89_img_0.tiff
Binary file not shown.
4 changes: 2 additions & 2 deletions Testing/board/scripts/details/description.py
Original file line number Diff line number Diff line change
Expand Up @@ -106,10 +106,10 @@ def canny_sobel_test(imgid, imgdim, funcid=2, img_type="gray8"):
"check" : SimilarImage(1)
}

def canny_sobel_test_autoref(imgid, imgdim, funcid=2, img_type="gray8"):
def canny_sobel_test_autoref(imgid, imgdim, funcid=0, img_type="gray8"):
return {"desc":f"Gauss {img_type} image {imgdim[0]}x{imgdim[1]}",
"funcid": funcid,
"useimg": [imgid],
"reference": CannyEdgeAutoRef(),
"check" : SimilarImage(1)
"check" : SimilarTensorFixp(0)
}
53 changes: 1 addition & 52 deletions Testing/board/scripts/details/testing.py
Original file line number Diff line number Diff line change
Expand Up @@ -140,55 +140,4 @@ def __call__(self,ref,result):

return False
return(True)

class SimilarImage(Comparison):
def __init__(self,t=0):
super().__init__()

self._t = t

def __call__(self,ref,result):
for s,d in zip(ref,result):
st = s.tensor
dt = d.tensor
# Cast to signed so that the difference below is giving
# the right value
if st.dtype == np.uint8:
st = st.astype(dtype=np.int16)
dt = dt.astype(dtype=np.int16)
if st.dtype == np.uint16:
st = st.astype(dtype=np.int32)
dt = dt.astype(dtype=np.int32)
if st.dtype == np.uint32:
st = st.astype(dtype=np.int64)
dt = dt.astype(dtype=np.int64)

diff = np.abs(st-dt)
errorVal = np.max(diff)
if errorVal > self._t:
MAXNB = 10
self.add_error(f"Different tensors. Max error = {errorVal}")
tooBig = diff > self._t
# Remove the channel to get the indice of the pixel
# and remove duplicates in case there may be errors for
# several channels of the same pixel
tooBigPos = list(np.argwhere(tooBig))
indices = list(set([tuple(x) for x in tooBigPos]))

allErrors = [diff[x] for x in indices]
nb_errors = len(allErrors)
indices = indices[:MAXNB]
allErrors = allErrors[:MAXNB]

ref = [st[x] for x in indices]
result = [dt[x] for x in indices]

ref=ref[:MAXNB]
result=result[:MAXNB]
if nb_errors > 10:
self.add_error(f"Latest {MAXNB} error indices: {indices}")
self.add_error(f"References : {ref}")
self.add_error(f"Results : {result}")
self.add_error(f"Number of errors : {nb_errors}")
return False
return(True)

34 changes: 17 additions & 17 deletions Testing/board/test_desc.py
Original file line number Diff line number Diff line change
Expand Up @@ -159,22 +159,22 @@
path="Patterns/Ruler.tiff"),
],
"tests":
[canny_sobel_test_autoref(imgid, imgdim, funcid=1) for imgid,imgdim in enumerate(STANDARD_IMG_SIZES)]+
[canny_sobel_test_autoref(0+len(STANDARD_IMG_SIZES), [512,512], funcid=1)]+
[canny_sobel_test_autoref(1+len(STANDARD_IMG_SIZES), [64,64], funcid=1)]+
[canny_sobel_test_autoref(2+len(STANDARD_IMG_SIZES), [500,500], funcid=1)]+
[canny_sobel_test_autoref(3+len(STANDARD_IMG_SIZES), [250,250], funcid=1)]+
[canny_sobel_test_autoref(4+len(STANDARD_IMG_SIZES), [200,200], funcid=1)]+
[canny_sobel_test_autoref(imgid+4+len(STANDARD_IMG_SIZES), imgdim, funcid=1) for imgid,imgdim in enumerate(STANDARD_IMG_SIZES)]+
[canny_sobel_test_autoref(imgid+4+2*len(STANDARD_IMG_SIZES), imgdim, funcid=1) for imgid,imgdim in enumerate(STANDARD_IMG_SIZES)]+
[canny_sobel_test_autoref(imgid+4+3*len(STANDARD_IMG_SIZES), imgdim, funcid=1) for imgid,imgdim in enumerate(STANDARD_IMG_SIZES)]+
[canny_sobel_test_autoref(imgid+4+4*len(STANDARD_IMG_SIZES), imgdim, funcid=1) for imgid,imgdim in enumerate(STANDARD_IMG_SIZES)]+
[canny_sobel_test_autoref(imgid+4+5*len(STANDARD_IMG_SIZES), imgdim, funcid=1) for imgid,imgdim in enumerate(STANDARD_IMG_SIZES)]+
[canny_sobel_test_autoref(imgid+4+6*len(STANDARD_IMG_SIZES), imgdim, funcid=1) for imgid,imgdim in enumerate(STANDARD_IMG_SIZES)]+
[canny_sobel_test_autoref(imgid+4+7*len(STANDARD_IMG_SIZES), imgdim, funcid=1) for imgid,imgdim in enumerate(STANDARD_IMG_SIZES)]+
[canny_sobel_test_autoref(imgid+4+8*len(STANDARD_IMG_SIZES), imgdim, funcid=1) for imgid,imgdim in enumerate(STANDARD_IMG_SIZES)]+
[canny_sobel_test_autoref(imgid+4+9*len(STANDARD_IMG_SIZES), imgdim, funcid=1) for imgid,imgdim in enumerate(STANDARD_IMG_SIZES)]+
[canny_sobel_test_autoref(imgid+4+10*len(STANDARD_IMG_SIZES), imgdim, funcid=1) for imgid,imgdim in enumerate(STANDARD_IMG_SIZES)]
[canny_sobel_test_autoref(imgid, imgdim) for imgid,imgdim in enumerate(STANDARD_IMG_SIZES)]+
[canny_sobel_test_autoref(0+len(STANDARD_IMG_SIZES), [512,512])]+
[canny_sobel_test_autoref(1+len(STANDARD_IMG_SIZES), [64,64])]+
[canny_sobel_test_autoref(2+len(STANDARD_IMG_SIZES), [500,500])]+
[canny_sobel_test_autoref(3+len(STANDARD_IMG_SIZES), [250,250])]+
[canny_sobel_test_autoref(4+len(STANDARD_IMG_SIZES), [200,200])]+
[canny_sobel_test_autoref(imgid+5+len(STANDARD_IMG_SIZES), imgdim) for imgid,imgdim in enumerate(STANDARD_IMG_SIZES)]+
[canny_sobel_test_autoref(imgid+5+2*len(STANDARD_IMG_SIZES), imgdim) for imgid,imgdim in enumerate(STANDARD_IMG_SIZES)]+
[canny_sobel_test_autoref(imgid+5+3*len(STANDARD_IMG_SIZES), imgdim) for imgid,imgdim in enumerate(STANDARD_IMG_SIZES)]+
[canny_sobel_test_autoref(imgid+5+4*len(STANDARD_IMG_SIZES), imgdim) for imgid,imgdim in enumerate(STANDARD_IMG_SIZES)]+
[canny_sobel_test_autoref(imgid+5+5*len(STANDARD_IMG_SIZES), imgdim) for imgid,imgdim in enumerate(STANDARD_IMG_SIZES)]+
[canny_sobel_test_autoref(imgid+5+6*len(STANDARD_IMG_SIZES), imgdim) for imgid,imgdim in enumerate(STANDARD_IMG_SIZES)]+
[canny_sobel_test_autoref(imgid+5+7*len(STANDARD_IMG_SIZES), imgdim) for imgid,imgdim in enumerate(STANDARD_IMG_SIZES)]+
[canny_sobel_test_autoref(imgid+5+8*len(STANDARD_IMG_SIZES), imgdim) for imgid,imgdim in enumerate(STANDARD_IMG_SIZES)]+
[canny_sobel_test_autoref(imgid+5+9*len(STANDARD_IMG_SIZES), imgdim) for imgid,imgdim in enumerate(STANDARD_IMG_SIZES)]+
[canny_sobel_test_autoref(imgid+5+10*len(STANDARD_IMG_SIZES), imgdim) for imgid,imgdim in enumerate(STANDARD_IMG_SIZES)]
},
]

Expand All @@ -189,5 +189,5 @@
format=Format.GRAY8,
path="Patterns/Mandrill.tiff")],
"reference": CannyEdgeAutoRef(),
"check" : SimilarImage(1)
"check" : SimilarTensorFixp(1)
}

0 comments on commit 9424e4e

Please sign in to comment.