Created
November 29, 2013 07:34
-
-
Save kumarkrishna/7702612 to your computer and use it in GitHub Desktop.
Creating Image
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//Author: Kumar Krishna Agarwal | |
//Mail : kumar.1994.14@gmail.com | |
#include <iostream> | |
#include <highgui.h> | |
#include <cv.h> | |
int main() | |
{ | |
IplImage* img; | |
//Creating Image | |
img=cvCreateImage(cvSize(400,400),IPL_DEPTH_8U,3); | |
/* cvCreateImage(cvSize(width,height),<depth stream>,<no. of channels>) */ | |
CvScalar pixel,pix1,pix2; //structure to store four values | |
cvNamedWindow("window",0); | |
int i,j | |
; | |
for(i=0;i<img->height/3;i++) | |
{ | |
for(j=0;j<img->width;j++) | |
{ | |
//Setting the values for Blue,Red and Green Stream | |
pixel.val[0]=255; //Blue | |
pixel.val[1]=0; //Green | |
pixel.val[2]=0; //Red | |
cvSet2D(img,i,j,pixel); //Set pixel | |
/*cvSet2D(<image name>,<x coord>,<y coord>, <name of pixel>) */ | |
} | |
} | |
for(i=img->height/3;i<2*img->height/3;i++) | |
{ | |
for(j=0;j<img->width;j++) | |
{ | |
pixel.val[0]=0; | |
pixel.val[1]=255; | |
pixel.val[2]=0; | |
cvSet2D(img,i,j,pixel); | |
} | |
} | |
for(i=2*img->height/3;i<img->height;i++) | |
{ | |
for(j=0;j<img->width;j++) | |
{ | |
pixel.val[0]=0; | |
pixel.val[1]=0; | |
pixel.val[2]=255; | |
cvSet2D(img,i,j,pixel); | |
} | |
} | |
cvShowImage("window",img); //Show Image | |
cvWaitKey(3000); //Wait Key (Default is keyStroke) | |
cvReleaseImage(&img); //Release image | |
cvDestroyWindow("window"); //Destroy window | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment