Embedding a python interpreter to c++ [closed] - c++

It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center.
Closed 10 years ago.
You'll have to forgive me if this question has been answered, but I haven't been able to find anything that specifically talks about what I need.
I am attempting to embed a python interpreter into a GUI written in C++. To describe it a bit more fully, I have a series of images that will be displayed in a window. These images will be streamed from a server, along with various information about the images and how they compare to each other. The GUI will also have a large text area at the bottom with a prompt (like the '>>>' prompt in the python CLI) that the user can type valid python code into, then the app executes that code based on the information it has on the image currently being displayed.
For example, if the image is stored in a struct that contains height and width information (image->height and image->width), and I have written in Python a class that interfaces with the data currently displayed (everything would do what it looks like it should do), I need to be able to execute the following and get the output:
>>> from image import image #custom module and class for interfacing with my GUI
>>> img = image.get_current_image() #returns a Python object relating to the image currently displayed
>>> img.width
800
>>>img.height
600
>>> img.aspect_ratio()
4:3
I am aware of a few methods of accessing c++ classes from python code, such as Boost Python. What I am not sure how to do is a create the interpreter inside a C++ GUI. The issue is the python and C++ must communicate with each other in realtime, and must share memory. For example, the python module may contain a to_grayscale() function that converts the image to grayscale, which would require that the python module retireve the image from C++, convert it, and send it back to be rerendered.
Just to make it clear, I don't need help doing that conversion or anything like that. Just how do I integrate the interpreter with C++?
Thanks!

Related

C++ "everlasting" variable [closed]

It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center.
Closed 9 years ago.
I need a variable which will contain the best player's score in C++ . So I need something which will not be erased after the program ends and every time when someone gets a higher score that variable must be replaced with a new one . I know that I can save that number in .txt file , but I would like to know if there is an alternative way ?
You could using something like OpenKeyval.
Setting the highscore would be a POST request:
$ curl http://api.openkeyval.org/highscore -d "data=1000"
Getting the highscore is a GET request:
$ curl http://api.openkeyval.org/highscore
1000
One alternative is to store it in a SQLite database. That way you've got the flexibility of a database without needing to run or connect to a server.
You have three main options that I can think of:
1.) Store it in a file
2.) Store it in the registry (http://forum.codecall.net/topic/63205-registry-operations-using-win32-part-1/)
3.) Store it on a server online that you can read or write to
The most generic and "portable" way is to store it in a text file. Of course, that is also open to abuse, someone can open the file in notepad and change the score from 1234 to 999999, or similar.
Storing in a binary file will work, but is sensitive to machine architecture and size of the variable.
Windows has a "registry", which can be used to store strings or binary data, similar to files. But obviously won't work if you decide to move your game to Linux, for example.
If you want to keep track of all scores for all games played, a database may be a better solution than a simple file. There are databases for "local use", such as SQLite or MySql that you can run on your own machine (MySql will also run over network and can be centralized to a set of machines on the same network, and it used for a vast number of web-based applications).
And you could set up a (or use some existing) website, and use program driven web-access to store and restore the values. Or you could store a file on an FTP server, which is pretty much the same as web-access, but a little more "messing about" to configure and set up (and potentially more difficult to get through certain firewalls). Of course, if you want to have a "world-wide" top score, personal stats for each player, etc, then a web-based solution is probably the right way to go - but would also need a bit of security to prevent someone from just faking the score.
All choices have their benefits and drawbacks. Which is YOUR best choice really depends on what your ultimate goal is with your game. If it's simply a case of "Let's make a little game of tetris at home for myself and my friends to play", then it's probably not a big deal to keep the score in a text file. If you are looking for the next generation of World of Warcraft or some such, then web-based is almost certainly the ONLY solution.

Things i need to know to build a real time feed system in Django [closed]

It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center.
Closed 10 years ago.
I want to build a simple app where i have different users and they make updates and all the users get the updates in real time much like facebook.
Edit:
I just want to know how to push updates to profiles of users without them reloading the page. Do i make repeated AJAX calls or is there something out there that can solve this problem for me.
Edit 2:
Here's a presentation which helped me http://www.slideshare.net/oellegaard/implementing-real-time-web-applications-with-django
for real-time like interaction, one idea is to use sockets.
What I would do is write my front facing site in python/django, and have a node.js layer behind that w/ socket.io (websockets) that handles keeping all of the clients in sync.
[DB]
/ \
[Django] [node.js]
app logic -> \ / <- async updates
[Browser]
but really this is a fairly uninformed answer based heavily on assumptions b/c you haven't told us anything concrete about what your site needs to do.
You need to know how to Program, you need to know Python, and the Django Framework, you will need to know HTML, JavaScript, and CSS, you will need to know some Database of your choice, you will need to know enough to make educated decisions about MVC frameworks on the Client Side, you will need to know about Queues, Stacks, Asynchronous Callbacks, HTTP methods, Encryption and other Security Practices, the list goes on.
Basically, you need to know more then someone who would ask the question you asked.

Image anlaysis in C/C++ [closed]

