void CvFaceElement::MergeRects(int d) { int nRects = m_seqRects->total; CvSeqReader reader, reader2; cvStartReadSeq( m_seqRects, &reader ); int i, j; for (i = 0; i < nRects; i++) { CvTrackingRect* pRect1 = (CvTrackingRect*)(reader.ptr); cvStartReadSeq( m_seqRects, &reader2 ); cvSetSeqReaderPos(&reader2, i + 1); for (j = i + 1; j < nRects; j++) { CvTrackingRect* pRect2 = (CvTrackingRect*)(reader2.ptr); if (abs(pRect1->ptCenter.y - pRect2->ptCenter.y) < d && abs(pRect1->r.height - pRect2->r.height) < d) { CvTrackingRect rNew; rNew.iColor = (pRect1->iColor + pRect2->iColor + 1) / 2; rNew.r.x = min(pRect1->r.x, pRect2->r.x); rNew.r.y = min(pRect1->r.y, pRect2->r.y); rNew.r.width = max(pRect1->r.x + pRect1->r.width, pRect2->r.x + pRect2->r.width) - rNew.r.x; rNew.r.height = min(pRect1->r.y + pRect1->r.height, pRect2->r.y + pRect2->r.height) - rNew.r.y; if (rNew.r != pRect1->r && rNew.r != pRect2->r) { rNew.ptCenter = Center(rNew.r); cvSeqPush(m_seqRects, &rNew); } } CV_NEXT_SEQ_ELEM( sizeof(CvTrackingRect), reader2 ); } CV_NEXT_SEQ_ELEM( sizeof(CvTrackingRect), reader ); } // delete equal rects for (i = 0; i < m_seqRects->total; i++) { CvTrackingRect* pRect1 = (CvTrackingRect*)cvGetSeqElem(m_seqRects, i); int j_begin = i + 1; for (j = j_begin; j < m_seqRects->total;) { CvTrackingRect* pRect2 = (CvTrackingRect*)cvGetSeqElem(m_seqRects, j); if (pRect1->r == pRect2->r) cvSeqRemove(m_seqRects, j); else j++; } } }//void CvFaceElement::MergeRects(int d)
inline void DelPoint(int PointIndex) { cvSeqRemove(m_pSeq, PointIndex); };
static gboolean hands_are_praying (guint16* depth, guint width, guint height, SkeltrackJointList list) { guint x, y, z; SkeltrackJoint *head, *left_elbow, *left_shoulder, *right_shoulder, *right_elbow; CvSeq *defects = NULL; if (list == NULL) return FALSE; head = skeltrack_joint_list_get_joint (list, SKELTRACK_JOINT_ID_HEAD); right_elbow = skeltrack_joint_list_get_joint (list, SKELTRACK_JOINT_ID_RIGHT_ELBOW); left_elbow = skeltrack_joint_list_get_joint (list, SKELTRACK_JOINT_ID_LEFT_ELBOW); right_shoulder = skeltrack_joint_list_get_joint (list, SKELTRACK_JOINT_ID_RIGHT_SHOULDER); left_shoulder = skeltrack_joint_list_get_joint (list, SKELTRACK_JOINT_ID_LEFT_SHOULDER); if (head == NULL || right_elbow == NULL || left_elbow == NULL || ((right_elbow->y < right_shoulder->y) && (left_elbow->y < left_shoulder->y))) return FALSE; x = head->screen_x; y = right_elbow->screen_y; z = ((gfloat) (right_shoulder->z + left_shoulder->z)) / 2.0 - 300; defects = get_defects (depth, width, height, x, y, z); if (defects) { guint i, sum; sum = 0; for (i = 0; i < defects->total; i++) { gfloat orientation; CvConvexityDefect *defect = CV_GET_SEQ_ELEM (CvConvexityDefect, defects, i); orientation = get_orientation_angle (defect->start, defect->depth_point, defect->end); orientation = ((gint) (orientation / M_PI * 180.0)) % 360; if (defect->depth > 20.0 && orientation < 180 && orientation > 0 && ABS (orientation - 90) > 25) { gfloat x1, x2, sig_x1, sig_x2; x1 = defect->start->x - defect->depth_point->x; x2 = defect->end->x - defect->depth_point->x; sig_x1 = x1 / ABS (x1); sig_x2 = x2 / ABS (x2); if (sig_x1 != sig_x2 || (x1 == 0 || x2 == 0)) { continue; } cvSeqRemove(defects, i); i--; } else { cvSeqRemove(defects, i); i--; } } if (defects->total > 1) { for (i = 1; i < defects->total; i++) { gfloat dist_hand1, dist_hand2, dist_depth_points; CvConvexityDefect *defect1, *defect2; CvPoint *defect1_top_point, *defect2_top_point; defect1 = CV_GET_SEQ_ELEM (CvConvexityDefect, defects, i); defect2 = CV_GET_SEQ_ELEM (CvConvexityDefect, defects, i - 1); if (defect1->end->y < defect1->start->y) defect1_top_point = defect1->end; else defect1_top_point = defect1->start; if (defect2->end->y < defect2->start->y) defect2_top_point = defect2->end; else defect2_top_point = defect2->start; dist_hand1 = get_points_distance (defect1_top_point, defect1->depth_point); dist_hand2 = get_points_distance (defect2_top_point, defect2->depth_point); dist_depth_points = get_points_distance (defect1->depth_point, defect2->depth_point); if (dist_depth_points < MAX (dist_hand1, dist_hand2)) sum++; } } if (sum > 0) return TRUE; } return FALSE; }
static CvSeq * get_finger_defects (guint16* depth, guint width, guint height, SkeltrackJointList list) { CvSeq *defects = NULL; SkeltrackJoint *head, *left_hand, *right_hand, *hand = NULL; if (list == NULL) return NULL; head = skeltrack_joint_list_get_joint (list, SKELTRACK_JOINT_ID_HEAD); right_hand = skeltrack_joint_list_get_joint (list, SKELTRACK_JOINT_ID_RIGHT_HAND); left_hand = skeltrack_joint_list_get_joint (list, SKELTRACK_JOINT_ID_LEFT_HAND); if (head == NULL || (left_hand == NULL && right_hand == NULL)) return NULL; if (right_hand == NULL) hand = left_hand; else if (left_hand == NULL) hand = right_hand; else { if (right_hand->z < left_hand->z && ABS (right_hand->z - head->z) > 150) { hand = right_hand; } else if (left_hand->z < right_hand->z && ABS (left_hand->z - head->z) > 150) { hand = left_hand; } } if (hand == NULL) return NULL; defects = get_defects (depth, width, height, hand->screen_x, hand->screen_y, hand->z); if (defects) { gfloat angle; guint i; for (i = 0; i < defects->total; i++) { CvConvexityDefect *defect = CV_GET_SEQ_ELEM (CvConvexityDefect, defects, i); angle = get_angle (defect->start, defect->depth_point, defect->end); if (angle > M_PI_2) { cvSeqRemove(defects, i); i--; } } return defects; } return NULL; }
static void doCoalesce(image_session_t *mySession) { CvSeq *newDetected = NULL; image_detected_t *current; CvRect tempRect; int over_left, over_top; int right1, right2, over_right; int bottom1, bottom2, over_bottom; int over_width, over_height; int r1Area, r2Area; int *merged = NULL; int newI = 0; int i, j; uint16_t current_category; for(current_category = 0; current_category < num_image_categories; current_category++) { current = &mySession->detected[current_category]; if(current->category->coalesceOverlap != 1.0f && current->detected) { // Loop the number of detected objects newDetected = cvCreateSeq( 0, sizeof(CvSeq), sizeof(CvRect), mySession->lstorage ); merged = malloc(sizeof(int) * current->detected->total); newI = 0; for(i = 0; i < current->detected->total; i++ ) merged[i] = -1; // quickly setup merged variable for(i = 0; i < current->detected->total; i++ ) { CvRect* r = (CvRect*)cvGetSeqElem( current->detected, i ); if(merged[i] == -1) { cvSeqPush( newDetected, r ); merged[i] = newI; newI++; } if(current->detected->total - i > 0) { r1Area = r->width * r->height; for(j = i + 1; j < current->detected->total; j++ ) { // Reset rectangles to original size CvRect* r2 = (CvRect*)cvGetSeqElem( current->detected, j ); r2Area = r2->width * r2->height; right1 = r->x + r->width; right2 = r2->x + r2->width; bottom1 = r->y + r->height; bottom2 = r2->y + r2->height; if (!(bottom1 < r2->y) && !(r->y > bottom2) && !(right1 < r2->x) && !(r->x > right2)) { // Ok, compute the rectangle of overlap: if (bottom1 > bottom2) over_bottom = bottom2; else over_bottom = bottom1; if (r->y < r2->y) over_top = r2->y; else over_top = r->y; if (right1 > right2) over_right = right2; else over_right = right1; if (r->x < r2->x) over_left = r2->x; else over_left = r->x; over_width=over_right-over_left; over_height=over_bottom-over_top; if((r1Area * current->category->coalesceOverlap <= over_width*over_height) || (r2Area * current->category->coalesceOverlap <= over_width*over_height)) { ci_debug_printf(10, "srv_classify_image: Merging detected %s at X: %d, Y: %d, Height: %d, Width: %d and X2: %d, Y2: %d, Height2: %d, Width2: %d\n", current->category->name, r->x, r->y, r->height, r->width, r2->x, r2->y, r2->height, r2->width); tempRect = cvMaxRect( (CvRect*)cvGetSeqElem( newDetected, merged[i] ), r2); cvSeqRemove( newDetected, merged[i] ); cvSeqInsert( newDetected, merged[i], &tempRect ); merged[j] = merged[i]; } } } } } cvClearSeq( current->detected ); current->detected = newDetected; free(merged); } } }
void CvBlobTrackSeq::DelBlobTrack(int TrackIndex) { CvBlobTrack* pP = GetBlobTrack(TrackIndex); if(pP && pP->pBlobSeq) delete pP->pBlobSeq; cvSeqRemove(m_pSeq,TrackIndex); }
/* * call-seq: * remove(<i>index</i>) -> obj or nil * * Deletes the elements at the specified index. */ VALUE rb_remove(VALUE self, VALUE index) { cvSeqRemove(CVSEQ(self), FIX2INT(index)); return self; }