C++ SFML Photo presentation - c++

I've installed SFML on my VS2015. I know how to display sprite. Problem occured when I wanted to display another images in the same program.
My goal is to write program which samples without replacement numbers from specified range, shows result on the screen (with few seconds' breaks beetween each) then saves result in txt file. I've done this stage. I only want to display images during sampling. Another specified image for every chosen number.
I don't need code to copy-paste. I just want to get any advice. Which methods available in SFML could help me?

You should declare a sprite
( sf::Sprite sprite )
and a texture ( sf::Texture texture ). The, simply load the texture from a file( one of your images ) ( texture.loadFromFile( "img.png") and set the sprite's texture(sprite.setTexture( texture )). Now, if you draw the sprite on the screen you should see your full image. I'm 100% sure it works on Windows 10 ,but i don't know if it works on Mac OS or Linux.

Related

C++ Image Manipulation

So I have made this program for a game and need help with making it a bit more automatic.
The program takes in an image and then displays it. I'm doing this over textures in OpenGL. When I take the screenshot of the game it is usually something about 700x400. I input the height and width into my program, resize the image to 1024x1024 (making it a POT texture for better compatibility) by adding blank space (the original image stays at the top left corner and goes all the way to (700,400) and the rest is just blank; does anyone know the term for this?) and then load it into my program and adjust the corners so only the part from (0,0) to (700,400) is shown.
That's how I handle the display of the image. Now, I would like to make this automatic. So I'd take a 700x400 picture, pass it to the program which would get the image's width and height (700x400), resize it to 1024x1024 by adding blank space and then load it.
So does anyone know a C++ library capable of doing this? I would still be taking the screenshot manually though.
I am using the Simple OpenGL Image Library (SOIL) for loading the picture (.bmp) and converting it into a texture.
Thanks!
You don't really have to resize by adding blank space to display image properly. In fact, it's really unefficient way to do it, especially because you store images in .bmp format.
SOIL is able to automatically add the blank space when loading textures - maybe just try to load the file as-is, without doing any operations.
From SOIL Documentation:
Can automatically rescale the image to the next largest power-of-two
size
Can load rectangluar textures for GUI elements or splash screens
(requires GL_ARB/EXT/NV_texture_rectangle)
Anyway, you don't have to use texture to display pixels on the screen. I presume you aren't using shaders for rendering - if it all goes through fixed pipeline, there's glDrawPixels function, which will be much simpler. Just remember to change your SOIL call to SOIL_load_image.

Strange scaling behavior

I have my own class that holds a sprite.
The sprite is an animation made with Zwoptex. I got both retina and standard images alright.
I put my class in middle of the scene. And, for some reason, the sprite displays with a really small size.
I thought it might be because of scaling (although I never scale the sprite). So I decided to put two NSLogs:
NSLog(#"%f",enemy2.scale);
NSLog(#"%f",enemy2.sprite.scale);
One tells me the scale of my custom class itself and the other the scale of the sprite itself.
However, when I put those two lines of code, the sprite appears with the expected size (bigger).
And the NSLog result is 1.0.
Why? Any ideas?
Unless the scale getter method has been implemented and changes the scale_ instance variable this should not happen.
Initially I would say that the sprites being small size seems to indicate that you are loading the SD images on a Retina device, instead of the HD images. Be sure to name your SD and HD assets like this if you're using a texture atlas:
// SD images
textureatlas.png
textureatlas.plist
--> player.png
--> enemy.png
// HD images
textureatlas-hd.png
textureatlas-hd.plist
--> player.png // no -HD suffix!
--> enemy.png // no -HD suffix!
It is a common mistake to also suffix the sprite frames inside the texture atlas. So if your sprite frames in the HD texture atlas are named player-hd.png and enemy-hd.png then Cocos2D will not find them and reverts to loading the SD images.
It should be noted that TexturePacker will detect and can automatically correct this for you. Last time I used Zwoptex, it would allow you to create such incorrect texture atlases.

QT and OpenGL how to integrate properly and display a texture

I have a few questions about using them both. At the moment I have a preexisting renderer I'm trying to use with QT and OpenGL.
A few questions are:
How can I get my results to draw in a QGraphicsScene? Is that even the right output to attempt to be using.
With OpenGL I want to be able to load textures and then be displayed in a window? Do I need to coordinate where to draw the texture or can I just say in the centre of a QWidget?
What paramenter would I usually need, I persume I need a Gluint for the texture, and then parameters for the size?
At the moment my results are quite poor, it seems to render something but basically not either in the correct window or not in the window of choice and basically it seems to 'hide' text e.g. hello, I can only see e. Odd I think.
I'm pretty sure this link will help you code with Qt and OpenGL:
http://wesley.vidiqatch.org/03-08-2009/nehe-opengl-lessons-in-qt-chapter-1-and-2
I used this and the NeHe tutorial to code a small Qt/OpenGL application, so all information you need is contained in both tutorials.

How to correct RGB color taken with camera?

I had this question in my mind lately: I have taken a photo of a picture in my computer's display using my phone's camera (2MP) then transferred the picture to my computer. What i have noticed is that the individual pixel (RGB) values of the photographed image are different from the original picture (which is obvious !) but the color looks the same; so what i intend to do is modify the photographed image so that the pixel color values (RGB) are the same as the original (100% if possible), in other words make every pixel identical to the original picture ! without making use of the original picture.
I do not know if this is possible or not but any help will be extremely appreciated, I'm using Visual c++ 2005 with CIMG Library for processing images !
Thanks in advance !
I'm more interested in WHY you photograph your own screen? If you are running windows you can just press the "Print Screen" key on your keyboard and then open, for example Paint and paste the image.
The colour difference is there because you have not white balanced your camera. Even the most mobile phone cameras can white balance. Take a picture filled entirely with white on your screen. Then tell the camera to use it as a reference for white. Take your photo and it should be correct.

Combining Direct3D, Axis to make multiple IP camera GUI

Right now, what I'm trying to do is to make a new GUI, essentially a software using directX (more exact, direct3D), that display streaming images from Axis IP cameras.
For the time being I figured that the flow for the entire program would be like this:
1. Get the Axis program to get streaming images
2. Pass the images to the Direct3D program.
3. Display the program, on the screen.
Currently I have made a somewhat basic Direct3D app that loads and display video frames from avi videos(for testing). I dunno how to load images directly from videos using DirectX, so I used OpenCV to save frames from the video and have DX upload them up. Very slow.
Right now I have some unclear things:
1. How to Get an Axis program that works in C++ (gonna look up examples later, prolly no big deal)
2. How to upload images directly from the Axis IP camera program.
So guys, do you have any recommendations or suggestions on how to make my program work more efficiently? Anything just let me know.
Well you may find it faster to use directshow and add a custom renderer at the far end that, directly, copies the decompressed video data directly to a Direct3D texture.
Its well worth double buffering that texture. ie have texture 0 displaying and texture 1 being uploaded too and then swap the 2 over when a new frame is available (ie display texture 1 while uploading to texture 0).
This way you can de-couple the video frame rate from the rendering frame rate which makes dropped frames a little easier to handle.
I use in-place update of Direct3D textures (using IDirect3DTexture9::LockRect) and it works very fast. What part of your program works slow?
For capture images from Axis cams you may use iPSi c++ library: http://sourceforge.net/projects/ipsi/
It can be used for capturing images and control camera zoom and rotation (if available).