RSS Subscription
Linux Howtos & Tutorials

Enter your email:

Delivered by


NOTE:New tutorials are from LinuxCareer.com

Poll

Do you own or wish to have iPhone?
 


Linux eBooks FREE Download
A guide to programming Linux kernel modules
Introduction to Linux - A Hands on Guide
A Newbie's Getting Started Guide to Linux

Linux from Scratch - Create Your Own Linux System - Free eBook

Linux: The Hacking Solution (v.3.0)

SQLite 3 with PHP Essential Training – Free Video Training Tutorials

This guide will introduce you to the world of GNU/Linux

The GNU/Linux Advanced Administration

A Complete Beginner's Manual for Ubuntu 10.04 (Lucid Lynx)

Advanced Bash-Scripting Guide

Set up, maintain, and secure a small office email server

Partner Linux Sites:
How-To.LinuxCareer.com
Jobs.LinuxCareer.com
TuxMachines
Monsterb
LinuxBloggers
AdamsInfo
LinuxScrew
All For Linux

OpenCV color to grayscale conversion program

Article Index
1. WRITE CODE
2. COMPILE
3. USAGE

To covert color image to a gray scale has never been easier with OpenCV. Here is a small C++ program that does conversion from color image to a grayscale.

1. WRITE CODE

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

using namespace std;

int main( int argc, char** argv )

{
//load color image specified by first argument
IplImage *source = cvLoadImage( argv[1]);

// create new image structure
// for the grayscale output image

IplImage *destination = cvCreateImage(
cvSize( source->width, source->height ), IPL_DEPTH_8U,
1 );



// set type CV_RGB2GRAY to convert
// RGB image to grayscale

cvCvtColor( source, destination, CV_RGB2GRAY );


// save grayscale image to a file specified by
// second argument

cvSaveImage( argv[2], destination );
return 0;

}

2. COMPILE

g++ `pkg-config opencv --cflags --libs` convert_grayscale.cpp -o convert_grayscale

3. USAGE

./convert_grayscale re_dsc00056.jpg gray_dsc00056.jpg

Share this linux post:

Submit OpenCV color to grayscale conversion program in Delicious Submit OpenCV color to grayscale conversion program in Digg Submit OpenCV color to grayscale conversion program in FaceBook Submit OpenCV color to grayscale conversion program in Google Bookmarks Submit OpenCV color to grayscale conversion program in Stumbleupon Submit OpenCV color to grayscale conversion program in Technorati Submit OpenCV color to grayscale conversion program in Twitter
 
Comments for this page are closed !!!
Please visit our new Linux Forum for additional help or discussion.


Linux eBooks FREE Download