C++ :: Program To Read Image (Later Represent By Array 3D)
May 1, 2013
I will make a program to read the image in C++. And later, the image will represent by array 3D, which (x,y) represent the spatial coordinate of (height*weight) image (pixel) and z represent the intesity of those image (0-255).
In matlab, the code for do that is --> imread('image.jpg')
How can I do that in C++?
View 2 Replies
ADVERTISEMENT
Oct 29, 2013
I am trying to read a 24 bit image but I'm getting errors when I'm tryting to read the pixels.
-The reading part looks bad because I'm reading both headers field by field. But I'm sure that it is reading both headers correctly.
-Right now my biggest concern is to get it to read successfully an entire bmp image
I'm using this calculation to get my padding bytes:
padding bytes = [4-(3*width)mod 4]mod 4
When I use a 2x2.bmp file to test it, I get an error that the [1][1] pixel was not read. When I use a bigger image it gives me the same error after about 100 rows and then every pixel is an error from that point on. This is what I got so far:
Code:
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
const size_t cSizeofPixel = 3; //size of struct tPixel
typedef struct{
unsigned char blue;
unsigned char green;
unsigned char red;
[Code]...
I read this post Reading 24 bit BMP file into a 2d array.
I still don't know if my error is when I allocate memory to my 2d array, or if I'm doing the padding bytes wrong or if it is something else.
View 8 Replies
View Related
Apr 8, 2014
I am trying to read the information from a .bmp file into my program while dynamically allocating memory for all of it. So I defined the structures for the headers and for a pixel, and then I have to read each pixel into a multi-dimensional array of pixels. I am completely new to structures, and definitely new to pointers combined with structures. I will have to use a filter with the information later, but right now I just want to read everything in correctly. The array of pixels will be two-dimensional -- the width by the height of the image, I guess.
Here's my code:
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
int main(int argc, char *argv[]) {
FILE *inFile, *outFile;
typedef struct
[Code] ....
View 4 Replies
View Related
Dec 5, 2014
I am trying to make an interpreter. This stack function is supposed to represent the scope of the program, meaning scope of the variables. The START represents a new scope, and FINISH represents the current scope closing. I am trying to do a recursive function in which the stack is updated with each recursive call, which represent a new scope for each call.After i enter a new scope and the scope ends, my program prematurely terminates.
void stack(ifstream& file,Hash& Table) {
string line;
getline(file,line);
int i=0;
[code].....
View 2 Replies
View Related
Apr 10, 2013
I am having trouble of exactly how "class" works. I dont know what the difference between set and get is. I have this code:
#include <iostream>
#include <cmath>
using namespace std;
class Point {
private:
double px;
double py;
[Code] .....
How to get void Triangle::setBottomLeftX(const double x) to work.
Implement the get and set member functions for the class Triangle. Use the appropriate class attributes of the class Triangle.
a. The location of the bottom left vertex is stored in the member attribute blPoint.
b. The top left vertex can be computed from blPoint and the height.
c. The bottom right vertex can be computed from blPoint and the length.
View 19 Replies
View Related
Nov 20, 2014
I have an *.lct file. I like to read *.lct file and save an bmp image.
I can not read this file using usual file read.
Code:
void CLCTtoBMPDlg::OnBnClickedReadlctfile() {
CFileException CFileEx;
CStdioFile ReadFile;
CString OpenlctfilePath;
TCHAR szFilters[]= _T("LCT Files (*.lct)");
CFileDialog fileDlg(TRUE, _T("bmp"), _T("*.lct"), OFN_FILEMUSTEXIST | OFN_HIDEREADONLY, szFilters);
[Code]...
Find the attachment. change the file extension *.lct instead of *.txt. I like to read ASCII Data into Hex, Example : Data "A" as "41" (Refer the jpeg image). How is possible?
View 4 Replies
View Related
Jan 25, 2015
How to insert and read images to/from database (sql server) using MFC ?
View 5 Replies
View Related
Apr 24, 2013
The program is supposed to design a class that can be used that can represent a parabola.
Code:
#include <iostream>
#include <iomanip>
#include <cmath>
#include <fstream>
#include <cstdlib>
#include <cstring>
using namespace std;
class Parabola {
public:
Parabola( double, double, double );
[Code] .....
View 3 Replies
View Related
Sep 25, 2013
im working on Book Ordering system and i having trouble how to make the system recognize different price values when i add different books into it, also how to make the system to be able to add/remove cart?
View 12 Replies
View Related
Apr 19, 2013
Here is the code I have written so far. My problem is that when the second user enters its position the last user's position is wiped of the board. I want to know how I can hold that position and keep doing so until the game is finished. I thought that calling the previous function would do that (and you can see where I have put that into a comment) but it doesn't.
Code:
#include <iostream> //includes header file
using namespace std;
//function prototypes
void printLeftUpper(int i, int j);
void printMiddleUpper(int i, int j);
[Code] ....
View 1 Replies
View Related
Aug 24, 2014
My program has a large version of this, where every leaf class is singleton, and pointers of the base class to represent each possible path are stored in a map during compile time. I have it working as follows:
#include <iostream>
#include <string>
#include <map>
[Code].....
But System::initializePrototypes() is constructing the map manually, and I want to use recursion somehow, because my hierarchy is much bigger than this. It's also easy to miss a path doing it the above way, and when new classes are added to the hierarchy, it will be a nightmare to update the map. So the ideal solution is recursion constructing the map perfectly--and when new classes are introduced, nothing needs to be added to System::initializePrototypes().
View 7 Replies
View Related
Jun 2, 2014
I've attached an image that shows a basic table with dynamic content in the header.
Initially, I thought about using a datagrid. However, I can't use a datagrid because of the format of my data visually. The DataGrid would not allow me to have static and dynamic data inside my column headers.
You see anything I am displaying in brackets, {}, are being updated with results after I process some data in the backend. After the data analysis is done, the results are displayed based on an algorithm.
So, let's say for control1, for each family, it would indicate whether the data passed or failed. Then, in the rows themselves, it would update with choice 1 or choice 2 depending on the data generated.
So, the data that is in brackets shows properties being updated. I'm not sure what UserControl I can use to accommodate this kind of display.
View 13 Replies
View Related
Jan 28, 2013
I want to create a program using c++ which will accept text from the user and then adds it onto a image of a form in specific locations (if that makes sense?)
and what libraries will be required?
View 1 Replies
View Related
Apr 2, 2013
I am trying to write a program that creates a hybrid image I've hit a roadblock early on my code throws up an unhandled exception I cant find where it goes wrong I need a fresh perspective on this. Here is my code so far
#include <iostream>
#include <cv.h>
#include <highgui.h>
#include <stdio.h>
using namespace cv;
Point P11, P12;
Point P21, P22;
[Code] .....
View 5 Replies
View Related
Feb 19, 2013
I am currently working on problem set 4 for Harvard's online CS50 course. I am working on a program that resizes a bmp image by a factor of N. N in entered along with an in-file and out-file in a command line argument. The program needs to calculate the header file for the out-file and write it to the out-file. It then needs to actually resize the image and, again, write to the out-file.
The first question I have relates to the header file, here is my code for calculating the header file:
bi2.biHeight = bi.biHeight *n;
bi2.biWidth = bi.biWidth *n;
int padding = (4 -(bi.biWidth * sizeof(RGBTRIPLE))%4)%4;
bi2.biSizeImage = (bi2.biWidth * sizeof(RGBTRIPLE) + padding) * abs(bi2.biHeight);
bf2.bfSize = sizeof(BITMAPFILEHEADER) + sizeof(BITMAPINFOHEADER) + bi2.biSizeImage;
And here is my code for writing the new header file (bi2 and bf2) to the out-file:
fwrite(&bf2, sizeof(BITMAPFILEHEADER), 1, outptr);
fwrite(&bi2, sizeof(BITMAPINFOHEADER), 1, outptr);
At this point I need to actually resize the image. As far as I can tell there are 2 ways to go about this you either have to use an array to store each line you want to print repeatedly (and then you can just write it repeatedly) OR you have to move the pointer back in the input stream and repeat the read/resize/write process each time you need to print the row.
It is this that I am stuck on, first of all, I am not sure what system would be better for resizing the image, although I am leaning towards using an array, and regardless, I don't even know where to begin when in implementing either.
So what I am asking for is, first of all, just a "double check" to make sure my header code makes sense. And second of all, a push in the right direction for actually resizing the image. Here is my complete code:
/****************************************************************************
* resize.c
*
* Resizes a BMP piece by piece, just because.
***************************************************************************/
#include
#include
#include "bmp.h"
int main(int argc, char* argv[]) {
// ensure proper usage
if (argc != 4) {
printf("Usage: copy N infile outfile
[Code]....
View 7 Replies
View Related
Jun 17, 2014
The following code is an example of how task are created with micro cos III in c. I am trying to figure how to create similliar code in C++. My problem is how do I instantiate objects and how to use member functions to represent task. Within the create task routine the address of function is passed as argument. How do I do this in C++? Will I need more than one class? New to embedded C++.
/*!
* @brief LED Flasher Task
*/
void
led5_task (void * p_arg)
{
OS_ERR err;
(void)p_arg; // NOTE: Silence compiler warning about unused param.
[Code]...
View 2 Replies
View Related
Mar 15, 2013
I need to represent each inputted amount of rainfall into a graph like this.. how would I do this with loops?
View 5 Replies
View Related
Jan 15, 2015
Given a product category and subcategory representation:
a. Come up with a tree data structure to minimally (in terms of storage) represent this
b. Write a program to convert the given representation (shown in example below) to this
c. Write a function to output the tree structure in a nice human readable format
Note:
a. There can be any number of levels of depth
b. Rows may be repeated in input, but need to feature only once in the final tree.
Example category list (read this input from a file):
everything else|office supplies
electronics|video games
electronics|video games|accessories
electronics|video games|accessories|headsets
electronics|video games|accessories|flight controls
electronics|video games|accessories|joysticks
View 5 Replies
View Related
Apr 4, 2013
I have an assignment where I need to take an assigned image, rotate it 90 degrees to the right, flip it upside down, and turn it to grayscale; each with different outputs.
I was thinking if I can read in the image into a 2d array //array[height][width] or even just an array with the values of each pixel (r, g, b), I can just modify the array and spit it out when done.
if i can just get it into the array, I think I'll be fine. We've done similar assignments with modifying arrays for grayscale images and the other two I can probably figure out. But how am I going to read in each pixel into an array with three different values in each slot? This is my code so far:
Code:
#include<stdio.h>
View 1 Replies
View Related
Sep 16, 2014
My assignment is use a 3D array to create an image. Use an array of the form arr[300][200][3]. For this homework, you need to use an array of the form arr[3][400][500]. It will have 400 rows and 500 columns. You need to first initialize the array as described in class and after that write the array to a ppm image file. When viewed using Gimp, it should display USM. The letters would be 200 pixels high and 100 pixels wide each. Use at least 15 pixels for the width of the stroke. Use different colors for each letter and a different color for the background.This is what I have so far.
#include <iostream>
#include <fstream>
#include <string>
using namespace std;
void initialize(unsigned char a[][200][3], int nrows, int ncols, int nc);
void printAll(unsigned char a[][200][3], int nrows, int ncols, int nc);
[code]....
View 3 Replies
View Related
Jul 3, 2014
Im trying to compare the image of a button to another image in Visual Studio like so...
//variables
Image active = Image.FromFile("C:\Users\Ethan\Desktop\StarWars Status\active.png");
Image stunned = Image.FromFile("C:\Users\Ethan\Desktop\StarWars Status\stunned.png");
[Code]...
btnStatusPlr1.Image SHOULD come back as True.Then I realized it might not be the same as setting the buttons image in the properties (Which is what i did to get the original image (the one being compared to))
I do have a feeling ive done something wrong here (Yes im a noob /> )
Variable active, is the same image as the buttons default (Well should be)
View 1 Replies
View Related
Jul 29, 2014
I am writing a program to display values from a data file as an image. But I can only get a blue screen. Here is a small program resembling my code. what I have missed? I only changed OnDraw function.
Code:
void CColorDisplayView::OnDraw(CDC* pDC) {
CColorDisplayDoc* pDoc = GetDocument();
ASSERT_VALID(pDoc);
if (!pDoc)
return;
CRect rect;
[code].....
View 10 Replies
View Related
Nov 29, 2014
I'm trying to read a PPM image into an array. The header will have already been read in and I'm trying to put in a 2-d array to make manipulations easier. This is the code I have so far with LOTS of errors and warnings and I honestly don't know what almost any of them mean.
Code:
int imageArray( FILE *input, struct pixel *theArray ){
int i, j;
int col, row;
int *imageArray = (int**)malloc(row * sizeof(int*));
for(i=0; i<row; i++){
[Code]...
View 3 Replies
View Related
Jun 8, 2013
I have a problem concerning transforming int array into bmp image. I wanted to add a post in this topic: [URL] .... , but unfortunately it is closed. Actually I have a question concerning the code written by Duoas. I have a function which takes values from the file and I want to convert it into bmp with the use of Duoas code. I do it like that(it's Duoas code + my load and main function) Is it something wrong with how I do it or it's rather sth wrong with the file.
It compiles without errors but when I run it: core dumped.
According to gdb debugger problem is here: double hue = (intarray[ row - 1 ][ col ] - min_value) * granularity; programs stops, segmentation fault ...
#ifndef INTARRAY2BMP_HPP
#define INTARRAY2BMP_HPP
#include <fstream>
#include <iostream>
#include <string>
[Code] ....
View 2 Replies
View Related
Feb 17, 2015
A few months ago I wrote a simple neural network using back propagation algorithm. It's input is a 2D array of any given size and type. I tried to make it learn the logic functions like AND & OR it worked. So now I want to try image recognition and I need the image as a 2D array of RGB values.(I mean three arrays of course one 2D array for each color.)
How can I get an array of RGB from an image? Can I do it with streams?
View 1 Replies
View Related
Sep 10, 2013
I am trying to retrieve an image from its URL as an array where each box represents the pixel value of the image.
View 3 Replies
View Related