Difference between revisions of "Цифрови камери"

From Ilianko
Line 1: Line 1:
 +
==Инсталация openCV==
 +
 +
 +
 +
1. Инсталирайте cmake
 +
sudo apt-get install cmake
 +
 +
2. Инсталирайте библиотеката libgtk2.0-dev
 +
sudo apt-get install libgtk2.0-dev
 +
 +
3. да се свали openCV 2.2 и разархивирайте в директория Downloads/OpenCV-2.2.0
 +
 +
4. Влезте в директорията
 +
cd Downloads/OpenCV-2.2.0
 +
cmake -D CMAKE_BUILD_TYPE=RELEASE -D CMAKE_INSTALL_PREFIX=/usr/local ./
 +
make
 +
make install
 +
 +
export LD_LIBRARY_PATH=/home/lab/Downloads/OpenCV-2.2.0/lib:$LD_LIBRARY_PATH sudo ldconfig
 +
 +
-lopencv_core -lopencv_imgproc -lopencv_calib3d -lopencv_video -lopencv_features2d -lopencv_ml -lopencv_highgui -lopencv_objdetect -lopencv_contrib -lopencv_legacy
 +
 +
 
1. Разглежда не R, G, B каналите
 
1. Разглежда не R, G, B каналите
  

Revision as of 20:27, 30 January 2012

Инсталация openCV

1. Инсталирайте cmake sudo apt-get install cmake

2. Инсталирайте библиотеката libgtk2.0-dev

sudo apt-get install libgtk2.0-dev

3. да се свали openCV 2.2 и разархивирайте в директория Downloads/OpenCV-2.2.0

4. Влезте в директорията

cd Downloads/OpenCV-2.2.0
cmake -D CMAKE_BUILD_TYPE=RELEASE -D CMAKE_INSTALL_PREFIX=/usr/local ./
make
make install
export LD_LIBRARY_PATH=/home/lab/Downloads/OpenCV-2.2.0/lib:$LD_LIBRARY_PATH sudo ldconfig
-lopencv_core -lopencv_imgproc -lopencv_calib3d -lopencv_video -lopencv_features2d -lopencv_ml -lopencv_highgui -lopencv_objdetect -lopencv_contrib -lopencv_legacy


1. Разглежда не R, G, B каналите

#include <opencv/highgui.h> //OpenCV GUI functions ̄include <stdio.h>
#include <opencv/cv.h> //main OpenCV functions

int main()
{
  
  IplImage *img, *img_r, *img_g, *img_b ; // image structer
  int x,y, w = 512, h = 512; //image size
  
  
  img_r = cvCreateImage( cvSize( w, h ), IPL_DEPTH_8U, 1 );
  img_g = cvCreateImage( cvSize( w, h ), IPL_DEPTH_8U, 1 );
  img_b = cvCreateImage( cvSize( w, h ), IPL_DEPTH_8U, 1 );
  
  img = cvLoadImage("lena_std.tif",1);
  
  for(x=0; x<img->width; x++)
	{
		for(y=0;y<img->height; y++)
		{
			(img_r->imageData + img_r->widthStep*y)[x]= (img->imageData + img->widthStep*y)[x*3+2];
			(img_g->imageData + img_g->widthStep*y)[x]= (img->imageData + img->widthStep*y)[x*3+1];
			(img_b->imageData + img_b->widthStep*y)[x]= (img->imageData + img->widthStep*y)[x*3];
		}
	}
  
 
  cvNamedWindow("red", 1);
  //display the image in the window
  cvShowImage("red", img_r);
  
  cvNamedWindow("green", 1);
  //display the image in the window
  cvShowImage("green", img_g);
  
  cvNamedWindow("blue", 1);
  //display the image in the window
  cvShowImage("blue", img_b);
  
  cvNamedWindow("rgb", 1);
  //display the image in the window
  cvShowImage("rgb", img);
  
  //wait for key to close the window  
  cvWaitKey(0);
  cvDestroyWindow( "blue" ); //destroy the window
  cvDestroyWindow( "red" ); 
  cvDestroyWindow( "green" );
  cvDestroyWindow( "rgb" );  
  cvReleaseImage( &img ); //release the memory for the image
  cvReleaseImage( &img_r );
  cvReleaseImage( &img_g );
  cvReleaseImage( &img_b );
  
return 0;
}


2. Получаване на черно бяло изображение

include <opencv/highgui.h> //OpenCV GUI functions ̄include <stdio.h>
#include <opencv/cv.h> //main OpenCV functions


