Opencv--skewing

Source: Internet
Author: User

Define head function#ifndef ps_algorithm_h_included#define ps_algorithm_h_included#include <iostream># Include <string> #include "cv.h" #include "highgui.h" #include "cxmat.hpp" #include "cxcore.hpp" #include "math.h" Using namespace Std;using namespace Cv;void show_image (mat&, const string &); #endif//ps_algorithm_h_included# Include "ps_algorithm.h" #include <time.h>using namespace std;using namespace CV; #define PI 3.1415926int main () {s    Tring Img_name ("4.jpg");    Mat Img;    Img=imread (Img_name);    float THETA=PI/6;    int width=img.cols;    int height=img.rows;    /*//horizontal skewing int new_height=height;    int New_width=width+height*tan (theta) +1;    Mat Img_h=mat::zeros (New_height,new_width, CV_8UC3);    float Dis;    float new_x, new_y;    Float x1, y1, p;        for (int y=0; y<new_height; y++) {dis= (height-y) *tan (theta);           for (int x=0; x<new_width; x + +) {new_y=y; Right skew//NEW_x=x-dis;          Left skew New_x=x+dis-height*tan (theta);          if (new_x<0) new_x=0;          if (new_x>width-1) new_x=width-2;                if (new_x>0 && new_x<width-1) {x1=int (new_x);                Y1=int (new_y);                p=new_x-x1;                Img_h.at<vec3b> (y,x) [0]= (1-p) *img.at<vec3b> (y1,x1) [0]+p*img.at<vec3b> (y1,x1+1) [0];                Img_h.at<vec3b> (y,x) [1]= (1-p) *img.at<vec3b> (y1,x1) [1]+p*img.at<vec3b> (y1,x1+1) [1];          Img_h.at<vec3b> (y,x) [2]= (1-p) *img.at<vec3b> (y1,x1) [2]+p*img.at<vec3b> (y1,x1+1) [2];    }}} show_image (Img_h, "out");    Imwrite ("H.jpg", img_h);    *///Vertical skewing int New_height=height+width*tan (theta) +1;    int new_width=width;    Mat Img_v=mat::zeros (New_height,new_width, CV_8UC3);    float Dis;    float new_x, new_y;    Float x1, y1, p;  for (int y=0; y<new_height; y++) {      for (int x=0; x<new_width; x + +) {Dis=x*tan (theta);           New_x=x;           Right skew New_y=y-dis;          Left skew//New_y=y+dis-width*tan (theta);                if (new_y>0 && new_y


Original




Opencv--skewing

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.