int compare_vbx_lbp_ci_to_scalar_patterns(unsigned short* img, int width, int height, int max_print_errors) { int j, errors = 0; unsigned char** scalar_patterns = test_scalar_patterns(img, 0, width, height); vbx_ubyte_t* v_in = (vbx_ubyte_t*)vbx_sp_malloc(3*width*sizeof(vbx_word_t)); vbx_ubyte_t* v_top = (vbx_byte_t*)vbx_sp_malloc(width*sizeof(vbx_byte_t)); vbx_ubyte_t* v_bot = (vbx_byte_t*)vbx_sp_malloc(width*sizeof(vbx_byte_t)); vbx_ubyte_t* v_lbp = v_bot; unsigned char* lbp = (unsigned char*)vbx_shared_malloc(width*sizeof(unsigned char)); vbx_set_vl(width); for(j=0; j < height - 2; j++){ vbx_dma_to_vector(v_in, img+j*width, 3*width*sizeof(unsigned char)); vbx(VVHU, VCUSTOM1, v_top, v_in, v_in+width); vbx(VVHU, VCUSTOM1, v_bot, v_in+width, v_in+2*width); vbx(SVHBU, VAND, v_top, 0xf0, v_top); vbx(SVHBU, VAND, v_bot, 0x0f, v_bot); vbx(VVBU, VADD, v_lbp, v_bot, v_top); vbx_dma_to_host(lbp, v_lbp, width*sizeof(unsigned char)); vbx_sync(); errors = match_array_byte(lbp, scalar_patterns[0]+j*width, "custom_lbp", width-2, 1, max_print_errors, 1, j); } vbx_sp_free(); vbx_shared_free(lbp); return errors; }
int compare_vbx_lut_to_vbx_lut_ci(int sz, int max_print_errors) { int f, n, errors; vbx_byte_t* v_pass = (vbx_byte_t*)vbx_sp_malloc(sz*sizeof(vbx_byte_t)); vbx_ubyte_t* v_pattern = (vbx_ubyte_t*)vbx_sp_malloc(sz*sizeof(vbx_byte_t)); vbx_ubyte_t* v_lutc = (vbx_ubyte_t*)vbx_sp_malloc(sz*sizeof(vbx_byte_t)); vbx_ubyte_t* v_group = (vbx_ubyte_t*)vbx_sp_malloc(sz*sizeof(vbx_byte_t)); vbx_ubyte_t* v_sel = (vbx_ubyte_t*)vbx_sp_malloc(sz*sizeof(vbx_byte_t)); vbx_ubyte_t* v_lut = (vbx_ubyte_t*)vbx_sp_malloc(sz*sizeof(vbx_word_t)); vbx_ubyte_t* v_idx = (vbx_ubyte_t*)vbx_sp_malloc(sz*sizeof(vbx_word_t)); unsigned char* lut = (unsigned char*)vbx_shared_malloc(sz*sizeof(unsigned char)); unsigned char* lut_c = (unsigned char*)vbx_shared_malloc(sz*sizeof(unsigned char)); for (n = 0; n < sz; n++) { v_pattern[n] = n & 0xff; } int s, stage = 11; for (f = 0; f < face_lbp[stage].count; f++) { lbp_feat_t feat = face_lbp[stage].feats[f]; vbx_set_vl(sz); int total = f; s = 0; while(s < stage){ total += face_lbp[s].count; s++; } vbx(SVBU, VCUSTOM0, v_lutc, total, v_pattern); vbx(SVB, VMOV, v_pass, feat.fail, 0); /* check if pattern is in lut */ vbx(SVBU, VSHR, v_group, 5, v_pattern); for (n = 0; n < 8; n++) { vbx(SVB, VADD, v_sel, -n, v_group); vbx(SVBW, VCMV_Z, v_lut, feat.lut[n], v_sel); } vbx(SVBWU, VAND, v_idx, 0x1f, v_pattern); vbx(VVWB, VSHR, v_lut, v_idx, v_lut); vbx(SVB, VAND, v_lut, 1, v_lut); vbx(SVB, VCMV_LEZ, v_pass, feat.pass, v_lut); vbx_dma_to_host(lut_c, v_lutc, sz*sizeof(unsigned char)); vbx_dma_to_host(lut, v_pass, sz*sizeof(unsigned char)); vbx_sync(); errors = match_array_byte(lut_c, lut, "custom_lut", sz, 1, max_print_errors, 0, 0); } vbx_sp_free(); vbx_shared_free(lut); vbx_shared_free(lut_c); return errors; }
int compare_ScalarLBPRestrictedPatterns_to_SATBinaryPattern(unsigned short *vbx_img, int log, int width, int height, int max_print_errors) { int l, i, j, cell, errors = 0; /* generate patterns */ unsigned short **sums = ScalarLBPRestrictedSums(vbx_img, width, height, log); unsigned char **patterns = ScalarLBPRestrictedPatterns(sums, width, height, log); unsigned char **sat_patterns = (unsigned char**)vbx_shared_malloc((log+1)*sizeof(unsigned char*)); for (l=0; l<log+1; l++) { sat_patterns[l] = (unsigned char*)vbx_shared_malloc(width*height*sizeof(unsigned char)); } unsigned int *iImg, *iiImg; iImg = (unsigned int *)vbx_shared_malloc(width*height*sizeof(unsigned int)); iiImg = (unsigned int *)vbx_shared_malloc(width*height*sizeof(unsigned int)); gen_integrals(vbx_img, iImg, iiImg, width, height); image_t lbp_img = {iImg, {width, height}}; for (l=0; l<log+1; l++) { cell = 1 << l; lbp_feat_t lbp_feat = {{{0, 0}, {cell, cell}}, 0, 0, {0, 0, 0, 0, 0, 0, 0, 0}}; for (j = 0; j < height - (3*cell-1); j++) { for (i = 0; i < width - (3*cell-1); i++) { pair_t lbp_p = {i, j}; sat_patterns[l][j*width+i] = SATBinaryPattern(lbp_img, &lbp_feat, lbp_p); } } } /* test patterns vs sat binary patterns */ for (l=0; l<log+1; l++) { cell = 1 << l; for (j = 0; j < height - (3*cell-1); j++) { errors += match_array_byte(patterns[l] + j*width, sat_patterns[l] + j*width, "patterns", width - (3*cell-1), 1, 0, max_print_errors, 1, j); if (errors > max_print_errors){ max_print_errors = 0; } } } return errors; }
int compare_LBPRestrictedSums_to_test_scalar_sums_byte(unsigned short* vbx_img, int log, int width, int height, int max_print_errors) { int cell, errors = 0; int i, j; /* generate sums */ unsigned char **sums = LBPRestrictedSums(vbx_img, width, height, log); unsigned char **scalar_sums = test_scalar_sums_byte(vbx_img, log, width, height); /* test sums vs scalar sums */ for (j=0; j<log+1; j++) { cell = 1 << j; for (i = 0; i < height - (cell-1); i++) { errors += match_array_byte(scalar_sums[j]+i*width, sums[j]+i*width, "sum", width - (cell-1), 1, 0, max_print_errors, 0, i); if (errors > max_print_errors){ max_print_errors = 0; } } } return errors; }
int compare_LBPRestricted_to_test_scalar_patterns(unsigned short* vbx_img, int log, int width, int height, int max_print_errors) { int j, l, cell, errors = 0; /* generate patterns */ unsigned char **patterns = LBPRestricted(vbx_img, width, height, log); unsigned char** scalar_patterns = test_scalar_patterns(vbx_img, log, width, height); /* test sums vs scalar sums */ for (l=0; l<log+1; l++) { cell = 1 << l; for (j = 0; j < height - (3*cell-1); j++) { errors += match_array_byte(scalar_patterns[l]+j*width, patterns[l]+j*width, "restricted patterns", width - (3*cell-1), 1, 0, max_print_errors, 1, j); if(errors > max_print_errors) { max_print_errors = 0; } } } return errors; }
int compare_ScalarLBPRestrictedPatterns_to_test_scalar_patterns(unsigned short* vbx_img, int log, int width, int height, int max_print_errors) { int i, j, cell, errors = 0; /* generate patterns */ unsigned short **sums = ScalarLBPRestrictedSums(vbx_img, width, height, log); unsigned char **patterns = ScalarLBPRestrictedPatterns(sums, width, height, log); unsigned char** scalar_patterns = test_scalar_patterns(vbx_img, log, width, height); /* test patterns vs scalar patterns */ for (j=0; j<log+1; j++) { cell = 1 << j; for (i = 0; i < height - (3*cell-1); i++) { errors += match_array_byte(scalar_patterns[j] + i*width, patterns[j] + i*width, "patterns", width - (3*cell-1), 1, 0, max_print_errors, 1, i); if (errors > max_print_errors){ max_print_errors = 0; } } } return errors; }
int compare_vbx_lbp_ci_to_scalar_patterns(unsigned short* img, int log, int width, int height, int max_print_errors) { int j, l, cell, max_cell, errors = 0; unsigned char** scalar_patterns = test_scalar_patterns(img, log, width, height); max_cell = 1<<log; vbx_uhalf_t* v_in = (vbx_uhalf_t*)vbx_sp_malloc((1+2*max_cell)*width*sizeof(vbx_half_t)); vbx_uhalf_t* v_top = (vbx_half_t*)vbx_sp_malloc(width*sizeof(vbx_half_t)); vbx_uhalf_t* v_bot = (vbx_half_t*)vbx_sp_malloc(width*sizeof(vbx_half_t)); vbx_ubyte_t* v_lbp = (vbx_ubyte_t*)v_bot; unsigned char* lbp = (unsigned char*)vbx_shared_malloc(width*sizeof(unsigned char)); vbx_set_vl(width); for(l = 0; l < 1; l++){ cell = 1<<l; for(j=0; j < height - 2*cell; j++){ vbx_dma_to_vector(v_in, img+j*width, (1+2*cell)*width*sizeof(unsigned short)); vbx(VVHU, VCUSTOM1, v_top, v_in, v_in+(1*cell)*width); vbx(VVHU, VCUSTOM1, v_bot, v_in+(1*cell)*width, v_in+(2*cell)*width); vbx(SVHBU, VAND, (vbx_ubyte_t*)v_top, 0xf0, v_top); vbx(SVHBU, VAND, (vbx_ubyte_t*)v_bot, 0x0f, v_bot); vbx(VVBU, VADD, v_lbp, v_bot, v_top); vbx_dma_to_host(lbp, v_lbp, width*sizeof(unsigned char)); vbx_sync(); errors += match_array_byte(lbp, scalar_patterns[l]+j*width, "custom_lbp", width-2*cell, 1, 0, max_print_errors, 1, j); if (errors > max_print_errors){ max_print_errors = 0; } } } vbx_sp_free(); vbx_shared_free(lbp); return errors; }
int compare_LBPRestrictedCI_to_test_scalar_patterns(unsigned short* vbx_img, unsigned char* vbx_img8, int log, int width, int height, int max_print_errors) { int i, j, l, cell, errors = 0, cell_errors, row_errors; /* generate patterns */ unsigned char **patterns = (unsigned char**)malloc((log+1)*sizeof(unsigned char*)); for (l=0; l<log+1; l++) { patterns[l] = (unsigned char*)vbx_shared_malloc(height*width*sizeof(unsigned char)); } /* LBPRestrictedCI28(patterns, vbx_img8, width, height, log); */ LBPRestricted_CI_column_8(patterns, vbx_img8, width, height, log); /* LBPRestricted_CI_column_8_scratch(patterns, vbx_img8, width, height, log); */ unsigned char **scalar_patterns = test_scalar_patterns(vbx_img, log, width, height); /* test sums vs scalar sums */ for (l=0; l<log+1; l++) { cell = 1 << l; cell_errors = 0; printf("Testing cell %d\n", cell); for (j = 0; j < height - (3*cell-1); j++) { row_errors = match_array_byte(scalar_patterns[l]+j*width, patterns[l]+j*width, "restricted patterns", width - (3*cell-1), 1, 0, max_print_errors, 1, j); if (row_errors) { printf("errors in row %d\n", j); } cell_errors += row_errors; errors += row_errors; if(errors > max_print_errors) { max_print_errors = 0; } } printf("Total errors: %d\n\n", cell_errors); } return errors; }
int compare_vbx_lut_to_vbx_lut_ci(int stage, int max_print_errors) { vbx_mxp_t *this_mxp = VBX_GET_THIS_MXP(); int vci_lanes = this_mxp->vcustom0_lanes; int sz = this_mxp->scratchpad_size/(16*sizeof(vbx_ubyte_t)); vbx_byte_t* v_pass = (vbx_byte_t*)vbx_sp_malloc(sz*sizeof(vbx_byte_t)); vbx_ubyte_t* v_pattern = (vbx_ubyte_t*)vbx_sp_malloc(sz*sizeof(vbx_byte_t)); vbx_ubyte_t* v_lutc = (vbx_ubyte_t*)vbx_sp_malloc(sz*sizeof(vbx_byte_t)); vbx_ubyte_t* v_group = (vbx_ubyte_t*)vbx_sp_malloc(sz*sizeof(vbx_byte_t)); vbx_ubyte_t* v_sel = (vbx_ubyte_t*)vbx_sp_malloc(sz*sizeof(vbx_byte_t)); vbx_ubyte_t* v_lut = (vbx_ubyte_t*)vbx_sp_malloc(sz*sizeof(vbx_word_t)); vbx_ubyte_t* v_idx = (vbx_ubyte_t*)vbx_sp_malloc(sz*sizeof(vbx_word_t)); if(v_idx == NULL) { printf("failed to allocate in compare_vbx_lut_to_vbx_lut_ci\n"); } unsigned char* lut = (unsigned char*)vbx_shared_malloc(sz*sizeof(unsigned char)); unsigned char* lut_c = (unsigned char*)vbx_shared_malloc(sz*sizeof(unsigned char)); int f, n, s, errors = 0; for (n = 0; n < sz; n++) { v_pattern[n] = (n & 0xff); } for (f = 0; f < face_lbp[stage].count; f++) { lbp_feat_t feat = face_lbp[stage].feats[f]; vbx_set_vl(sz); int total = f; s = 0; while(s < stage){ total += face_lbp[s].count; s++; } if(total < 256) { vbx(SVBU, VLBPLUT, v_lutc, total, v_pattern); } else { vbx(SVBS, VLBPLUT, v_lutc, total-256, v_pattern); } vbx(SVB, VMOV, v_pass, feat.fail, 0); /* check if pattern is in lut */ vbx(SVBU, VSHR, v_group, 5, v_pattern); for (n = 0; n < 8; n++) { vbx(SVB, VADD, v_sel, -n, v_group); vbx(SVBW, VCMV_Z, v_lut, feat.lut[n], v_sel); } vbx(SVBWU, VAND, v_idx, 0x1f, v_pattern); vbx(VVWB, VSHR, v_lut, v_idx, v_lut); vbx(SVB, VAND, v_lut, 1, v_lut); vbx(SVB, VCMV_LEZ, v_pass, feat.pass, v_lut); vbx_dma_to_host(lut_c, v_lutc, sz*sizeof(unsigned char)); vbx_dma_to_host(lut, v_pass, sz*sizeof(unsigned char)); vbx_sync(); errors += match_array_byte(lut, lut_c, "custom_lut", sz, 1, 0, max_print_errors, 0, 0); } vbx_sp_free(); vbx_shared_free(lut); vbx_shared_free(lut_c); return errors; }
//FIXME stride for match not implemented int compare_LBPPassStage_to_restricted(unsigned short *vbx_img, int log, lbp_stage_t lbp_stage, int window, int width, int height, int max_print_errors) { int l, i, j, cell, errors = 0; unsigned char** scalar_patterns = test_scalar_patterns(vbx_img, log, width, height); unsigned char *pass, *vbx_pass; pass = (unsigned char*)vbx_shared_malloc(width*height*sizeof(unsigned char)); vbx_pass = (unsigned char*)vbx_shared_malloc(width*height*sizeof(unsigned char)); vbx_byte_t** v_lbp =(vbx_byte_t**)vbx_shared_malloc((log+1)*sizeof(vbx_byte_t*)); for (l=0; l<log+1; l++) { v_lbp[l] = (vbx_byte_t*)vbx_sp_malloc((window+1)*width*sizeof(vbx_byte_t)); } vbx_byte_t* v_lut = (vbx_byte_t*)vbx_sp_malloc(width*sizeof(vbx_byte_t)); vbx_byte_t* v_stage = (vbx_byte_t*)vbx_sp_malloc(width*sizeof(vbx_byte_t)); vbx_byte_t* v_pattern; lbp_feat_t feat; int dx, dy, dw, f; for (l=0; l<log+1; l++) { vbx_dma_to_vector(v_lbp[l]+width, scalar_patterns[l], (window)*width*sizeof(unsigned char)); } vbx_sync(); for(j=0; j < height-(window+1); j++) { for (l=0; l<log+1; l++) { vbx_set_vl(width * window); vbx(VVB, VMOV, v_lbp[l], v_lbp[l]+width, NULL); vbx_dma_to_vector(v_lbp[l] + window*width, scalar_patterns[l]+(j+window)*width, width*sizeof(unsigned char)); } vbx_set_vl(width-(window+1)); vbx(SVB, VMOV, v_stage, 0, NULL); for (f = 0; f < lbp_stage.count; f++) { feat = lbp_stage.feats[f]; dx = feat.pos.src.x; dy = feat.pos.src.y; dw = feat.pos.size.x; v_pattern = v_lbp[dw>>1]+(dy*width+dx); vbx(SVBU, VLBPLUT, v_lut, f, v_pattern); vbx(VVB, VADD, v_stage, v_stage, v_lut); } vbx(SVB, VMOV, v_lut, 0, NULL); vbx(SVB, VCMV_GEZ, v_lut, 1, v_stage); vbx_dma_to_host(vbx_pass + j*width, v_lut, (width-(window+1))*sizeof(unsigned char)); vbx_sync(); } unsigned int *iImg, *iiImg; iImg = (unsigned int *)vbx_shared_malloc(width*height*sizeof(unsigned int)); iiImg = (unsigned int *)vbx_shared_malloc(width*height*sizeof(unsigned int)); gen_integrals(vbx_img, iImg, iiImg, width, height); image_t lbp_img = {iImg, {width, height}}; for (j = 0; j < height - (window + 1); j++) { for (i = 0; i < width - (window + 1); i++) { pair_t lbp_p = {i, j}; pass[j*width+i] = LBPPassStage(lbp_img, lbp_stage, lbp_p); } } /* test pass vs vbx pass */ for (j = 0; j < height - (window + 1); j++) { errors += match_array_byte(vbx_pass + j*width, pass + j*width, "pass stage", width - (window + 1), 1, 0, max_print_errors, 1, j); if (errors > max_print_errors){ max_print_errors = 0; } } return errors; }