int main()
{
  
  IplImage *img, *img_bw ; // image structure
  int x,y, w = 512, h = 512; //image size
  
  
  img_bw = cvCreateImage( cvSize( w, h ), IPL_DEPTH_8U, 1 );
  
  img = cvLoadImage("lena_std.tif",1);
  
  for(x=0; x<img->width; x++)
	{
		for(y=0;y<img->height; y++)
		{

			(img_bw->imageData + img_bw->widthStep*y)[x] =    
			   ((uchar)((img->imageData + img->widthStep*y)[x*3+2])  >> 2 ) +  ((uchar)((img->imageData + img->widthStep*y)[x*3+2])  >> 4 ) +
			   ((uchar)((img->imageData + img->widthStep*y)[x*3+1])  >> 1 ) +  ((uchar)((img->imageData + img->widthStep*y)[x*3+1])  >> 4 ) +
			   ((uchar)((img->imageData + img->widthStep*y)[x*3])    >> 3 );
			                                                      
		}
	}
  
 
  cvNamedWindow("rgb", 1);
  //display the image in the window
  cvShowImage("rgb", img);
  
  cvNamedWindow("bw", 1);
  //display the image in the window
  cvShowImage("bw", img_bw);
  
 
  //wait for key to close the window  
  cvWaitKey(0);
  cvDestroyWindow( "bw" );
  cvDestroyWindow( "rgb" );  
  cvReleaseImage( &img ); //release the memory for the image
  cvReleaseImage( &img_bw );
  
return 0;
}

3. Извличане на Bayer pattern

#include <opencv/highgui.h> //OpenCV GUI functions ̄include <stdio.h>
#include <opencv/cv.h> //main OpenCV functions


int main()
{
  
  IplImage *img, *img_bw ; // image structure
  int x,y, w = 512, h = 512; //image size
  
  
  img_bw = cvCreateImage( cvSize( w, h ), IPL_DEPTH_8U, 1 );
  
  img = cvLoadImage("lena_std.tif",1);
  
  int b = 1, r = 0, g = 1, br = 0;
  for(x=0; x<img->width; x++)
	{
		b = ( b == 1 ) ? 0 : 1;
		r = ( r == 1) ?  0 : 1;
		for(y=0;y<img->height; y++)
		{
           g = (g == 1) ? 0 : 1;
           br = (br == 1) ? 0 : 1;
        (img_bw->imageData + img_bw->widthStep*y)[x] =        
          ((uchar)((img->imageData + img->widthStep*y)[x*3+2])*br*r)+
          ((uchar)((img->imageData + img->widthStep*y)[x*3+1])*br*b) + ((uchar)((img->imageData + img->widthStep*y)[x*3+1])*g*r)+
	      ((uchar)((img->imageData + img->widthStep*y)[x*3])*g*b);  
			                                                      
		}
	}
  
 
  cvNamedWindow("rgb", 1);
  //display the image in the window
  cvShowImage("rgb", img);
  
  cvNamedWindow("bw", 1);
  //display the image in the window
  cvShowImage("bw", img_bw);
  
  cvSaveImage("raw.bmp", img_bw, 0);

  //wait for key to close the window  
  cvWaitKey(0);
  cvDestroyWindow( "bw" );
  cvDestroyWindow( "rgb" );  
  cvReleaseImage( &img ); //release the memory for the image
  cvReleaseImage( &img_bw );
  
return 0;
}

4. Преобразуване от bayer pattern в RGB

#include <opencv/highgui.h> //OpenCV GUI functions ̄include <stdio.h>
#include <opencv/cv.h> //main OpenCV functions


int main()
{
  
  IplImage *img, *img_bw ; // image structure
  int x,y, w = 512, h = 512; //image size
  
  
  img = cvCreateImage( cvSize( w, h ), IPL_DEPTH_8U, 3 );
  
  img_bw = cvLoadImage("raw.bmp",0);
  
  int b = 0, r = 1, g = 1, br = 0;
  for(x=1; x<img->width-1; x++)
	{
		b = ( b == 1 ) ? 0 : 1;
		r = ( r == 1) ?  0 : 1;
		for(y=1;y<img->height-1; y++)
		{
          g = (g == 1) ? 0 : 1;
          br = (br == 1) ? 0 : 1;
          
          (img->imageData + img->widthStep*y)[x*3] = (img_bw->imageData + img_bw->widthStep*(y-1*g))[x-1*r];
          
          (img->imageData + img->widthStep*y)[x*3+1] = (img_bw->imageData + img_bw->widthStep*(y+1*br))[x]*b +
                                                       (img_bw->imageData + img_bw->widthStep*(y+1*g))[x]*r;
          
          
	   (img->imageData + img->widthStep*y)[x*3+2]  =  (img_bw->imageData + img_bw->widthStep*(y+1*br))[x+1*b] ;
          
	                                                      
		}
	}
  
 
  cvNamedWindow("rgb", 1);
  //display the image in the window
  cvShowImage("rgb", img);
  
  cvNamedWindow("bw", 1);
  //display the image in the window
  cvShowImage("bw", img_bw);
  
  cvSaveImage("out1.bmp", img, 0);

  //wait for key to close the window  
  cvWaitKey(0);
  cvDestroyWindow( "bw" );
  cvDestroyWindow( "rgb" );  
  cvReleaseImage( &img ); //release the memory for the image
  cvReleaseImage( &img_bw );
  
return 0;
}

5. Оценка на разликите