Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // ***********************************************************************
- //
- // Demo program pro vyuku predmetu APPS (10/2012)
- // Petr Olivka, katedra informatiky, FEI, VSB-TU Ostrava
- // email:petr.olivka@vsb.cz
- //
- // Priklad pouziti CUDA technologie.
- // Prevedeni barevneho obrazku na odstiny sede.
- //
- // Pro manimulaci s obrazkem je pouzita knihovna OpenCV.
- //
- // ***********************************************************************
- #include <stdio.h>
- #include <cuda_runtime.h>
- #include "..\include\opencv\highgui.h"
- void joinImage( uchar4 *first, uchar4 *second,uchar4 *final, int width, int height );
- void run_grayscale( uchar4 *color_pic, uchar4 *bw_pic, uchar4 *MyO ,int sizex, int sizey );
- void run_rotace(uchar4 *input ,uchar4* output ,int sizex ,int sizey);
- void run_resize_low(uchar4 *input ,uchar4* output ,int sizex ,int sizey);
- void run_resize_big(uchar4 *input ,uchar4* output ,int sizex ,int sizey);
- int main( int numarg, char **arg )
- {
- if ( numarg < 2 )
- {
- printf( "Enter picture filename!\n" );
- return 1;
- }
- /////
- // nacteni obrazku
- IplImage *first = cvLoadImage( arg[ 1 ] );
- IplImage *second = cvLoadImage( arg[ 2] );
- int height = first->height;
- int width = first->width;
- uchar4 *firstImg = new uchar4[ width * height ];
- uchar4 *secondImg = new uchar4[ width * height ];
- uchar4 *finalImg = new uchar4[ width * height ];
- // vyplneni obrazku barevnym gradientem modra-zelena-cervena
- for ( int y = 0; y < height; y++ )
- for ( int x = 0; x < width; x++ )
- {
- CvScalar s = cvGet2D( first, y, x );
- uchar4 bgr = { (char) s.val[ 0 ], (char) s.val[ 1 ], (char) s.val[ 2 ] };
- firstImg[ y * width + x ] = bgr;
- }
- for ( int y = 0; y < height; y++ )
- for ( int x = 0; x < width; x++ )
- {
- CvScalar s = cvGet2D( second, y, x );
- uchar4 bgr = { (char) s.val[ 0 ], (char) s.val[ 1 ], (char) s.val[ 2 ] };
- secondImg[ y * width + x ] = bgr;
- }
- // prenos vypoctu do souboru .cu
- joinImage(firstImg,secondImg,finalImg,width,height);
- cvShowImage("Prvni",first);
- cvShowImage("Druhy",second);
- IplImage *joinedimg = cvCreateImage( cvSize( width, height ), IPL_DEPTH_8U, 3 );
- // prevedeni ziskanych dat do obrazku
- for ( int y = 0; y < height; y++ )
- for ( int x = 0; x < width; x++ )
- {
- uchar4 bgr = finalImg[ y * width + x ];
- CvScalar s = { bgr.x, bgr.y, bgr.z };
- cvSet2D( joinedimg, y, x, s );
- }
- // zobrazeni vysledku
- cvShowImage( "joinded image", joinedimg );
- cvWaitKey( 0 );
- //
- // nacteni obrazku
- IplImage *bgr_img = cvLoadImage( arg[ 1 ] );
- int sizex = bgr_img->width;
- int sizey = bgr_img->height;
- int lowsizex = sizex /2;
- int hightsizex = sizex *2;
- int lowsizey = sizey /2;
- int hightsizey = sizex *2;
- // alokace poli uchar4 pro body obrazku a jeho naplneni
- uchar4 *bgr_pole = new uchar4[ sizex * sizey ];
- uchar4 *bw_pole = new uchar4[ sizex * sizey ];
- uchar4 *MyO_pole = new uchar4[ sizex * sizey ];
- uchar4* Rotate_pole = new uchar4[sizex * sizey];
- uchar4 *lowpole = new uchar4[lowsizex * lowsizey];
- uchar4 *bigpole = new uchar4[hightsizex * hightsizey];
- /// input obrazku do pole bgr
- for ( int y = 0; y < sizey; y++ )
- for ( int x = 0; x < sizex; x++ )
- {
- CvScalar s = cvGet2D( bgr_img, y, x );
- uchar4 bgr = { (char) s.val[ 0 ], (char) s.val[ 1 ], (char) s.val[ 2 ] };
- bgr_pole[ y * sizex + x ] = bgr;
- }
- // volani funkce ze souboru .cu
- run_grayscale( bgr_pole, bw_pole, MyO_pole ,sizex, sizey );
- run_rotace(bgr_pole,Rotate_pole,sizex,sizey);
- run_resize_low(bgr_pole,lowpole,sizex,sizey);
- run_resize_big(bgr_pole,bigpole,sizex,sizey);
- IplImage *bw_img = cvCreateImage( cvSize( sizex, sizey ), IPL_DEPTH_8U, 3 );
- IplImage *MyO = cvCreateImage( cvSize( sizex, sizey ), IPL_DEPTH_8U, 3 );
- IplImage *RotateImage = cvCreateImage( cvSize( sizey, sizex ), IPL_DEPTH_8U, 3 );
- IplImage *LowImage = cvCreateImage( cvSize( lowsizex, lowsizey ), IPL_DEPTH_8U, 3 );
- IplImage *BigImage = cvCreateImage( cvSize( hightsizex, hightsizey ), IPL_DEPTH_8U, 3 );
- // maly obrazek
- for ( int y = 0; y < lowsizey; y++ )
- for ( int x = 0; x < lowsizex; x++ )
- {
- uchar4 bgr = lowpole[ y * lowsizex + x ];
- CvScalar s = { bgr.x, bgr.y, bgr.z };
- cvSet2D( LowImage, y, x, s );
- }
- // velky obrazek
- for ( int y = 0; y < hightsizey; y++ )
- for ( int x = 0; x <hightsizex; x++ )
- {
- uchar4 bgr = bigpole[ y * hightsizex + x ];
- CvScalar s = { bgr.x, bgr.y, bgr.z };
- cvSet2D( BigImage, y, x, s );
- }
- // ziskana data ulozime do noveho obrazku
- for ( int y = 0; y < sizey; y++ )
- for ( int x = 0; x < sizex; x++ )
- {
- uchar4 bgr = bw_pole[ y * sizex + x ];
- CvScalar s = { bgr.x, bgr.y, bgr.z };
- cvSet2D( bw_img, y, x, s );
- }
- // ziskana data ulozime do noveho obrazku
- for ( int y = 0; y < sizey; y++ )
- for ( int x = 0; x < sizex; x++ )
- {
- uchar4 bgr1 = MyO_pole[ y * sizex + x ];
- CvScalar s = { bgr1.x, bgr1.y, bgr1.z };
- cvSet2D( MyO, y, x, s );
- }
- /// zobrayeni rotovaneho obrazku
- for ( int y = 0; y < sizex; y++ )
- for ( int x = 0; x < sizey; x++ )
- {
- uchar4 bgr = Rotate_pole[ y * sizey + x ];
- CvScalar s = { bgr.x, bgr.y, bgr.z };
- cvSet2D (RotateImage, y, x, s );
- }
- // zobrazeni puvodniho obrazku a vysledku
- cvShowImage( "Color", bgr_img );
- cvShowImage( "GrayScale", bw_img );
- cvShowImage( "MojeUprava",MyO);
- cvShowImage( "rotace",RotateImage);
- cvShowImage( "zmenseni",LowImage );
- cvShowImage( "zvetseni",BigImage );
- cvWaitKey( 0 );
- }
Add Comment
Please, Sign In to add comment