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 353ceed
Show file tree
Hide file tree
Showing 40 changed files with 42 additions and 93 deletions.
6 changes: 3 additions & 3 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 @@ -57,8 +57,8 @@ 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);
uint8_t lowThreshold,
uint8_t highThreshold);

#ifdef __cplusplus
}
Expand Down
38 changes: 19 additions & 19 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 All @@ -44,7 +43,7 @@ Macro that implement core operation of threshold and hysteresis for the canny ed
The different values of x are angle dependent see helper below, and relative to the 8 neighboring pixels
*/
#define DECISION(x0, x1, x2, x3, x4, x5, x6, x7, y0, thresh, width, datain, dataout, offs, mag, col, row) \
if (mag <= datain[((col - x0) % NB_LINE_BUF) * width + row - y0] || \
if (mag <= datain[((col - x0) % NB_LINE_BUF) * width + row - y0] || \
mag <= datain[((col - x1) % NB_LINE_BUF) * width + row + y0]) \
{ \
dataout[offs] = 0; \
Expand Down Expand Up @@ -79,7 +78,7 @@ The different values of x are angle dependent see helper below, and relative to
continue;

#define DECISION_LAST(x0, x2, x3, x4, x5, x6, x7, y0, thresh, width, datain, dataout, offs, mag, col, row) \
if (mag <= datain[((col - x0) % NB_LINE_BUF) * width + row - y0]) \
if (mag <= datain[((col - x0) % NB_LINE_BUF) * width + row - y0]) \
{ \
dataout[offs] = 0; \
continue; \
Expand Down Expand Up @@ -132,7 +131,7 @@ The different values of x are angle dependent see helper below, and relative to
DECISION_LAST(1, 1, 1, 2, 2, 1, 1, -1, threshold, width, datain, dataout, idx, mag, col, row)

#define THRESHOLDING_HYSTERESIS(angle, thresh, width, data_mag, data_out, idx, mag, x, y) \
if ((angle) < (DEG_TO_RAD_Q2_13(22))) \
if ((angle) < (DEG_TO_RAD_Q2_13(22))) \
{ \
VERTICAL_CASE(thresh, width, data_mag, data_out, idx, mag, x, y) \
} \
Expand All @@ -154,7 +153,7 @@ The different values of x are angle dependent see helper below, and relative to
}

#define THRESHOLDING_HYSTERESIS_BOTTOM_BORDER(angle, thresh, width, data_mag, data_out, idx, mag, x, y) \
if ((angle) < (DEG_TO_RAD_Q2_13(22))) \
if ((angle) < (DEG_TO_RAD_Q2_13(22))) \
{ \
VERTICAL_CASE_BOT_BORDER(thresh, width, data_mag, data_out, idx, mag, x, y) \
} \
Expand Down Expand Up @@ -312,7 +311,7 @@ static void arm_cv_gradient_magnitude_tail(int rowIdx, int rowIdxOut, int width,
uint8_t *data_in = imageIn->pData;
for (int y = MASK_16(width - 1); y < width; y++)
{
if ((y == 0 || y == width - 1) && rowIdx != 0 && rowIdx != imageIn->height - 1)
if ((y == 0 || y == width - 1) && rowIdx != 0 && rowIdx != imageIn->height - 1)
{
dataGrad2[rowIdxOut * width + y].y =
Q5_10_TO_Q15(data_in[(rowIdx - 1) * width + y] + (data_in[rowIdx * width + y] << 1) +
Expand All @@ -321,7 +320,7 @@ static void arm_cv_gradient_magnitude_tail(int rowIdx, int rowIdxOut, int width,
dataOut[rowIdx * width + y] = 0;
continue;
}
if (rowIdx == 0 || y == 0 || y == width - 1)
if (rowIdx == 0 || y == 0 || y == width - 1)
{
magOut[((((rowIdx - 1) % NB_LINE_BUF * width)) + y)] = 0;
dataOut[rowIdx * width + y] = 0;
Expand All @@ -332,7 +331,7 @@ static void arm_cv_gradient_magnitude_tail(int rowIdx, int rowIdxOut, int width,
dataGrad2[rowIdxOut * 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)]);
if (rowIdx == 1)
if (rowIdx == 1)
{
continue;
}
Expand All @@ -341,7 +340,7 @@ static void arm_cv_gradient_magnitude_tail(int rowIdx, int rowIdxOut, int width,
dataGrad2[(rowIdx - 1) % NB_LINE_BUF * width + (y + 1)].y;
dataGrad1[(rowIdx - 1) % NB_LINE_BUF * width + y].x = gradx;
dataGrad1[(rowIdx - 1) % NB_LINE_BUF * width + y].y = grady;
if (gradx == 0 && grady == 0)
if (gradx == 0 && grady == 0)
{
magOut[((((rowIdx - 1) % NB_LINE_BUF * width)) + y)] = 0;
dataOut[(rowIdx - 1) * width + y] = 0;
Expand All @@ -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,11 +378,10 @@ 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;
if (gradx == 0 && grady == 0)
if (gradx == 0 && grady == 0)
{
int idxp = (rowIdx - 1) % NB_LINE_BUF * width + y;

Expand All @@ -399,8 +398,9 @@ static void arm_cv_compute_buffer_line_canny_sobel(const arm_cv_image_gray8_t *i
out = Q31_TO_Q15(root);
grad1[(rowIdx - 1) % NB_LINE_BUF * width + y].y = grady;
grad1[(rowIdx - 1) % NB_LINE_BUF * width + y].x = gradx;
magOut[(rowIdx - 1) % NB_LINE_BUF * width + y] = (q15_t)out;
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 Down Expand Up @@ -502,7 +502,7 @@ 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 @@ -543,7 +543,7 @@ void arm_cv_canny_edge_sobel(const arm_cv_image_gray8_t *imageIn, arm_cv_image_g
// Tail
arm_cv_gradient_magnitude_tail(x, x3, width, data_grad1, data_grad2, imageIn, data_mag, data_out);
}
// Core loop
// Core loop
for (int x = 3; x < imageIn->height; x++)
{
int x3 = x % NB_LINE_BUF;
Expand Down Expand Up @@ -713,7 +713,7 @@ 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 All @@ -729,7 +729,7 @@ void arm_cv_canny_edge_sobel(const arm_cv_image_gray8_t *imageIn, arm_cv_image_g
x = 2;
// first line
arm_cv_compute_buffer_line_canny_sobel(imageIn, imageOut, data_grad1, data_grad2, data_mag, x);
// core loop
// core loop
for (int x = 3; x < imageIn->height; x++)
{
arm_cv_compute_buffer_line_canny_sobel(imageIn, imageOut, data_grad1, data_grad2, data_mag, x);
Expand All @@ -755,10 +755,10 @@ 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;
int idx = (x - 2) * width + y;
int mag = data_mag[((x - 2) % NB_LINE_BUF) * (width) + y];
data_out[idx + width] = 0;
if (mag < low_threshold)
Expand All @@ -780,6 +780,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 353ceed

Please sign in to comment.