Why is OpenCV python crashing in Windows? - python

I am running OpenCV2.2 on Windows 7 64-bit.
I built OpenCV using cmake with MinGW 32-bit.
I have no problem with the C/C++ build. However the python bindings seem to have some problems. Most of the python samples are crashing.
The HighGui functions seem to cause trouble. Python crashes when I try to read an image (using imread, LoadImage or LoadImageM), display an image (imshow or ShowImage) or even create and manipulate windows (NamedWindow, MoveWindow, etc).\
WaitKey doesn't crash python but it always returns a -1 immediately, no matter how long the delay I provide. Similarly imgproc functionality listed under "Image Filtering" in the reference seem to crash python. I haven't been able to test it with too many other functions, mainly because I can't load in images and I am forced to test it with matrices i have built myself.
I am currently using python 2.6.6 (32-bit) , but I got the same problem with python 2.7 (32-bit). I also tried building the python wrappers for OpenCV2.1, and I got the same problem. It's very likely a problem specific to my setup. I've been cracking my head against this problem for quite some time now, I would appreciate any help.
Thanking you in advance.
Regards,
Anush.

Related

Displaying graph using python online compiler with matlab library

I've written a program with python to display a graph with matlab library which displays it in a new window with python3. I would like to use an online compiler (https://www.tutorialspoint.com/execute_python_online.php) so that I would be able to share the program, but because this requires matlab to open a window, the online compiler fails. How am I able to solve this?
Can you just send the entire .py file to someone else so they can run it on their computer? As far as I know, there is no option for running Python code online without requiring a download / installation that is free where you can also install libraries (like matplotlib).

Code completion is not working for OpenCV and Python

I am using Ubuntu 14.04. I have installed OpenCV using Adrian Rosebrock's guide. I am also using PyCharm for programming python and opencv.
My problem is that I can use code completion for cv2 modules but code completion wont work for instances initiated from cv2. An example is shown below.
This works:
This does not:
There is no run time error when I write my program as expected. Such that cap.isOpened() works without an error.
Though I am Window user, I also had faced similar problem with you. In my case, I could solve this problem by importing this way:
from cv2 import cv2
As I'm lack of knowledge of how does the python imports module, I can't explain you clearly about why this solve the problem, but it works anyway.
Good luck.
The openCV python module is a dynamically generated wrapper of the underlying c++ library. PyCharm relies on the availability of python source code to provide autocomplete functionality. When the source code is missing (as in the opencv case), pycharm will generate skeleton files with function prototypes and rely on those for autocompletion but with diminished capabilities.
As a result when you autocomplete at
cv2.
it can figure out that the module cv2 has the following members and provide suggestions.
On the other hand when you
cap = cv2.VideoCapture(file_name)
PyCharm can figure out that you just called a method from the cv2 module and assigned it to cap but has no information about the type of the result of this method and does not know where to go look for suggestions for
cap.
If you try the same things in shell mode, you will see the behavior you actually expected to see, since in shell mode will actually introspect live objects (it will ask the created cap object what members it has and provide those as suggestions)
You can also write stubs for the opencv module yourself to enable correct autocompletion in edit mode.
Take a look here
If anyone still is experiencing the issue, downgrading to opencv to 4.5.5.62 helped my case.
I am using PyCharm on windows 10 and faced similar issue on the intellisense for cv2.
This is my solution:
Pycharm>File>Manage IDE settings> Restore Default settings
Restart the Pycharm IDE
Reconfigure Python Interpretor

Clyther-how to get started?

