static int transform_reverse_near_far(struct transformation *t, struct point *p, struct coord *c, int near, int far) { double xc,yc; dbg(1,"%d,%d\n",p->x,p->y); if (t->ddd) { struct coord_geo_cart nearc,farc,nears,fars,intersection; transform_screen_to_3d(t, p, near, &nearc); transform_screen_to_3d(t, p, far, &farc); transform_apply_inverse_matrix(t, &nearc, &nears); transform_apply_inverse_matrix(t, &farc, &fars); if (transform_zplane_intersection(&nears, &fars, HOG(*t), &intersection) != 1) return 0; xc=intersection.x; yc=intersection.y; } else { double xcn,ycn; xcn=p->x - t->offx; ycn=p->y - t->offy; xc=(xcn*t->im00+ycn*t->im01)*(1 << POST_SHIFT); yc=(xcn*t->im10+ycn*t->im11)*(1 << POST_SHIFT); } c->x=xc*(1 << t->scale_shift)+t->map_center.x; c->y=yc*(1 << t->scale_shift)+t->map_center.y; return 1; }
int main(int argc, char** argv){ int nHOGFeatureNum; HOG_FEATURE *pHOGFeatures; char FileName[256]; char buffer[256]; //画像の読み込み if(NULL == (Img=cvLoadImage(argv[1], CV_LOAD_IMAGE_GRAYSCALE))){ printf("Can not open the file.\n"); return(1); } //画像のサイズを一定にするための構造体 CvSize r_size = cvSize((int)SET_X_SIZE, (int)SET_Y_SIZE); LowImg = cvCreateImage(r_size, IPL_DEPTH_8U, 1); //パッチサイズにリサイズ cvResize(Img, LowImg, CV_INTER_LINEAR); //あらかじめ特徴量の数を算出 nHOGFeatureNum = CountHOGFeature(); //扱う特徴量の数だけ構造体を確保 pHOGFeatures = new HOG_FEATURE[nHOGFeatureNum]; //HOG 特徴抽出 HOG(pHOGFeatures); sscanf(argv[1],"%s.png",buffer); sprintf(FileName,"%s.hog",buffer); //特徴量の書き出し OutputHOGFeature(nHOGFeatureNum, pHOGFeatures, FileName); //画像のデータが入っている構造体を解放 cvReleaseImage(&LowImg); cvReleaseImage(&Img); //特徴量の構造体を解放 delete []pHOGFeatures; return (0); }
void transform_setup_source_rect(struct transformation *t) { int i; struct coord screen[4]; struct point screen_pnt[4]; struct point_rect *pr; struct map_selection *ms,*msm,*next,**msm_last; ms=t->map_sel; while (ms) { next=ms->next; g_free(ms); ms=next; } t->map_sel=NULL; msm_last=&t->map_sel; ms=t->screen_sel; while (ms) { msm=g_new0(struct map_selection, 1); *msm=*ms; pr=&ms->u.p_rect; screen_pnt[0].x=pr->lu.x; /* left upper */ screen_pnt[0].y=pr->lu.y; screen_pnt[1].x=pr->rl.x; /* right upper */ screen_pnt[1].y=pr->lu.y; screen_pnt[2].x=pr->rl.x; /* right lower */ screen_pnt[2].y=pr->rl.y; screen_pnt[3].x=pr->lu.x; /* left lower */ screen_pnt[3].y=pr->rl.y; if (t->ddd) { struct coord_geo_cart tmp,cg[8]; struct coord c; int valid=0; unsigned char edgenodes[]={ 0,1, 1,2, 2,3, 3,0, 4,5, 5,6, 6,7, 7,4, 0,4, 1,5, 2,6, 3,7}; for (i = 0 ; i < 8 ; i++) { transform_screen_to_3d(t, &screen_pnt[i%4], (i >= 4 ? t->zfar:t->znear), &tmp); transform_apply_inverse_matrix(t, &tmp, &cg[i]); } msm->u.c_rect.lu.x=0; msm->u.c_rect.lu.y=0; msm->u.c_rect.rl.x=0; msm->u.c_rect.rl.y=0; for (i = 0 ; i < 12 ; i++) { if (transform_zplane_intersection(&cg[edgenodes[i*2]], &cg[edgenodes[i*2+1]], HOG(*t), &tmp) == 1) { c.x=tmp.x*(1 << t->scale_shift)+t->map_center.x; c.y=tmp.y*(1 << t->scale_shift)+t->map_center.y; dbg(1,"intersection with edge %d at 0x%x,0x%x\n",i,c.x,c.y); if (valid) coord_rect_extend(&msm->u.c_rect, &c); else { msm->u.c_rect.lu=c; msm->u.c_rect.rl=c; valid=1; } dbg(1,"rect 0x%x,0x%x - 0x%x,0x%x\n",msm->u.c_rect.lu.x,msm->u.c_rect.lu.y,msm->u.c_rect.rl.x,msm->u.c_rect.rl.y); } } } else { for (i = 0 ; i < 4 ; i++) { transform_reverse(t, &screen_pnt[i], &screen[i]); dbg(1,"map(%d) %d,%d=0x%x,0x%x\n", i,screen_pnt[i].x, screen_pnt[i].y, screen[i].x, screen[i].y); } msm->u.c_rect.lu.x=min4(screen[0].x,screen[1].x,screen[2].x,screen[3].x); msm->u.c_rect.rl.x=max4(screen[0].x,screen[1].x,screen[2].x,screen[3].x); msm->u.c_rect.rl.y=min4(screen[0].y,screen[1].y,screen[2].y,screen[3].y); msm->u.c_rect.lu.y=max4(screen[0].y,screen[1].y,screen[2].y,screen[3].y); } dbg(1,"%dx%d\n", msm->u.c_rect.rl.x-msm->u.c_rect.lu.x, msm->u.c_rect.lu.y-msm->u.c_rect.rl.y); *msm_last=msm; msm_last=&msm->next; ms=ms->next; } }
int transform(struct transformation *t, enum projection pro, struct coord *c, struct point *p, int count, int mindist, int width, int *width_return) { struct coord c1; int xcn, ycn; struct coord_geo g; int xc, yc, zc=0, xco=0, yco=0, zco=0; int xm,ym,zct; int zlimit=t->znear; int visible, visibleo=-1; int i,j = 0,k=0; dbg(1,"count=%d\n", count); for (i=0; i < count; i++) { if (pro == t->pro) { xc=c[i].x; yc=c[i].y; } else { transform_to_geo(pro, &c[i], &g); transform_from_geo(t->pro, &g, &c1); xc=c1.x; yc=c1.y; } if (i != 0 && i != count-1 && mindist) { if (xc > c[k].x-mindist && xc < c[k].x+mindist && yc > c[k].y-mindist && yc < c[k].y+mindist && (c[i+1].x != c[0].x || c[i+1].y != c[0].y)) continue; k=i; } xm=xc; ym=yc; // dbg(2,"0x%x, 0x%x - 0x%x,0x%x contains 0x%x,0x%x\n", t->r.lu.x, t->r.lu.y, t->r.rl.x, t->r.rl.y, c->x, c->y); // ret=coord_rect_contains(&t->r, c); xc-=t->map_center.x; yc-=t->map_center.y; xc >>= t->scale_shift; yc >>= t->scale_shift; xm=xc; ym=yc; xcn=xc*t->m00+yc*t->m01+HOG(*t)*t->m02; ycn=xc*t->m10+yc*t->m11+HOG(*t)*t->m12; if (t->ddd) { zc=(xc*t->m20+yc*t->m21+HOG(*t)*t->m22); zct=zc; zc+=t->offz << POST_SHIFT; dbg(1,"zc=%d\n", zc); dbg(1,"zc(%d)=xc(%d)*m20(%d)+yc(%d)*m21(%d)\n", (xc*t->m20+yc*t->m21), xc, t->m20, yc, t->m21); /* visibility */ visible=(zc < zlimit ? 0:1); dbg(1,"visible=%d old %d\n", visible, visibleo); if (visible != visibleo && visibleo != -1) { dbg(1,"clipping (%d,%d,%d)-(%d,%d,%d) (%d,%d,%d)\n", xcn, ycn, zc, xco, yco, zco, xco-xcn, yco-ycn, zco-zc); if (zco != zc) { xcn=xcn+(long long)(xco-xcn)*(zlimit-zc)/(zco-zc); ycn=ycn+(long long)(yco-ycn)*(zlimit-zc)/(zco-zc); } dbg(1,"result (%d,%d,%d) * %d / %d\n", xcn,ycn,zc,zlimit-zc,zco-zc); zc=zlimit; xco=xcn; yco=ycn; zco=zc; if (visible) i--; visibleo=visible; } else { xco=xcn; yco=ycn; zco=zc; visibleo=visible; if (! visible) continue; } dbg(1,"zc=%d\n", zc); dbg(1,"xcn %d ycn %d\n", xcn, ycn); dbg(1,"%d,%d %d\n",xc,yc,zc); #if 0 dbg(0,"%d/%d=%d %d/%d=%d\n",xcn,xc,xcn/xc,ycn,yc,ycn/yc); #endif #if 1 xc=(long long)xcn*t->xscale/zc; yc=(long long)ycn*t->yscale/zc; #else xc=xcn/(1000+zc); yc=ycn/(1000+zc); #endif #if 0 dbg(1,"%d,%d %d\n",xc,yc,zc); #endif } else { xc=xcn; yc=ycn; xc>>=POST_SHIFT; yc>>=POST_SHIFT; } xc+=t->offx; yc+=t->offy; p[j].x=xc; p[j].y=yc; if (width_return) { if (t->ddd) width_return[j]=width*t->wscale/zc; else width_return[j]=width; } j++; } return j; }
int transform_get_hog(struct transformation *this_) { return HOG(*this_); }