void FeatureTracker::changeType(vx_array vx_pt, vector<cv::Point2f> &cv_pt ) { vx_size vCount = 0; vxQueryArray(vx_pt, VX_ARRAY_ATTRIBUTE_NUMITEMS, &vCount, sizeof(vCount)); vx_enum item_type = 0; NVXIO_SAFE_CALL( vxQueryArray(vx_pt, VX_ARRAY_ATTRIBUTE_ITEMTYPE, &item_type, sizeof(item_type)) ); NVXIO_ASSERT( item_type == NVX_TYPE_POINT2F) ; vx_size stride; void * featureData = NULL; NVXIO_SAFE_CALL( vxAccessArrayRange(vx_pt, 0, vCount, &stride, (void**)&featureData, VX_READ_ONLY) ); int id = 0; cv_pt.resize(vCount); for (vx_size i = 0; i < vCount; i++) { nvx_point2f_t feature = vxArrayItem(nvx_point2f_t, featureData, i, stride); cv_pt[id].x = feature.x; cv_pt[id].y = feature.y; id++; } NVXIO_SAFE_CALL( vxCommitArrayRange(vx_pt, 0, vCount, featureData) ); cv_pt.resize(id); //cout<<"point size "<<cv_pt.size()<<" id "<<id<<endl; }
static vx_status VX_CALLBACK vxFindWarpKernel(vx_node node, vx_reference *parameters, vx_uint32 num) { if(num != 3) return VX_ERROR_INVALID_PARAMETERS; vx_status status = VX_SUCCESS; vx_array def_pnts = (vx_array) parameters[0]; vx_array moved_pnts = (vx_array) parameters[1]; vx_matrix matrix = (vx_matrix)parameters[2]; vx_size points_num; status |= vxQueryArray(def_pnts, VX_ARRAY_ATTRIBUTE_NUMITEMS, &points_num, sizeof(points_num)); if(status != VX_SUCCESS) { VX_PRINT(VX_ZONE_ERROR, "Can't query array attribute(%d)!\n", status); return VX_FAILURE; } if(points_num < 4) { vx_float32 matr_buff[9]; vxAccessMatrix(matrix, (void*)matr_buff); memset(matr_buff, 0, sizeof(vx_float32) * 9); matr_buff[0] = matr_buff[4] = matr_buff[8] = 1.; vxCommitMatrix(matrix, (void*)matr_buff); VX_PRINT(VX_ZONE_WARNING, "Number of points less then 4(%d)!\n", points_num); return VX_SUCCESS;//VX_FAILURE; } /*** CV array initialize ***/ std::vector<cv::Point2f> cv_points_from, cv_points_to; cv_points_from.reserve(points_num); cv_points_to.reserve(points_num); /***************************/ vx_size i, stride1 = 0ul, stride2 = 0ul; void *def_buff = NULL, *moved_buff = NULL; status |= vxAccessArrayRange(def_pnts, 0, points_num, &stride1, &def_buff, VX_READ_AND_WRITE); status |= vxAccessArrayRange(moved_pnts, 0, points_num, &stride2, &moved_buff, VX_READ_AND_WRITE); if(def_buff && moved_buff) { for (i = 0; i < points_num; i++) { if(vxArrayItem(vx_keypoint_t, moved_buff, i, stride2).tracking_status) { cv::Point2f pnt_from; pnt_from.x = vxArrayItem(vx_keypoint_t, def_buff, i, stride1).x; pnt_from.y = vxArrayItem(vx_keypoint_t, def_buff, i, stride1).y; cv_points_from.push_back(pnt_from); cv::Point2f pnt_to; pnt_to.x = vxArrayItem(vx_keypoint_t, moved_buff, i, stride2).x; pnt_to.y = vxArrayItem(vx_keypoint_t, moved_buff, i, stride2).y; cv_points_to.push_back(pnt_to); } } } else { status = VX_FAILURE; } status |= vxCommitArrayRange(def_pnts, 0, points_num, def_buff); status |= vxCommitArrayRange(moved_pnts, 0, points_num, moved_buff); VX_PRINT(VX_ZONE_LOG, "Number of points = (%d)!\n", cv_points_from.size()); /*** CV find homography ***/ cv::Mat_<float> cv_matr = cv::Mat::eye(3, 3, CV_32FC1); if(cv_points_from.size() > 0 && cv_points_to.size() > 0) cv_matr = cv::findHomography(cv_points_from, cv_points_to, CV_RANSAC); else VX_PRINT(VX_ZONE_WARNING, "Number of points is equal to zero!\n"); vx_float32 matr_buff[9]; status |= vxAccessMatrix(matrix, (void*)matr_buff); memcpy(matr_buff, cv_matr.data, sizeof(vx_float32) * 9); status |= vxCommitMatrix(matrix, (void*)matr_buff); return status; }
bool CVxParamArray::CompareFrameCoord2d(size_t numItems, size_t numItemsRef, vx_uint8 * bufItems, int frameNumber, const char * fileName) { FILE * fpLog = NULL; if (m_fileNameCompareLog.length() > 0) { char fileName[MAX_FILE_NAME_LENGTH]; sprintf(fileName, m_fileNameCompareLog.c_str(), frameNumber); fpLog = fopen(fileName, "w"); if (!fpLog) ReportError("ERROR: Unable to create: %s\n", fileName); printf("OK: creating array compare output log for %s in %s\n", GetVxObjectName(), fileName); } enum { // color indices of each list for viewing colorIndex_match_XYexact = 0, colorIndex_match_XY = 1, colorIndex_missing_in_ref = 2, colorIndex_missing_in_cur = 3, }; // number of keypoint counts size_t count_match_XYexact = 0; size_t count_match_XY = 0; size_t count_missing_in_ref = 0; size_t count_missing_in_cur = 0; // reset array list for viewing ResetArrayListForView(); // get reference and actual keypoint buffers vx_coordinates2d_t * kpRefBase = (vx_coordinates2d_t *)m_bufForRead, *kpActualBase = nullptr; vx_size stride; if (numItems > 0) { ERROR_CHECK(vxAccessArrayRange(m_array, 0, numItems, &stride, (void **)&kpActualBase, VX_READ_ONLY)); } // try matching reference keypoints with actual for (size_t j = 0; j < numItemsRef; j++) { vx_coordinates2d_t * kpRef = &kpRefBase[j]; bool matched = false; for (size_t i = 0; i < numItems; i++) { vx_coordinates2d_t * kpCur = &vxArrayItem(vx_coordinates2d_t, kpActualBase, i, stride); if ((kpCur->x == kpRef->x) && (kpCur->y == kpRef->y)) { AddToArrayListForView(colorIndex_match_XYexact, kpCur->x, kpCur->y, 0.0f); if (fpLog) fprintf(fpLog, "MATCH-XY-EXACT -- %5d %5d (ref:%06d) %5d %5d (cur:%06d)\n", kpRef->x, kpRef->y, (int)j, kpCur->x, kpCur->y, (int)i); count_match_XYexact++; matched = true; } else if ((abs((vx_int32)kpCur->x - (vx_int32)kpRef->x) <= m_errX) && (abs((vx_int32)kpCur->y - (vx_int32)kpRef->y) <= m_errY)) { AddToArrayListForView(colorIndex_match_XY, kpCur->x, kpCur->y, 0.0f); if (fpLog) fprintf(fpLog, "MATCH-XY -- %5d %5d (ref:%06d) %5d %5d (cur:%06d)\n", kpRef->x, kpRef->y, (int)j, kpCur->x, kpCur->y, (int)i); count_match_XY++; matched = true; } if (matched) break; } if (!matched) { AddToArrayListForView(colorIndex_missing_in_cur, kpRef->x, kpRef->y, 0.0f); if (fpLog) fprintf(fpLog, "MISMATCH-WITH-CUR -- %5d %5d (ref:%06d)\n", kpRef->x, kpRef->y, (int)j); count_missing_in_cur++; } } // try matching actual keypoints with reference for (size_t i = 0; i < numItems; i++) { vx_coordinates2d_t * kpCur = &vxArrayItem(vx_coordinates2d_t, kpActualBase, i, stride); bool matched = false; for (size_t j = 0; j < numItemsRef; j++) { vx_coordinates2d_t * kpRef = &kpRefBase[j]; if ((abs((vx_int32)kpCur->x - (vx_int32)kpRef->x) <= m_errX) && (abs((vx_int32)kpCur->y - (vx_int32)kpRef->y) <= m_errY)) { matched = true; break; } } if (!matched) { AddToArrayListForView(colorIndex_missing_in_ref, kpCur->x, kpCur->y, 0.0f); if (fpLog) fprintf(fpLog, "MISMATCH-WITH-REF -- %5d %5d (cur:%06d)\n", kpCur->x, kpCur->y, (int)i); count_missing_in_ref++; } } if (numItems > 0) { ERROR_CHECK(vxCommitArrayRange(m_array, 0, numItems, kpActualBase)); } // check for overall mismatch criteria size_t totalMatched = count_match_XYexact + count_match_XY; size_t totalMismatchesOrMissing = max(count_missing_in_ref, count_missing_in_cur); size_t total = totalMatched + totalMismatchesOrMissing; float percentMismatches = (total > 0) ? (100.0f * (float)totalMismatchesOrMissing / (float)total) : 0.0f; bool mismatched = false; if (percentMismatches > m_errMismatchPercent) { mismatched = true; printf("ERROR: array COMPARE MISMATCHED [matched %d; mismatched/missing %d (%.3f%%)] for %s with frame#%d of %s\n", (int)totalMatched, (int)totalMismatchesOrMissing, percentMismatches, GetVxObjectName(), frameNumber, fileName); if (fpLog) fprintf(fpLog, "ERROR: array COMPARE MISMATCHED [matched %d; mismatched/missing %d (%.3f%%)] for %s with frame#%d of %s\n", (int)totalMatched, (int)totalMismatchesOrMissing, percentMismatches, GetVxObjectName(), frameNumber, fileName); } else { if (m_verbose) printf("OK: array COMPARE MATCHED %.3f%% for %s with frame#%d of %s\n", 100.0f - percentMismatches, GetVxObjectName(), frameNumber, fileName); if (fpLog) fprintf(fpLog, "OK: array COMPARE MATCHED %.3f%% for %s with frame#%d of %s\n", 100.0f - percentMismatches, GetVxObjectName(), frameNumber, fileName); } if (fpLog) fclose(fpLog); return mismatched; }