C++ :: Accessing Pixel RGB Values In Float Format?
Apr 7, 2013
I have tried everything and i still can't access pixel RGB values in float format.
I tried vec3b which produces strange characters which i can't covert to float as it says no suitable function exists.
I tried vector<float> RGB;
with RGB = image.at<vector<float>>(row,col);
I get a unhandled exception error.
So whatever i do, if it is syntax correct i get unhandled exception error. If it should work i get this stupid error. I need it for chroma keying.
View 4 Replies
ADVERTISEMENT
Dec 30, 2014
I would like to subtract one image from another to get something like "differential picture" (i am not sure whether the name is correct). I've managed to read the FILEHEADER and FILEINFOHEADER of bitmap. I will subtract 24-bit bmp files only. However i can't understand the structure of this file. So far my code looks like this. Any example of at least copying one bmp file to a new one? This example would be useful, because subtracting will be simillar, instead of copying the pixel value i will just put abs(value1-value2) in the output.
Code:
// ConsoleApplication1.cpp : Defines the entry point for the console application.
#include "stdafx.h"
#include <iostream>
#include <fstream>
using namespace std;
struct BITMAPfileHEADER {
[Code] .....
View 4 Replies
View Related
Mar 7, 2013
I am writing a C program to access a string into an array from a pointer array in Visual Studio 2010. Program is given below:-
Code:
#include <stdio.h>
#include <string.h>
void main() {
char data_a[6],data_b[6]="ABcde",*ptr;
ptr=&data_b[0];
data_a[0]=*ptr;
printf("%s",a);
}
I am getting some junk character first and then my actual data on console window. I want to where I am getting wrong and how to resolve it.
View 4 Replies
View Related
Feb 8, 2014
I'm okay with 2-dimensional arrays, but when I get to 3 or more, I can't seem to wrap my head around how to assign and/or pull values from specific parts.
To give an example, let's take the following example:
We know that a player can take up to 5 total quests, and each quest can have a max of 5 tasks.
Let's assume I have the following multi-dimensional array holding all of a players quest data:
quests[0] = 78;// Store the questID
quests[0][0] = 3945;// Store the 1st creature ID
quests[0][1] = 2230;// Store the 2nd creature ID
quests[0][2] = 3045;// Store the 3rd creature ID
quests[0][0][0] = 2;// Store how many needed of the 1st creature
quests[0][1][0] = 5;// Store how many needed of the 2nd creature
quests[0][2][0] = 13;// Store how many needed of the 3rd creature
As we know, the above code can't be done. How do I assign certain values to each specific dimension?
View 6 Replies
View Related
Aug 5, 2013
I am trying to write down in binary format an array of unsigned int values but i get the following compilation error :
: In function ‘int CIndex(std::fstream&, std::fstream&, std::fstream&, std::fstream&)’:
./src/IndexBuilder/index.cpp:23:26: error: no matching function for call to ‘std::basic_fstream<char>::write(int*, long unsigned int)’
./src/IndexBuilder/index.cpp:23:26: note: candidate is:
/usr/include/c++/4.6/bits/ostream.tcc:184:5: note: std::basic_ostream<_CharT, _Traits>& std::basic_ostream<_CharT, _Traits>::write(const _CharT*, std::streamsize) [with _CharT = char, _Traits = std::char_traits<char>, std::streamsize = long int]
This is the part the is not working:
Code:
// uia is : unsigned int * uia;
// then I have allocated the space for it
// load it with unsigned int's
// k is the number of variables in my array
o.write(uia,sizeof(unsigned int)*k); But thsi should be so simple and strait forward.... in c i do it as :
Code:
fwrite(uia, sizeof(unsigned int), k , fp); but since i would need to convert fstream to FILE* i decided to do it c++ way.
and this is how i opened the file :
Code:
o.open (fileName.c_str(),std::ios::out|std::ios::binary);
View 5 Replies
View Related
Apr 8, 2013
I was going through the exercises in one C programming ebook.There is this question which asks me to print a float variable in fixed decimal notation, field size of 6, right-justified, no digits after decimal point.I got printf("%6f", x );
x = float variable.
But the above code prints numbers after the decimal point, so I changed it to %d. But %d doesn't work with float variables..
View 2 Replies
View Related
Feb 3, 2015
I have the main() - which has entries like
Code:
main() {
int ss, ret, z;
float yy;
ret = function1(&yy, &ss, &z);
//int function1(flat *cc, int *dd, int *k) - is it correct?
[Code]...
View 5 Replies
View Related
Nov 20, 2013
I can do the folowing:
float var1 ;
var1 = 9.12345 ;
printf("%.2f",var1) ;
the output will be 9.12. What if I wanted to save that as another separate float with displaying it on screen?
View 1 Replies
View Related
Jun 8, 2014
#include <iostream>
#include <string.h>
#include <sstream>
[Code]....
View 1 Replies
View Related
Mar 12, 2014
I am working on image processing in C + + and opencv, I treat images in grayscale, ie the pixel values it must be between 0 (black) to 255 (white).
Mat img; img = imread (file, -1);
for ( int i = 0; i < img. rows ; i ++) {
for ( int j = 0; j < img. cols ; j ++) {
val_pixel=img.at < double >(i,j);
printf( "%d ",val_pixel);
}
printf( "
");
}
when displaying the pixel value from two loop, I get values to 0 and it is normal for propablement black areas, but for whites I find the value -2147483648. I don't understand why this value is not 255.Is there an explanation for this has value.
View 4 Replies
View Related
Nov 5, 2013
I use SDL2. and i was testing some functions i took from some internet and some unwanted results happened.
Code :
Pixel *GetPixel(SDL_Surface *surface, int x, int y) {
Uint8 p8, *buf8;
Uint16 p16, *buf16;
Uint32 p32, *buf32;
switch(surface->format->BitsPerPixel {
[Code] .....
And the output changes time to time.
View 3 Replies
View Related
Apr 17, 2012
I have an image of size 640x480 pixels. It's possible to obtain the dimension in mm of one pixel from that image given only that size?I do not have the size of the image in mm,however.
View 5 Replies
View Related
Jul 26, 2014
How can I find each and every pixel in a circle so that I can do some operations on it.
View 6 Replies
View Related
Mar 27, 2013
How can I import a font file and get the pixel information of the letters so I can make my own custom text drawing function?
I basically have a pixel surface (a 2D array) and I want to draw the text to that array.
View 1 Replies
View Related
Apr 21, 2014
I wrote a script that generates n random pixel positions and draws them to the screen. Works well. Now i tried to rotate them. Rotating does work too. But it does not work as i planned it.
paramters 'angle' and 'timestep' work somehow, but not as they should do. the function 'move' is supposed to rotate the pixelfield 'angle' degrees in a given direction, addicted to the 'timestep' parameter. 'timestep' is needed time for drawing in one single game loop.
angle_step = timestep * angle
// x
ppdPoint[i]->x =
pRotationPoint->x + cos(angel_step) * (ppdPoint[i]->x - pRotationPoint->x) - sin(angel_step) * (ppdPoint[i]->y - pRotationPoint->y);
// y
ppdPoint[i]->y =
pRotationPoint->y + sin(angel_step) * (ppdPoint[i]->x - pRotationPoint->x) + cos(angel_step) * (ppdPoint[i]->y - pRotationPoint->y);
rotation point is the middle of the screen. when i set angle to 10 it should rotate 10 degrees / second. Instead it's rotating very very fast and all stars are moving nearer to the center of the screen, so after x rounds there is just 1 pixel left in the middle of the screen. there is a kind of gravition.I'm working with SDL2. What I did find out:
FPS is <= 60, 'cause of the 'SDL_RENDERER_PRESENTVSYNC' flag. When i skip that flag, for any reason the 'gravition' would take more time. FPS is <= 1400 then, 'though i got a natural game loop (i hope):
while(pBuild->getExecuteFlag())
{
pBuild->draw();
pBuild->update(time_dif, pTimeWindow->TimeStampB);
time_dif = (pTimeWindow->TimeStampB - pTimeWindow->TimeStampA);
time_dif *= 0.001;
pTimeWindow->TimeStampA = pTimeWindow->TimeStampB;
pTimeWindow->TimeStampB = SDL_GetTicks();
pBuild->count_fps(pTimeWindow->TimeStampB);
}
So maybe (timestep * angle) isn't the right way?
View 13 Replies
View Related
Mar 27, 2014
Im new to c#. In c++ I have made a window and painted it with dots and concentric circles, like a radar PPI screen. Trying to do this in c#, I can't find how to draw a single pixel on the window.
Also, what should I be drawing on: the form, panel, picturebox...?
View 2 Replies
View Related
May 23, 2013
How can i convert pixel to [-1..1]coordinate in opengl? Which function? I want to write a program that is work with
glutmousefunc(),
When I click on the screen a ball is appear on it where clicked. but mouse work with pixel and circle work with coordinate between -1 and 1 ....
View 4 Replies
View Related
Oct 15, 2013
I have the code and it compiles fine but it doesn't work. (i am using the coding made easy sfml 2.0 tutorials)
Code:
#include <SFML/Graphics.hpp>
#include <iostream>
#include <algorithm>
#include <vector>
class Player {
public:
sf::Sprite player;
[Code] ....
View 18 Replies
View Related
Mar 7, 2013
I am using the SDL library, and came across a way to access pixel data.
//A pointer to a surface structure
SDL_Surface *w = SDL_SetVideoMode(800,400,8,SDL_SWSURFACE);
//Casting a void pointer pointing to an array of memory locations(the pixels), to a pointer to an array of Uint8's.
//SDL_MapRGB() Returns an Uint32 containing the color 0,0,255,(0/255, i think it returns the transparency too, or else it would rather return a Uint24,not sure).
Then modifying the memory location, in this case the pixel at the middle of the window.
static_cast<Uint8*>(w->pixels)[(200*w->pitch)+400]=SDL_MapRGB(w->format,0,0,255);
What i seem to not understand is that, i cast pixels to Uint8*, which means I now have a pointer to an array of 8bit numbers, but SDL_MapRGB seemingly returns an Uint32 or Uint24 for a color composed of r,g,b, together without 'a' is 24bits(256=1b,256=1b,256=1b)=3b.
And then i somehow assign that pixel which is of 8bit at chosen location, an Uint24 or 32bit unsigned int.
How does this work?
View 3 Replies
View Related
Jul 21, 2013
I'm currently working with linear VRAM (a buffer with 256KB memory, divided into four 64k planes, so plane 0 at 0x00000, plane 1 at 0x10000, plane 2 at 0x20000, plane 3 at 0x30000). Just add the index of the plane to that for the full address in VRAM.
I'm still wondering how to get a specific pixel from VRAM (x,y coordinate) when doing graphic modes (none color modes work, only the black/white pixels (1-bit) graphic mode works).
how I can get specific pixels from the VGA VRAM (having linear access described above) using Shift Register Interleave mode (VGA modes 4&5), 16-bit planar mode (Most VGA modes) etc.
View 4 Replies
View Related
Jan 27, 2015
I have a bw(grayscale) image and want to calculate the slope for each pixel which returns a value 0 to 255 value.
Pixels are always between 0 and 255. The highest possible difference is 255. The end result would be 0 for no slope and 256 for the highest slope.
Would this formula work?
slopex = pixel[x+1,y] - pixel[x - 1,y];
slopey = pixel[x,y+1] - pixel[x,y - 1];
totalslope = sqrt(slopex * slopex + slopey * slopey)*256;
View 3 Replies
View Related
Jan 18, 2015
I have managed to successfully extracted the BMP file header and file info but ran into troubles with getting the pixel data out into a 2d array.This is my function to read the data while i have another to write the data. The output does not match the input at all.
void BMPProgram::GetPixelData(std::ifstream & inStream) {
std::cout << "Entered function";
if(inStream.fail())
return;
//space allocated to reading in of padding
int paddingSpace = 0;
[Code] ....
PIXEL is a struct of 3 unsigned char containing values of RGB.
View 3 Replies
View Related
Feb 28, 2014
I'm trying to read a jpeg pixel and then compare it if it'x bigger than a number to change it. Either I'm breaking the folder if I start less than 22000 which is very large number shouldn't include the header or I'm getting solid color without any different.
Code:
const char* filename ="Hydrangeas.JPG";
const char* nfilename ="Hydrangeas1.JPG";
FILE *ptr_old, *ptr_new;
errno_t err = 0, err1 = 0;
int a;
[Code] ....
View 5 Replies
View Related
Nov 25, 2014
In this project I need to develop few functions to work with graphics card. I work in minix and this is pretty rubbish.
I'm having an hard time to read a pixel map, or atleast to print it on my main function.
I have a read_xpm function, which is given, therefore, working.
Code:
char *read_xpm(char *map[], int *wd, int *ht)
Then I have a pixmap.h file which gives some examples of pixmap images that I can use as example:
Code:
static char *pic1[] = {
"32 13 4",
". 0",
"x 2",
"o 14",
"+ 4",
[Code] ....
The doubt is. I have a test_xpm function and I need to call this char array but this is so many pointers that I can't even figure out where I'm pointed to (?)
Code: int test_xpm(unsigned short xi, unsigned short yi, char *xpm[])
I tried something like read_xpm(xi, yi, *xpm[0]); but I'm guessing I need to index that array and run all those chars in order to show them.
View 11 Replies
View Related
Nov 2, 2014
creating a bitmap. Our professor wants us to creat a black 100*100 bitmap.
Code:
#include <stdio.h>
#include <stdlib.h>
#pragma pack(push,2)
typedef struct{
[Code].....
I dont even know where to start. I spend the last 7h infront of my computer and i'm so frustrated cause my professor gave us no information what so ever. At the moment its more of a trial and error process than anything else.
How would i set the color of an individual pixel for examplel or how would i save the file ?
View 1 Replies
View Related
Jan 6, 2015
I need to save RGB values of each pixel in a 3D array A[width][height][3]. I found a code online that transfers the bytes into an array but I cant understand how bytes are saved them so i could transfer them into an array. The truth is I dont know much about working with images at all so i have a problem working on them. How to transfer the RGB data from an .jpeg image into a 3D array? This is my code so far:
#include <iostream>
#include <jerror.h>
#include <jpeglib.h>
using namespace std;
int main(){
FILE *pic = fopen( "image.jpeg", "rb+" );
[Code] .....
View 6 Replies
View Related