I don't get what Clyther is or how to use it.
My stuff:
ATI OpenCl SDK (just dl'd)
clyther beta (just dl'd)
windows 7 pro 64 bit
active python 3.1.2
Xfxs Ati radeon 5850 video card
I downloaded the ATI OpenCl SDK and the clyther beta from sourceforge. Then I tooke the sample 'reduce' function from the sourceforge documents and pasted the code into notepad and named it clythersample.py. When I double-click the file or open it in the interactiveshell, it gives an error message on the first line.
Is naming the file .py wrong? I guess clyther is its own lqnguage and not really python? Can I write python code and in the middle of the program, write a chunk of clyther code? Will python IDEs (esp. Wing understand and debug it?) Will it work with python 3 or do I need 2.6? Is 64 bit os ok?
(I'm not a programme or technically competent, so things like its a python API for OpenCl or it had C bindings for python don't mean a whole lot).
Clyther is a Python package for High-Performance Computing (HPC) using, for example, video cards with multiple Graphics Packaging Units (GPUs) or (less frequently) multi-core processors. Clyther is for parallel processing of algorithms or data sets that would normally take a lot of time to process serially. Meaning, if you have a problem that can be split into many smaller problems, then Clyther is a useful package to use. Additionally, your problem must be something that can use numpy arrays.
Clyther is a nice package to use if you have the problem it is intended to solve. It makes it fairly easy to write Python code to run on multiple processes.
If that's not the problem you need to solve, then Clyther probably won't help you.
When you name the file .py (the file extension associated with python.exe) and double-click it, how is windows supposed to know it's supposed to run the file with CLyther?
Is naming the file .py wrong? I guess clyther is its own lqnguage and not really python?
Documentation compares it with Cython - so I suppose it's an extension to the language, i.e. they take Python and bolt more features on it.
Can I write python code and in the middle of the program, write a chunk of clyther code?
From the goals of the project, it should (like Cython) ultimately be able to accept all or most Python code. So, yes - but of course you'd have to run the whole program with CLyther.
Will python IDEs (esp. Wing understand and debug it?)
Not natively, I suppose.
Side note: The project is in a very early stage of developement (very first beta-release), so don't expect things to run smoothly right now.

Problems with process created using 32bit python on Debian 5.0 IA-64

So, the problem is with creating processes - all of them immediately return with exit code -9.
I tried to use subprocess.Popen module and os.popen2, os.system and some other. Nothing helps.
I'm using python 2.5.
I have a python binary executable built on 32bit platform with 32bit python using pyinstaller. This is very important and I know that the best way to make it working is to create ia64 executable. But currently I'm looking for more common solution. It possibly exists cause on several other IA64 machines it worked.
Have anybody faced similar problem?

OpenGL in Python with Snow Leopard?

I'm interested in playing around with OpenGL in Python. I've used OpenGL in C++ and Objective-C, but I don't have much experience in Python. I'm wondering if there's a good tutorial that works in Snow Leopard. I'd prefer to stay in 64-bit mode if possible, since I've heard 32-bit programs require loading a lot of extra 32-bit libraries.
I've already tried a PyOpenGL/wxPython tutorial. When I ran the code, it crashed with this message:
ImportError: /System/Library/Frameworks/Python.framework/Versions/2.6/Extras/lib/python/wx-2.8-mac-unicode/wx/_core_.so: no appropriate 64-bit architecture (see "man python" for running in 32-bit mode)
It looks like there's a bug in wxPython that prevents it from working on a 64-bit system.
I also looked at Pyglet, but they have a similar issue. They provide a work-around (setting Python to 32-bit mode), but it doesn't look like they're going to fix it.
Finally, I looked at PyGLUT, but I think it's only for Windows.
Are there any other libraries that would let me access OpenGL and draw on the screen? Again, I'd prefer to stay in 64-bit mode, but if nothing works, I'll switch to 32-bit and try wxPython or Pyglet again.
Edit: I've also tried PyGame. It depends on SDL which is broken in SL. I thought about trying to use Cocoa through PyObjc, but the Xcode Python application templates have been removed.
I've used PyOpenGL 3.0.0 quite successfully on Snow Leopard. It uses ctypes, so it should be making 64-bit calls if those libraries are available (and Snow Leopard's Python includes a 64-bit version). I haven't used the wxPython stuff with PyOpenGL so that's where you might be running into problems, but PyOpenGL also includes GLUT, which both run fine.
There's probably no good reason to avoid 32-bit mode. Unless your Python programs need to larger address space, of course.
You could try pygame. Pygame is a python wrapper around SDL. According to their website they have Max OS X binaries. Here is a simple example of using pygame with OpenGL. Once you are able to create the window and handle events most OpenGL programming is just like it would be in C or C++, but with some added python goodness. For OpenGL a great tutorial is NeHe.
Also when programing with OpenGL in python remember that Python datastructures can be rather slow when it comes to requirements for 3D graphics. PyGL developers for example recommend using ctypes for operations that concern graphics, since that way you can get enough performance for some complicated geometry with bareable FPS.

Categories