void net_motion_test::OnMouseMove(UINT nFlags, CPoint point) { //TRACE("on mouse move\n"); if(m_bmouse_down) { int orix,oriy; getxy(m_ori,&orix,&oriy); int dstx,dsty; getxy(point,&dstx,&dsty); int minx = min(orix,dstx); int maxx = max(orix,dstx); int miny = min(oriy,dsty); int maxy = max(oriy,dsty); for(int i = minx; i <= maxx; i++) { for(int j = miny; j <= maxy; j++) { if(m_ori_is_set) { set_motion(i,j); }else{ clear_motion(i,j); } } } } CEdit::OnMouseMove(nFlags,point); }
void net_motion_test::clear_motion(POINT pt) { int x,y; getxy(pt,&x,&y); clear_motion(x,y); }
void ADNS_Configuration(void) { ON_CS(); writr_register(Configuration_bits,0x10); //设置分辨率 1600 //若Bit 4为0,则为400点每英寸 delay_ms(3); writr_register(Extended_Config,0x01); delay_ms(3); if(read_busy()!=1) {//设为3000帧每秒 OFF_CS(); //突发_写模式 delay_ms(2); ON_CS(); SPI_SendReceive(Frame_Period_Max_Bound_Lower+0x80); //设置帧率 //先写低位再写高位 SPI_SendReceive(0x40); // C0 5000帧率 SPI_SendReceive(Frame_Period_Max_Bound_Upper+0x80); SPI_SendReceive(0x1f); // 12 } clear_motion(); OFF_CS(); }
void ADNS_Configuration(void) { ON_CS(); writr_register(Configuration_bits,0x10); //设置分辨率 1600 //若Bit 4为0,则为400点每英寸 delay_ms(3); writr_register(Extended_Config,0x01); //设置为固定帧率,其值在Frame_Period_Max_Bound寄存器中 delay_ms(3); if(read_busy()!=1) { //设为3000帧每秒,3000=24MHz/0x1f40,0x1f40=8000 OFF_CS(); //突发_写模式 delay_ms(2); ON_CS(); SPI_Simu_RW(Frame_Period_Max_Bound_Lower+0x80); //设置帧率 //先写低位再写高位,若是读的话先读高位再读低位 SPI_Simu_RW(0x40); // C0, 5000帧率 // delay_us(75); SPI_Simu_RW(Frame_Period_Max_Bound_Upper+0x80); SPI_Simu_RW(0x1f); // 12 } clear_motion(); OFF_CS(); }
void net_motion_test::OnLButtonDown(UINT nFlags, CPoint point) { if(!is_show_motion()) { return; } if(is_motion_set(point)) { clear_motion(point); m_ori_is_set = FALSE; }else{ set_motion(point); m_ori_is_set = TRUE; } m_ori = point; m_bmouse_down = TRUE; //CEdit::OnLButtonDown(nFlags,point); }
static int ransac(const int *matched_points, int npoints, int *num_inliers_by_motion, double *params_by_motion, int num_desired_motions, const int minpts, IsDegenerateFunc is_degenerate, FindTransformationFunc find_transformation, ProjectPointsDoubleFunc projectpoints) { static const double PROBABILITY_REQUIRED = 0.9; static const double EPS = 1e-12; int N = 10000, trial_count = 0; int i = 0; int ret_val = 0; unsigned int seed = (unsigned int)npoints; int indices[MAX_MINPTS] = { 0 }; double *points1, *points2; double *corners1, *corners2; double *image1_coord; // Store information for the num_desired_motions best transformations found // and the worst motion among them, as well as the motion currently under // consideration. RANSAC_MOTION *motions, *worst_kept_motion = NULL; RANSAC_MOTION current_motion; // Store the parameters and the indices of the inlier points for the motion // currently under consideration. double params_this_motion[MAX_PARAMDIM]; double *cnp1, *cnp2; for (i = 0; i < num_desired_motions; ++i) { num_inliers_by_motion[i] = 0; } if (npoints < minpts * MINPTS_MULTIPLIER || npoints == 0) { return 1; } points1 = (double *)aom_malloc(sizeof(*points1) * npoints * 2); points2 = (double *)aom_malloc(sizeof(*points2) * npoints * 2); corners1 = (double *)aom_malloc(sizeof(*corners1) * npoints * 2); corners2 = (double *)aom_malloc(sizeof(*corners2) * npoints * 2); image1_coord = (double *)aom_malloc(sizeof(*image1_coord) * npoints * 2); motions = (RANSAC_MOTION *)aom_malloc(sizeof(RANSAC_MOTION) * num_desired_motions); for (i = 0; i < num_desired_motions; ++i) { motions[i].inlier_indices = (int *)aom_malloc(sizeof(*motions->inlier_indices) * npoints); clear_motion(motions + i, npoints); } current_motion.inlier_indices = (int *)aom_malloc(sizeof(*current_motion.inlier_indices) * npoints); clear_motion(¤t_motion, npoints); worst_kept_motion = motions; if (!(points1 && points2 && corners1 && corners2 && image1_coord && motions && current_motion.inlier_indices)) { ret_val = 1; goto finish_ransac; } cnp1 = corners1; cnp2 = corners2; for (i = 0; i < npoints; ++i) { *(cnp1++) = *(matched_points++); *(cnp1++) = *(matched_points++); *(cnp2++) = *(matched_points++); *(cnp2++) = *(matched_points++); } while (N > trial_count) { double sum_distance = 0.0; double sum_distance_squared = 0.0; clear_motion(¤t_motion, npoints); int degenerate = 1; int num_degenerate_iter = 0; while (degenerate) { num_degenerate_iter++; if (!get_rand_indices(npoints, minpts, indices, &seed)) { ret_val = 1; goto finish_ransac; } copy_points_at_indices(points1, corners1, indices, minpts); copy_points_at_indices(points2, corners2, indices, minpts); degenerate = is_degenerate(points1); if (num_degenerate_iter > MAX_DEGENERATE_ITER) { ret_val = 1; goto finish_ransac; } } if (find_transformation(minpts, points1, points2, params_this_motion)) { trial_count++; continue; } projectpoints(params_this_motion, corners1, image1_coord, npoints, 2, 2); for (i = 0; i < npoints; ++i) { double dx = image1_coord[i * 2] - corners2[i * 2]; double dy = image1_coord[i * 2 + 1] - corners2[i * 2 + 1]; double distance = sqrt(dx * dx + dy * dy); if (distance < INLIER_THRESHOLD) { current_motion.inlier_indices[current_motion.num_inliers++] = i; sum_distance += distance; sum_distance_squared += distance * distance; } } if (current_motion.num_inliers >= worst_kept_motion->num_inliers && current_motion.num_inliers > 1) { int temp; double fracinliers, pNoOutliers, mean_distance, dtemp; mean_distance = sum_distance / ((double)current_motion.num_inliers); current_motion.variance = sum_distance_squared / ((double)current_motion.num_inliers - 1.0) - mean_distance * mean_distance * ((double)current_motion.num_inliers) / ((double)current_motion.num_inliers - 1.0); if (is_better_motion(¤t_motion, worst_kept_motion)) { // This motion is better than the worst currently kept motion. Remember // the inlier points and variance. The parameters for each kept motion // will be recomputed later using only the inliers. worst_kept_motion->num_inliers = current_motion.num_inliers; worst_kept_motion->variance = current_motion.variance; memcpy(worst_kept_motion->inlier_indices, current_motion.inlier_indices, sizeof(*current_motion.inlier_indices) * npoints); assert(npoints > 0); fracinliers = (double)current_motion.num_inliers / (double)npoints; pNoOutliers = 1 - pow(fracinliers, minpts); pNoOutliers = fmax(EPS, pNoOutliers); pNoOutliers = fmin(1 - EPS, pNoOutliers); dtemp = log(1.0 - PROBABILITY_REQUIRED) / log(pNoOutliers); temp = (dtemp > (double)INT32_MAX) ? INT32_MAX : dtemp < (double)INT32_MIN ? INT32_MIN : (int)dtemp; if (temp > 0 && temp < N) { N = AOMMAX(temp, MIN_TRIALS); } // Determine the new worst kept motion and its num_inliers and variance. for (i = 0; i < num_desired_motions; ++i) { if (is_better_motion(worst_kept_motion, &motions[i])) { worst_kept_motion = &motions[i]; } } } } trial_count++; } // Sort the motions, best first. qsort(motions, num_desired_motions, sizeof(RANSAC_MOTION), compare_motions); // Recompute the motions using only the inliers. for (i = 0; i < num_desired_motions; ++i) { if (motions[i].num_inliers >= minpts) { copy_points_at_indices(points1, corners1, motions[i].inlier_indices, motions[i].num_inliers); copy_points_at_indices(points2, corners2, motions[i].inlier_indices, motions[i].num_inliers); find_transformation(motions[i].num_inliers, points1, points2, params_by_motion + (MAX_PARAMDIM - 1) * i); } num_inliers_by_motion[i] = motions[i].num_inliers; } finish_ransac: aom_free(points1); aom_free(points2); aom_free(corners1); aom_free(corners2); aom_free(image1_coord); aom_free(current_motion.inlier_indices); for (i = 0; i < num_desired_motions; ++i) { aom_free(motions[i].inlier_indices); } aom_free(motions); return ret_val; }