Linux System Administration

This small OpenCV program demonstrates how to separate RGB image into R, G and B components. The program is written in low level programming as there are build in function in OpenCV which would make this code more efficient. However, this example deepens an understanding on how image is split into matrix of pixels and how can each pixel can be manipulated separately.

WRITE CODE

#include <iostream>
#include "cv.h"
#include "highgui.h"

using namespace std;

int main( int argc, char** argv )

{
//load color img specified by first argument
//IplImage *img = cvLoadImage( argv[1]);
IplImage *img = cvLoadImage
(argv[1], CV_LOAD_IMAGE_COLOR );


IplImage *red = cvCreateImage

(cvSize(img->width, img->height ),
img->depth, img->nChannels );

IplImage *green = cvCreateImage
(cvSize(img->width, img->height ),
img->depth, img->nChannels );

IplImage *blue = cvCreateImage
(cvSize(img->width, img->height ),
img->depth, img->nChannels );



// setup the pointer to access img data
uchar *pImg = ( uchar* )img->imageData;

// setup pointer to write data
uchar *pRed = ( uchar* )red->imageData;
uchar *pGreen = ( uchar* )green->imageData;
uchar *pBlue = ( uchar* )blue->imageData;



int i, j, rED, gREEN, bLUE, byte;
for( i = 0 ; i < img->height ; i++ )
{

for( j = 0 ; j < img->width ; j++ )
{
rED = pImg[i*img->widthStep + j*img->nChannels + 2];

gREEN = pImg[i*img->widthStep + j*img->nChannels + 1];
bLUE = pImg[i*img->widthStep + j*img->nChannels + 0];
// RED

pRed[i*img->widthStep + j*img->nChannels + 2] = rED;
// GREEN
pGreen[i*img->widthStep + j*img->nChannels + 1] = gREEN;

// BLUE
pBlue[i*img->widthStep + j*img->nChannels + 0] = bLUE;
}
}
// save images

cvSaveImage( argv[2], red );
cvSaveImage( argv[3], green );
cvSaveImage( argv[4], blue );

return 0;

}

COMPILE

g++ `pkg-config opencv --cflags --libs` \ 
separate-RGB.cpp -o separate-RGB

USAGE

./separate-RGB img.png red.png green.png blue.png

Sometimes we would like to instruct apache to redirect all incoming visitors from our_sample_domain.com to www.our_sample_domain.com

to do this we need to amend .htaccess file as follows:

# RewriteCond %{HTTP_HOST} ^our_sample_domain.com\.com$ [NC]
# RewriteRule .* our_sample_domain.com/ [L,R=301]

Instead of conventional burning method using GUI application there are also many ways on how to burn a ISO image to a CD-RW or CD-R from a command line. One way is to use a wodim command. Firs we use wodim to detect our burning device:

# wodim --devices

OUTPUT:

wodim: Overview of accessible drives (1 found) :
-------------------------------------------------------------------------
 0  dev='/dev/scd0'     rwrw-- : 'TSSTcorp' 'CD/DVDW SH-S183L'
-------------------------------------------------------------------------

now we can combine the device file of our burning device with wodim command to write actual ISO image:

wodim -eject  -tao speed=0 dev=/dev/scd0 -v -data /my/directory/image.iso

if you get an error mesage saying : wodim: trying to use a high speed medium on low writter try use higher burninng speed such us speed=1 or speed=2:

wodim -eject  -tao speed=1 dev=/dev/scd0 -v -data /my/directory/image.iso

Page 67 of 72



Go to top