Exemplo n.º 1
0
void RotatedImages(std::string destFoldPath, cv::Mat Im)
{
	cv::Mat R90, L90, R180;
	R90 = Im.clone();
	R180 = Im.clone();
	L90 = Im.clone();
	rot90(R90, 1);
	rot90(L90, 2);
	rot90(R180, 3);
	cv::imwrite(destFoldPath + "_R90.jpg", R90);
	cv::imwrite(destFoldPath + "_R180.jpg", R180);
	cv::imwrite(destFoldPath + "_L90.jpg", L90);
}
Exemplo n.º 2
0
void
main(int argc, char *argv[])
{
	Memimage *m;
	int fd, r;
	char f;

	f = 0;
	r = 0;
	fd = 0;
	ARGBEGIN {
	case 'u':
		f = 'u';
		break;
	case 'l':
		f = 'l';
		break;
	case 'r':
		r = atoi(EARGF(usage()));
		break;
	default:
		usage();
	} ARGEND;
	if(*argv){
		fd = open(*argv, OREAD);
		if(fd < 0)
			sysfatal("open: %r");
	}
	memimageinit();
	if((m = readmemimage(fd)) == nil)
		sysfatal("readmemimage: %r");
	if(f == 'u' || f == 'l'){
		m = upsidedown(m);
		if(f == 'l')
			r = 180;
	}
	switch(r % 360){
	case 270:
		m = rot90(m);
	case 180:
		m = rot90(m);
	case 90:
		m = rot90(m);
		break;
	}
	if(writememimage(1, m) < 0)
		sysfatal("writememimage: %r");
	exits(0);
}
Exemplo n.º 3
0
main () {
    FILE *fin  = fopen ("transform.in", "r");
    FILE *fout = fopen ("transform.out", "w");
    int a, b;
    int i,j,k;
	char ln[10];
	
	fscanf (fin, "%d", &nt);
	for(i=0;i<nt;i++){
		fscanf(fin, "%s", ln);
		for(j=0;j<nt;j++)pbf[i][j]=ln[j];
	}
	for(i=0;i<nt;i++){
		fscanf(fin, "%s", ln);
		for(j=0;j<nt;j++)pt[i][j]=paf[i][j]=ln[j];
	}
	
	for(k=1;k<4;k++){
		cpy();
		rot90(k);
		if(ide()){
			fprintf (fout, "%d\n", k);exit(0);
		}
	}
	
	cpy();
	ref();
	if(ide()){
		fprintf (fout, "%d\n", 4);exit(0);
	}
	
	for(k=1;k<4;k++){
		cpy();
		ref();
		rot90(k);
		if(ide()){
			fprintf (fout, "%d\n", 5);exit(0);
		}
	}

	cpy();
	if(ide()){
		fprintf (fout, "%d\n", 6);exit(0);
	}
	
    fprintf (fout, "%d\n", 7);
    exit (0);
}
Eigen::Eigen(Matrix const &m) {
    double const B = -m[0] - m[3];
    double const C = m[0]*m[3] - m[1]*m[2];
    double const center = -B/2.0;
    double const delta = sqrt(B*B-4*C)/2.0;
    values = Point(center + delta, center - delta);
    for (int i = 0; i < 2; i++) {
        vectors[i] = unit_vector(rot90(Point(m[0]-values[i], m[1])));
    }
}
Exemplo n.º 5
0
//TODO: handle the case when B is "behind" A for the natural orientation of the level set.
//TODO: more generally, there might be up to 4 solutions. Choose the best one!
D2<SBasis>
sb2d_cubic_solve(SBasis2d const &f, Geom::Point const &A, Geom::Point const &B){
    D2<SBasis>result;//(Linear(A[X],B[X]),Linear(A[Y],B[Y]));
    //g_warning("check 0 = %f = %f!", f.apply(A[X],A[Y]), f.apply(B[X],B[Y]));

    SBasis2d f_u  = partial_derivative(f  , 0);
    SBasis2d f_v  = partial_derivative(f  , 1);
    SBasis2d f_uu = partial_derivative(f_u, 0);
    SBasis2d f_uv = partial_derivative(f_v, 0);
    SBasis2d f_vv = partial_derivative(f_v, 1);

    Geom::Point dfA(f_u.apply(A[X],A[Y]),f_v.apply(A[X],A[Y]));
    Geom::Point dfB(f_u.apply(B[X],B[Y]),f_v.apply(B[X],B[Y]));

    Geom::Point V0 = rot90(dfA);
    Geom::Point V1 = rot90(dfB);
    
    double D2fVV0 = f_uu.apply(A[X],A[Y])*V0[X]*V0[X]+
                  2*f_uv.apply(A[X],A[Y])*V0[X]*V0[Y]+
                    f_vv.apply(A[X],A[Y])*V0[Y]*V0[Y];
    double D2fVV1 = f_uu.apply(B[X],B[Y])*V1[X]*V1[X]+
                  2*f_uv.apply(B[X],B[Y])*V1[X]*V1[Y]+
                    f_vv.apply(B[X],B[Y])*V1[Y]*V1[Y];

    std::vector<D2<SBasis> > candidates = cubics_fitting_curvature(A,B,V0,V1,D2fVV0,D2fVV1);
    if (candidates.empty()) {
        return D2<SBasis>(Linear(A[X],B[X]),Linear(A[Y],B[Y]));
    }
    //TODO: I'm sure std algorithm could do that for me...
    double error = -1;
    unsigned best = 0;
    for (unsigned i=0; i<candidates.size(); i++){
        Interval bounds = *bounds_fast(compose(f,candidates[i]));
        double new_error = (fabs(bounds.max())>fabs(bounds.min()) ? fabs(bounds.max()) : fabs(bounds.min()) );
        if ( new_error < error || error < 0 ){
            error = new_error;
            best = i;
        }
    }
    return candidates[best];
}
Exemplo n.º 6
0
Arquivo: image.c Projeto: pts/pts-qiv
void transform( qiv_image *q, enum Orientation orientation) {
    switch (orientation) {
     default: return;
     case HFLIP:     flipH(q); snprintf(infotext, sizeof infotext, "(Flipped horizontally)"); break;
     case VFLIP:     flipV(q); snprintf(infotext, sizeof infotext, "(Flipped vertically)"); break;
     case ROT_180:   rot180(q); snprintf(infotext, sizeof infotext, "(Turned upside down)"); break;
      case TRANSPOSE: transpose(q); swapWH(q); snprintf(infotext, sizeof infotext, "(Transposed)"); break;
     case ROT_90:    rot90(q); swapWH(q); snprintf(infotext, sizeof infotext, "(Rotated left)"); break;
     case TRANSVERSE: transpose(q); rot180(q); swapWH(q); snprintf(infotext, sizeof infotext, "(Transversed)"); break;
     case ROT_270:   rot270(q); swapWH(q); snprintf(infotext, sizeof infotext, "(Rotated left)"); break;
    }
}
Exemplo n.º 7
0
void exertPatchR(Point anchor, Mat &ROI, Mat &dst, int pos)//我们认为左上角和右上角已经有数据了
{
    int edge = HALFPATCHSIZE;
    Mat newRightTopROI(ROI, Rect(edge-1, 0, HALFPATCHSIZE, HALFPATCHSIZE));
    Mat oldRightTopROI(dst, Rect(anchor.x+edge-1, anchor.y, HALFPATCHSIZE, HALFPATCHSIZE));
    Mat seamMatrix(HALFPATCHSIZE, HALFPATCHSIZE, CV_8UC1, Scalar(0));
    int k, l;
    for (k = 0; k < HALFPATCHSIZE; k++)
    {
        for (l = 0; l < HALFPATCHSIZE; l++)
        {
            int diff = 0;
            for (int i = 0; i < 3; i++)
            {
                diff += newRightTopROI.at<Vec3b>(k, l)[i] - oldRightTopROI.at<Vec3b>(k, l)[i];
            }
            diff /= 3;
            seamMatrix.at<uchar>(k, l) = diff;
        }
    }
    //DP
    int rotIndex[4][2] = { { 1, 2 }, { 0, 0 }, { 2, 1 }, { 3, 3 } };
    rot90(seamMatrix, rotIndex[pos][0]);
    rot90(newRightTopROI, rotIndex[pos][0]);
    rot90(oldRightTopROI, rotIndex[pos][0]);
    Mat newdst = oldRightTopROI.clone();
    dp(seamMatrix, oldRightTopROI, newRightTopROI, newdst);
    rot90(newRightTopROI, rotIndex[pos][1]);
    rot90(oldRightTopROI, rotIndex[pos][1]);
    rot90(newdst, rotIndex[pos][1]);
    //cout << newdst << endl;;
    //cout << newLeftTopROI << endl;
    newdst.copyTo(newRightTopROI);
}
Exemplo n.º 8
0
Eigen::Eigen(double m[2][2]) {
    double const B = -m[0][0] - m[1][1];
    double const C = m[0][0]*m[1][1] - m[1][0]*m[0][1];
    //double const desc = B*B-4*C;
    //double t = -0.5*(B+sgn(B)*desc);
    int n;
    values[0] = values[1] = 0;
    quadratic_roots(C, B, 1, n, values[0], values[1]);
    for (int i = 0; i < n; i++)
        vectors[i] = unit_vector(rot90(Point(m[0][0]-values[i], m[0][1])));
    for (int i = n; i < 2; i++) 
        vectors[i] = Point(0,0);
}
Exemplo n.º 9
0
int circle_circle_intersection(Point X0, double r0,
                               Point X1, double r1,
                               Point & p0, Point & p1)
{
  /* dx and dy are the vertical and horizontal distances between
   * the circle centers.
   */
  Point D = X1 - X0;

  /* Determine the straight-line distance between the centers. */
  double d = L2(D);

  /* Check for solvability. */
  if (d > (r0 + r1))
  {
    /* no solution. circles do not intersect. */
    return 0;
  }
  if (d <= fabs(r0 - r1))
  {
    /* no solution. one circle is contained in the other */
    return 1;
  }
  
  /* 'point 2' is the point where the line through the circle
   * intersection points crosses the line between the circle
   * centers.  
   */

  /* Determine the distance from point 0 to point 2. */
  double a = ((r0*r0) - (r1*r1) + (d*d)) / (2.0 * d) ;

  /* Determine the coordinates of point 2. */
  Point p2 = X0 + D * (a/d);

  /* Determine the distance from point 2 to either of the
   * intersection points.
   */
  double h = sqrt((r0*r0) - (a*a));

  /* Now determine the offsets of the intersection points from
   * point 2.
   */
  Point r = (h/d)*rot90(D);

  /* Determine the absolute intersection points. */
  p0 = p2 + r;
  p1 = p2 - r;

  return 2;
}
Exemplo n.º 10
0
void final_magic_crop_rotate ( Mat& mat, vector<Point>& points4 ) {

  Size size_mat = mat.size();
  corners_magick_do ( points4 /*ref*/ ); /*sorts corner points4*/

  vector<Point2f> points4f;
  // this here is probably closest to the size of the original invoice... well, let's try... tension :)
  RotatedRect rect_minAreaRect = minAreaRect ( points4 );

  // RNG rng(12345);
  Point2f rect_points[4]; rect_minAreaRect.points( rect_points );

  for ( int i=0; i<(int)points4.size(/*4*/); ++i ) {
    points4f.push_back(points4[i]);
  }

  bool is_mat_width = size_mat.width>size_mat.height; /*is width larger*/
  int small = min(rect_minAreaRect.size.width, rect_minAreaRect.size.height);
  int large = max(rect_minAreaRect.size.width, rect_minAreaRect.size.height);
  !is_mat_width && (small=small^large) && (large=small^large) && (small=small^large); /*XOR swap*/
  // Mat quad = Mat::zeros ( small, large, CV_8UC3 );
  Mat quad = Mat::zeros ( small, large, CV_8U );

  vector<Point2f> quad_pts;
  quad_pts.push_back(Point2f(0, 0));
  quad_pts.push_back(Point2f(quad.cols, 0));
  quad_pts.push_back(Point2f(quad.cols, quad.rows));
  quad_pts.push_back(Point2f(0, quad.rows));

  if ( points4f.size()==4 ) {
    outfile << "ok, doing pers transform and warp..." << points4f << endl;
    Mat transmtx = getPerspectiveTransform ( points4f, quad_pts );
    warpPerspective ( mat, quad, transmtx, quad.size() );

    imwrite ( IMG_PATH, quad ) ;
    ocr_doit ( quad );
  }
  else {
    outfile << "checking points4f... not 4 of number " << points4f << endl;
    // TODO rotate
    if ( mat.cols>mat.rows ){
      rot90 ( mat, 1 );
    }
    imwrite ( IMG_PATH, mat ) ;
    outfile << "DISPLAY_IMG" << endl;
  }
}
Exemplo n.º 11
0
// returns (a, (b,c)), three points which define the narrowest diameter of the hull as the pair of
// lines going through b,c, and through a, parallel to b,c TODO: This can be made linear time by
// moving point tc incrementally from the previous value (it can only move in one direction).  It
// is currently n*O(furthest)
double ConvexHull::narrowest_diameter(Point &a, Point &b, Point &c) {
    Point tb = boundary.back();
    double d = INFINITY;
    for(unsigned i = 0; i < boundary.size(); i++) {
        Point tc = boundary[i];
        Point n = -rot90(tb-tc);
        Point ta = *furthest(n);
        double td = dot(n, ta-tb)/dot(n,n);
        if(td < d) {
            a = ta;
            b = tb;
            c = tc;
            d = td;
        }
        tb = tc;
    }
    return d;
}
Exemplo n.º 12
0
//对于patches中需要更改的anchor处的patch,用ROI来对其进行覆盖
void exertPatch(Point anchor, Mat &ROI,Mat &dst,int pos)//我们认为左上角和右上角已经有数据了
{
    //pos没有用!!!
    const int edge = HALFPATCHSIZE;
    Mat newLeftTopROI(ROI, Rect(0,0, HALFPATCHSIZE, HALFPATCHSIZE));
    Mat oldLeftTopROI(dst, Rect(anchor.x, anchor.y, HALFPATCHSIZE, HALFPATCHSIZE));
    
    Mat seamMatrix(HALFPATCHSIZE, HALFPATCHSIZE, CV_8UC1, Scalar(0));
    
    for (int k = 0; k < PATCH_SIZE/2; k++)
    {
        for (int l = 0; l < PATCH_SIZE/2; l++)
        {
            //需要修改
            int diff = 0;
            for (int i = 0; i < 3; i++)
            {
                diff += abs(newLeftTopROI.at<Vec3b>(k, l)[i] - oldLeftTopROI.at<Vec3b>(k, l)[i]);
            }
            diff /= 3;
            //diff += 128;
            seamMatrix.at<uchar>(k, l) = diff;
        }
    }
    
    //将其顺时针旋转90度
    int rotIndex[4][2] = { { 1, 2 }, { 0, 0 }, { 2, 1 }, { 3, 3 } };
    rot90(seamMatrix, rotIndex[pos][0]);
    rot90(newLeftTopROI, rotIndex[pos][0]);
    rot90(oldLeftTopROI, rotIndex[pos][0]);
    Mat newdst = oldLeftTopROI.clone();
    
    //DP
    dp(seamMatrix, oldLeftTopROI, newLeftTopROI, newdst);
    
    //将其转回
    rot90(newLeftTopROI, rotIndex[pos][1]);
    rot90(oldLeftTopROI, rotIndex[pos][1]);
    rot90(newdst, rotIndex[pos][1]);
    newdst.copyTo(newLeftTopROI);
}
Exemplo n.º 13
0
static Image*
_cachedpage(Document *doc, int angle, int page, char *ra)
{
	int i;
	Cached *c, old;
	Image *im, *tmp;

	if((page < 0 || page >= doc->npage) && !doc->fwdonly)
		return nil;

Again:
	for(i=0; i<nelem(cache); i++){
		c = &cache[i];
		if(c->doc == doc && c->angle == angle && c->page == page){
			if(chatty) fprint(2, "cache%s hit %d\n", ra, page);
			goto Found;
		}
		if(c->doc == nil)
			break;
	}

	if(i >= nelem(cache))
		i = nelem(cache)-1;
	c = &cache[i];
	if(c->im)
		freeimage(c->im);
	c->im = nil;
	c->doc = nil;
	c->page = -1;

	if(chatty) fprint(2, "cache%s load %d\n", ra, page);
	im = doc->drawpage(doc, page);
	if(im == nil){
		if(doc->fwdonly)	/* end of file */
			wexits(0);
		im = questionmark();
		if(im == nil){
		Flush:
			if(i > 0){
				cacheflush();
				goto Again;
			}
			fprint(2, "out of memory: %r\n");
			wexits("memory");
		}
		return im;
	}

	if(im->r.min.x != 0 || im->r.min.y != 0){
		/* translate to 0,0 */
		tmp = xallocimage(display, Rect(0, 0, Dx(im->r), Dy(im->r)), im->chan, 0, DNofill);
		if(tmp == nil){
			freeimage(im);
			goto Flush;
		}
		drawop(tmp, tmp->r, im, nil, im->r.min, S);
		freeimage(im);
		im = tmp;
	}

	switch(angle){
	case 90:
		im = rot90(im);
		break;
	case 180:
		rot180(im);
		break;
	case 270:
		im = rot270(im);
		break;
	}
	if(im == nil)
		goto Flush;

	c->doc = doc;
	c->page = page;
	c->angle = angle;
	c->im = im;

Found:
	if(chatty) fprint(2, "cache%s mtf %d @%d:", ra, c->page, i);
	old = *c;
	memmove(cache+1, cache, (c-cache)*sizeof cache[0]);
	cache[0] = old;
	if(chatty){
		for(i=0; i<nelem(cache); i++)
			fprint(2, " %d", cache[i].page);
		fprint(2, "\n");
	}
	if(chatty) fprint(2, "cache%s return %d %p\n", ra, old.page, old.im);
	return old.im;
}
Exemplo n.º 14
0
//reflect a point into it's "mirror" with repect to a line
point2d reflectPoint(Line l, point2d p)
{
    Line r = rot90(l, p);
    point2d Y=intersect(l,r);
    return Y-(p-Y);
}
Exemplo n.º 15
0
// get a line passing between two points
Line getmidline(point2d a, point2d b)
{
    point2d mid(a+b); mid.x/=2; mid.y/=2;
    return rot90( makeline(a,b), mid );
}
Exemplo n.º 16
0
/**
* \brief returns all the parameter values of A whose tangent is parallel to vector V.
* \relates D2
*/
std::vector<double> find_tangents_by_vector(Point V, D2<SBasis> const &A) {
    SBasis crs = dot(derivative(A), rot90(V));
    return roots(crs);
}