Writing PPM image file in C++
Following is the C++ code for writting the ppm image file
strtemp has file name,
fData is the pointer to the image data.
sprintf(strtemp,”%04d.ppm”,imageNo);
ofstream output(strtemp, ios::binary|ios::out);
if(!output){
cout << ” unable to open the output file “<< strtemp << endl;
}
else{
output << “P6″<< endl <<“# foreground “<<endl;
output << itoa(IWidth, strtemp, 10);
output << ” “;
output << itoa(IHeight, strtemp, 10);
output << endl;
output << itoa(255, strtemp, 10) << endl;
output.write( (char *)fData, IHeight*IWidth*3);
output.close();};//end of else
OpenCv IplImage how to clear or initialize the image to scalar
just use the cvSet
e.g if img is the IplImage object pointer with 3 channels.
cvSet(img, cvScalar(0,0,0));
will set each and every pixel to zero.
Becarefull with the channels and cvScalar used.
GLSL: Accessing one row of the texture
//Fragment Shader Program to access texture and just copying one row to other
uniform sampler2D textureX;
uniform float texRows;
uniform float texCols;
void main(void) {
//cols rows
vec4 x = texture2D(textureX, vec2(gl_TexCoord[0].s, gl_TexCoord[0].t+1.0/texRows));
gl_FragColor = x;
}
GLSL Texture
Coordinates of the gl_TexCoord[0]
gl_TexCoord[0].t —— rows
gl_TexCoord[0].s ——cols
vec4 x = texture2D(textureX, vec2(Columns, rows));
gl_FragColor = x;
Assignment 3; Textures Very Imp Links
Use glEnable(GL_TEXTURE_2D);
GPU Programming Course http://www.evl.uic.edu/aej/594/
For the Multi Texturing refer to
http://www.clockworkcoders.com/oglsl/tutorial8.htm
glActiveTextureARB(GL_TEXTURE0_ARB); glBindTexture(GL_TEXTURE_2D, texture1); glEnable(GL_TEXTURE_2D); glTexEnvf (GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_COMBINE_EXT); glTexEnvf (GL_TEXTURE_ENV, GL_COMBINE_RGB_EXT, GL_REPLACE); glActiveTextureARB(GL_TEXTURE1_ARB); glBindTexture(GL_TEXTURE_2D, texture2); glEnable(GL_TEXTURE_2D); glTexEnvf (GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_COMBINE_EXT); glTexEnvf (GL_TEXTURE_ENV, GL_COMBINE_RGB_EXT, GL_INCR);
http://www.evl.uic.edu/aej/594/lecture04.html http://www.research.rutgers.edu/~sueda/428Fall2005/proj3.html Texture Rectangle http://www.opengl.org/registry/specs/ARB/texture_rectangle.txt The Dominick Page http://www.mathematik.uni-dortmund.de/~goeddeke/gpgpu/tutorial.html http://www.mathematik.uni-dortmund.de/~goeddeke/gpgpu/saxpy_glsl2.cpp http://code.google.com/p/matpix/source/browse/trunk/src/helloGPGPU.cpp
Settingup Texture to read the Frame Buffer
<good link http://www.mathematik.tu-dortmund.de/~goeddeke/gpgpu/saxpy_glsl.cpp>
These are basic steps to take
For each texture do the following things
1) Generate the texture
glGenTextures(1, texId);
2) Then Bind the texture to what target you want
glBindTexture( GL_TEXTURE_RECTANGLE_ARB, tex);
3) Setup the properties to avoid the wraping on edges, min-mapping,
glTexParameteri(GL_TEXTURE_RECTANGLE_ARB, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
glTexParameteri(GL_TEXTURE_RECTANGLE_ARB, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
//clamp so that it does not excede where you do want to write
glTexParameteri(GL_TEXTURE_RECTANGLE_ARB, GL_TEXTURE_WRAP_S, GL_CLAMP);
glTexParameteri(GL_TEXTURE_RECTANGLE_ARB, GL_TEXTURE_WRAP_T, GL_CLAMP);
4) Use the glTexImage2D to setup the properties like for format, type, height and width of the texture
Gaussian Masks
Gaussian Masks (2D Normal Distribution)
Just Placing Masks so that one does not have to generate again when wanting to use quickly.
For the Matlab Code you can go to https://whatevericode.wordpress.com/2008/03/24/genrating-gaussian-mask/
Standard Deviation 1
0.0030 0.0133 0.0219 0.0133 0.0030
0.0133 0.0596 0.0983 0.0596 0.0133
0.0219 0.0983 0.1621 0.0983 0.0219
0.0133 0.0596 0.0983 0.0596 0.0133
0.0030 0.0133 0.0219 0.0133 0.0030
Standard Deviation 0.5
0.0113 0.0838 0.0113
0.0838 0.6193 0.0838
0.0113 0.0838 0.0113
Standard Deviation 0.25
0.0000 0.0003 0.0000
0.0003 0.9987 0.0003
0.0000 0.0003 0.0000
(ReadShader)Simple File Reading Code in C++ with File Size buffer
//impressed by lighthouse 3d and help taken from sources on the internet.
//this is not my idea, not my full code.
//It reads the full file in single go.
#ifndef READSHADER_H
#define READSHADER_H
#include
#include
using namespace std;
char * readShader(char *fileName){
cout <<“nothing”;
ifstream input(fileName);
if(!input){
cout << endl << “UNABLE TO OPEN FILE ” << fileName <<endl;
return 0;
}
int st = input.tellg();
input.seekg(0, ios::end);
int end = input.tellg();
int fileSize = end – st;
if(fileSize <= 0){return 0;}
char *data = new char[fileSize+50];//50 added to just have buffer
memset(data, ”,fileSize+10);
input.seekg(0, ios::beg);
input.read(data,fileSize);
input.close();
data[fileSize]= ”; //appending the zero as the read does not append that
return data;
};
#endif