C++ :: Subtracting Pixel Values From Two Different BMP Files
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
ADVERTISEMENT
Jun 9, 2013
I want to add this piece of code to a project. I have created a vector from values entered by a user. I want to then subtract each value from each other from the beginning to the end. For example if a user enters 10,4,3 the program will subtract the values in that order 10 - 4 - 3 and output 3 as the solution. I figured how to do it with addition but can't get it to output for subtraction.
#include <iostream>
#include <vector>
using namespace std;
[Code].....
View 5 Replies
View Related
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
View Related
Mar 31, 2015
I have some ascii characters in a char variable.ex - char buf[100]="ab*(z&";
So each of the char in that char array will have some hex value.ex- *'s hex value is '2a'.
And I have a long long int variable in which there is a 64 bit hex value.
ex- long long int k=0x0000888888888888;
Now i want to subtract the char buff's hex value in k. How to accomplish it.
That is 0x0000888888888888
- 0x000061622a287a26
= 0x000027265e600e62 (final result in a buffer or a long variable is okay)
Later i want to reverse the result as 26e006e56272.It should be stored in a variable such that i should be able to access each byte from it(ex- '72'(last 2 hex digits))
View 1 Replies
View Related
Oct 18, 2013
I have a 2d array where I manage donations and requests for different foods. I output a menu to the user who picks the options to either make a donation, make a request, fulfill a request, or print a status report of all the donations and requests. What I'm having trouble with is the fulfilling requests option. When the user picks fulfill requests that means that the donations are supposed to be subtracted from the requests. For example if there are 10 donations for grains and 15 requests for grains then after picking fulfill request there should be 0 donations for grains and 5 requests for grains but I don't know how to make the program do that since the values are in a 5 row by 2 column array. The five rows correspond to the five foods and the two columns correspond to donations and requests, respectively. Here's my code so far. Just disregard everything but the third case.
Code:
#include <stdio.h>int main(){
int foodbank[5][2]= {
{0,0},
{0,0},
[Code]....
View 6 Replies
View Related
Feb 11, 2013
I have 2 integers, both in 2 seperate classes in 2 seperate files. I have main.cpp, test_01.h, Test_01.cpp, Player.h and Player.cpp. I ahve a function which takes an integer (a) as a parameter (from Test_01.h and Test_01.cpp). a sets another integer (attackPower) from the same class equal to a. The integer (health) in the other class (Player.h and Player.cpp), is then equal to health -= attackPower. But instead of giving me the right answer 75 (health = 100 and a is set to 25 when i call the function) it gives me the answer.
main.cpp
#include <iostream>
#include "Test_01.h"
#include "Player.h"
using namespace std;
int main() {
Player p;
Test_01 t;
[Code] ....
View 2 Replies
View Related
Dec 22, 2014
I cant seem to read stuff in from my students.txt file which contains this
19992195 John Smith 20 05 1995 09 09 2011 15 05 2014 55 65 72 58 80 45 40 45 66 78 88 81
20051195 Mark Dobson 20 05 1995 09 09 2011 15 05 2014 55 65 72 58 80 45 40 45 66 78 88 81
20063196 Paula O'Reilly 20 05 1995 09 09 2011 15 05 2014 55 65 72 58 80 45 40 45 66 78 88 81
20053344 Aoife Cleary 20 05 1995 09 09 2011 15 05 2014 55 65 72 58 80 45 40 45 66 78 88 81
It has something to do with the lines at the bottom of the code. It doesnt cout anything. The program just crashes upon execution. First, it asks me the amount of students i want to handle. I enter '1'. Then it asks me if i want to read in from external file and i enter 'Y'. then the exe just crashes
#include <iostream>
#include <cstddef>
#include <cstdlib>
[Code]......
View 3 Replies
View Related
Mar 31, 2015
[URL] .... This is what I have so far, and it isn't incorrect, but how to improve this or make it more accurate?
// subtracting the area of two circles from a rectangle
#include <iostream>
using namespace std;
int main() {
cout << "This program is designed to calculate the area of a rectangle, to exclude the area of 2 circles that have been placed inside of the rectangle." << endl << endl;
[Code] .....
View 12 Replies
View Related
Apr 23, 2013
I am currently working on a program that uses a class to store integer arrays. I have most of the code done, but I am having trouble on the main.cpp part of my program. The program should display this:
OBJ 1:
2 3 4
OBJ 2:
1 4 -2
Addition:
OBJ 1 =
3 7 6
Subtraction:
OBJ 1 = 1 -1 6
But when I run and compile my program, this is what I get:
OBJ 1:
2 3 4
OBJ 2:
ADDING:
OBJ 1 =
4 6 8
Subtraction:
OBJ 1 =
Here is my current main.cpp:
Code:
#include <iostream>
#include "SafeArray.h"
using namespace std;
[Code].....
View 3 Replies
View Related
Dec 11, 2014
I have written in a binary file using fstream an using sort value.
unsigned shortwidth=50,height=50;
file.write((char*)&width,sizeof(width));
file.write((char*)&height,sizeof(height));
When i try to read it back from fstream again there are some symbols (binary obviously). How can i get my values back? I want to read those symbols and in a way to convert them to my old width and height values.
View 6 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