Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- #include "opencv/cv.h"
- #include "opencv/highgui.h"
- #include "opencv/cxcore.h"
- #define scale 1
- int main(int argc, char* argv[])
- {
- int w, h, nc; int step;
- int x, y, i;
- IplImage* img = cvLoadImage("/Users/ranhao/Desktop/introduce to multimedia/hk1/hk1/hk1/7213_Kobe.jpg", CV_LOAD_IMAGE_UNCHANGED );
- //IplImage* img2 = cvLoadImage("/Users/ranhao/Desktop/introduce to multimedia/hk1/kb.jpg", CV_LOAD_IMAGE_UNCHANGED );
- /*
- #define CV_LOAD_IMAGE_UNCHANGED -1 原圖影像
- #define CV_LOAD_IMAGE_GRAYSCALE 0 灰階
- #define CV_LOAD_IMAGE_COLOR 1 彩色
- #define CV_LOAD_IMAGE_ANYDEPTH 2 任何彩度
- #define CV_LOAD_IMAGE_ANYCOLOR 4 任何彩色
- */
- IplImage* dst;
- IplImage* img3;
- int Y, R, G, B;
- int *ary[9]={0};
- double alpha ;
- double beta ;
- //if( argc == 2 && (img = cvLoadImage(argv[1], -1)) != 0 )
- if( img != 0 ) //
- {
- printf("Channels %d depth %d widthStep %d \n",
- img->nChannels, img->depth, img->widthStep);
- printf("The image Width by Height is %d * %d \n", img->width,img->height);
- printf("The image origin is %d\n", img->origin);
- step = img->widthStep;
- w = img->width;
- h = img->height;
- nc = img->nChannels;
- dst = cvCreateImage(
- cvSize(w, h), //CvSize size,
- IPL_DEPTH_8U , //int depth,
- nc //int channels
- );
- img3 = cvCreateImage(
- cvSize(w, h), //CvSize size,
- IPL_DEPTH_8U , //int depth,
- nc //int channels
- );
- //Open first image
- cvNamedWindow( "Image 1", 1 );
- cvMoveWindow("Image 1", 0, 0);
- cvShowImage( "Image 1", img );
- cvWaitKey(0); //0:wait for entering any keys ; number:unit is ms;
- //Open second image
- /*
- cvNamedWindow( "Image 2", 1 );
- cvMoveWindow("Image 2", 630, 0); //Move to other point on screen
- cvShowImage( "Image 2", img2 );
- cvWaitKey(0);
- */
- uchar* ptr;
- uchar* ptr2;
- int temp;
- for (y = 1; y < h-1; y++) // using macro
- {
- for (x = 1; x < w-1; x++)
- {
- ptr = &CV_IMAGE_ELEM(img, uchar, y, x *3);
- ptr2 = &CV_IMAGE_ELEM(img3, uchar, y, x *3);
- //CV_IMAGE_ELEM( image, elemtype, row, col )
- //Iplimage BGR
- temp =
- 0*ptr[-2-2*step] + ptr[-1-2*step] + 2*ptr[-2*step] + ptr[1-2*step] + 0*ptr[2-2*step] +
- ptr[-2-step] + 3*ptr[-1-step] + 5*ptr[0-step] + 3*ptr[1-step] + ptr[2-step] +
- 2*ptr[-2] + 5*ptr[-1] + 9*ptr[0] + 5*ptr[1] + 2*ptr[2] +
- ptr[step-2] + 3*ptr[step-1] + 5*ptr[step+0] + 3*ptr[step+1] + ptr[step+2] +
- 0*ptr[2*step-2] + ptr[-1+2*step] + 2*ptr[2*step] + ptr[1+2*step] + 0*ptr[2+2*step] ;
- // 5*5 Filter
- /*
- 0 1 2 1 0
- 1 3 5 3 1
- 2 5 9 5 2
- 1 3 5 3 1
- 0 1 2 1 0
- */
- ptr2[0] = temp/25;
- }
- }
- cvNamedWindow("Image 3", 1);
- cvMoveWindow("Image 3", 630, 0);
- for (alpha=0.0; alpha<=1.0; alpha = alpha + 0.1)
- {
- beta = 1 - alpha;
- cvAddWeighted(img, beta, img3, alpha, 0.0, dst);
- cvShowImage("Image 3", dst);
- cvWaitKey(150);
- }
- cvWaitKey(0);
- //Destroy and release
- cvDestroyWindow( "Image 2" );
- cvDestroyWindow( "Image 1" );
- //cvDestroyWindow( "Image 4" );
- cvDestroyWindow( "Image 3" );
- cvReleaseImage( &dst );
- cvReleaseImage( &img3 );
- cvReleaseImage( &img );
- //cvReleaseImage( &img2 );
- return 0;
- }
- printf("Can't open image file\n");
- //system("PAUSE");
- return -1;
- }
Advertisement
Add Comment
Please, Sign In to add comment