It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center.
Closed 11 years ago.
I'm rather novice in C++ and I must realize this schoolar project :
Assume an image in a document containing both texts and images.
There should be a program written in C++ whose the goal is to load the document and extract separately texts and images in order to output it in
some target destinations like UI or file.
Furthermore, if image contains any texts like legends, program should be able to extract it separately too.
Is there an existing c++ library that respond to those requirements ?
Yes, OpenCV.
http://sourceforge.net/projects/opencvlibrary/
No doubt in that, use OpenCV.
But remember, you have a long way to go.
1. First of all, you should be good in C++ and object oriented programming.
Well, if you are not good, try to learn it first. Check out following link for some best resources : https://stackoverflow.com/questions/909323/what-are-good-online-resources-or-tutorials-to-learn-c
2. Then get OpenCV and install
Check out OpenCV homepage to get info about downloading and installing OpenCV.
3. Now get and read some good books on OpenCV
The best book on OpenCV is "Learning OpenCV" written by Gary Bradsky, main founder of OpenCV.
Second one is "OpenCV cookbook".
These books contains lots of examples on OpenCV along with description
4. Check out OpenCV documentation.
OpenCV documentation contains details of complete functions. It also includes a lot of tutorials, which are really good for all.
5. Also try running OpenCV samples. It contains a lot of good programs
And always, Google is your best friend. Ask everything there first. Come here only when you are lost in your path.
Acquire all the above things. Then you will be really good in OpenCV and i am sure you will enjoy its power. Once you are done with these, you will get enough idea on realizing your project.( Otherwise, you will post new questions every day asking codes to realize your project, which will be useless for you. )
For your understanding, your project include advanced things like Optical Character Recognition. It is a big topic. So build yourself from basics. And it will take time.
All the best.

Editing bitmaps in C++ [closed]

It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center.
Closed 11 years ago.
I am wondering if there is any good tutorial or a book on loading,creating and editing bitmaps in c++. I need to edit bitmap pixel by pixel but none of the tutorials don't show how. I want to understand how does bitmap "work" and wikipedia helped a little.
If you want to manipulate bitmaps on the pixel level, then you should start learning Image Processing and then read something about bitmap file formats. It is not a C++ question. C++ is just icing on the cake in such task.
Here you can find some lectures on Image processing:
http://www.archive.org/details/Lectures_on_Image_Processing
And here is the description of BMP file format:
http://www.fileformat.info/format/bmp/spec/e27073c25463436f8a64fa789c886d9c/view.htm
You can easily find a lot of sources for other formats as well. Good luck, I have been studying this topic three years at the university... I think you really should use some open source library as David Grayson advised.
If you want to edit a bitmap you only need to learn about the format you want to edit. How many bits per component, how many components per pixel, where is the width and height defined, what's the standard for said format files. If you want to use the popular BMP you can find all this in Wikipedia.
If all this made little sense to you, then you should try a tutorial on digital image processing first.
An image is just an array of structures (pixels) with a certain number of components each, you just need to read and write said array to do whatever edition you want. But be warned, although common crops and pixel replacement are almost trivial, advanced edition and altering are not.
I'm assuming you searched Google already and didn't find anything good.
If I were you, I would learn about the binary format of bitmaps first. You can learn about it by reading the specifications and/or looking at bitmap files with a hex editor like WinHex or ghex2.
Then I would learn how to read files and work with binary data in C++.
But really you could probably save a lot of effort if you just used the Magick++ library:
http://www.imagemagick.org/Magick++/

Simple text editor in Qt/C++ [closed]

It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center.
Closed 10 years ago.
I would like to write a simple text editor. I would like it to be GUI-based, and written using Qt.
Qt provides the class QTextEdit, which is a pretty fully-featured text editor (it supports ctrl+c, x , and z, text highlighting, and moving the cursor around left-right-top-down). I would like to write something similar, but I would like to implement all this functionality from scratch.
So my requirements are:
A simple window.
Be able to read text from a user, and output the prepared file to the screen.
The user must be able to access the text for editing.
I have taken a look at the source code to qtextedit.cpp from the official Qt site to get some idea of how this was implemented. Unfortunately I am not experienced enough to understand it (there are nearly 4000 lines of code, and many macros).
How might I make some progress with my project?
I think you are best off taking a look at some of the code here: http://kde-apps.org/index.php?xcontentmode=241
Take a look at the code, try coding something of your own, and realise that Qt requires one to know C++ fairly well. You will, at the very least, need to understand classes and pointers. If that feels manageable, then the best way is generally to try: you'll run into some problems, and then you can see how other people have solved that problem.
I think the most specific advice I can give is to write tests for everything that looks like it can reasonably be tested, that may save you some debugging time. Other than that, there's little more to say without example code and a more specific question.
This is a major job of work. If you want a decent editor, you are more or less forced to start with the Scintilla edit control, because it's simply the best (and it comes with a Lesser General Public Licence). But then you have to implement an editor on top of it. You don't really want to do this (trust me), so you have to use an existing open-source editor. The best of these is probably Notepad++, which has way more than 4000 lines of code. It comes with a General Public Licence, which is not compatible with the project I'm currently working on, so I ended up using the SciTE editor instead. I have implemented an interface for this which lets me embed it in a Qt application, and it works like a charm. In the next two or three months I hope to get this interface accepted by the SciTE community and incorporated into the official release. Meanwhile, if you are not bound by the licensing requirements, you might want to look at QScintilla.
In the Qt Demo application there is an MDI text editor that teaches a lot (http://doc.qt.nokia.com/latest/mainwindows-mdi.html).