Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // assignment3.cpp : Defines the entry point for the console application.
- //
- #include "stdafx.h"
- #include <stdlib.h>
- #include <stdio.h>
- #include <iostream>
- #include <cv.h>
- #include <cxcore.h>
- #include <highgui.h>
- #include <conio.h>
- #include <cxtypes.h>
- #include <math.h>
- #include <iostream>
- #include <algorithm>
- #include <fstream>
- #include <string>
- #include <sstream>
- using namespace std;
- void my_mouse_callback( int event, int x, int y, int flags, void* param );
- CvRect box;
- int press=0;
- int x1;
- int y11;
- int x2;
- int y2;
- int x3;
- int y3;
- int x4;
- int y4;
- IplImage* X;
- IplImage* Y;
- IplImage* Z;
- IplImage* test1;
- IplImage* test2;
- IplImage* test3;
- //IplImage* D1;
- //bool drawing_box = false;
- void LoadMyImage2()
- {
- //Load Image
- X = cvLoadImage("vodafone.png",0);
- Y = cvLoadImage("mobinile.png",0);
- Z = cvLoadImage("mobinila.png",0);
- //>0 the loaded image is forced to be a 3-channel color image
- //=0 the loaded image is forced to be a 1 channel grayscale image
- //<0 the loaded image is loaded as is (with number of channels in the file).
- //cvFindHomography cvWarpPerspective
- //CvMat* matrix=cvCreateMat(4,2,Cv32F
- }
- void showPicture2(IplImage* i, char* title)
- {
- //Create a Window
- cvNamedWindow(title,CV_WINDOW_AUTOSIZE);
- int mouseParam = 5;
- cvSetMouseCallback( title, my_mouse_callback,&mouseParam);
- //Display Image in Window
- cvShowImage(title, i);
- cvWaitKey();
- }
- IplImage* ezbotha(int x1,int y1,int x2,int y2, int x3,int y3,int x4 ,int y4,IplImage* src) {
- IplImage* dest=cvCloneImage(src);
- double xysrc[8] = {x1, x2, x3, x4,
- y1, y2, y3, y4};
- CvMat matrix1 = cvMat(2,4, CV_64F, xysrc);
- double xydst[8] = {x1, x2, x1, x2,
- y1, y1, y3, y3};
- CvMat matrix2 = cvMat(2,4, CV_64F, xydst);
- double heyheyhey[9];
- CvMat Homography= cvMat(3,3, CV_64F, heyheyhey);
- cvFindHomography(&matrix1,&matrix2,&Homography);
- cvWarpPerspective(src,dest,&Homography);
- return dest;
- }
- IplImage* threshold (IplImage* img){
- IplImage* copy=cvCloneImage(img);
- static uchar *created = (uchar *)copy->imageData;
- int height=copy->height;
- int width=copy->width;
- int channels= copy->nChannels;
- //now to color
- for(int i=0;i<height;i++) for(int j=0;j<width;j++) for(int k=0;k<channels;k++)
- {
- if(created[i*copy->widthStep +(j*copy->nChannels+k)] < 170 )
- {
- created[i*img->widthStep+(j*copy->nChannels+k)] = 255 ;
- }
- else
- {
- created[i*copy->widthStep+(j*copy->nChannels+k)] = 0 ; //Saturation
- }
- }
- return copy;
- }
- void my_mouse_callback( int event, int x, int y, int flags, void* param ){
- IplImage* image = (IplImage*) param;
- switch( event ){
- case CV_EVENT_LBUTTONDOWN:
- if (press==0){
- x1=x;
- y11=y;
- }
- else if (press==1){
- x2=x;
- y2=y;
- }
- else if (press==2){
- x3=x;
- y3=y;
- }
- else if (press==3){
- x4=x;
- y4=y;
- press =10;
- }
- press++;
- break;
- }}
- int _tmain(int argc, _TCHAR* argv[])
- {
- //When using the console you will have to try to make it user friendly
- //Use prints to explain to the user how to use your application
- //Take inputs from the user in form of commands to use your application
- LoadMyImage2();
- test1=cvLoadImage("IMG_0119.png",0);
- showPicture2(test1,"hussien");
- cout<<x1<<" "<<y11<<endl;
- cout<<x2<<" "<<y2<<endl;
- cout<<x3<<" "<<y3<<endl;
- cout<<x4<<" "<<y4<<endl;
- test2=ezbotha(x1,y11,x2,y2,x3,y3,x4,y4,test1);
- showPicture2(test2,"hussieeen");
- test3=threshold(test2);
- showPicture2(test3,"hussieeen");
- IplImage* distTransformImage = cvCreateImage(cvSize(test3->width, test3->height), test3->depth, test3->nChannels);
- cvDistTransform(test3, distTransformImage, CV_DIST_L1, CV_DIST_MASK_3, 0);
- showPicture2(distTransformImage,"man");
- //showPicture(A,"hussien");
- getch();
- return 1;
- return 0;
- }
Add Comment
Please, Sign In to add comment