I installed OpenCV3.2 + python3.6.1 from this installation guide. (For the paths needed in guide I typed:
Edit: I'm not sure, but I guess that I should install opencv under 3.6, not 3.6.1, please don't use my paths for your installation!
/usr/local/Cellar/python3/3.6.1/Frameworks/Python.framework/Versions/3.6/lib/python3.6/config-3.6m-darwin/libpython3.6.dylib
and
ls -d /usr/local/Cellar/python3/3.6.1/Frameworks/Python.framework/Versions/3.6/include/python3.6m/)
My testing code is completely the same as the tutorial of OpenCV 3.2 documentation, but the output screen show nothing but a title:
import numpy as np
import cv2
img = cv2.imread('1.jpg',0)
cv2.imshow('image', img)
cv2.waitKey(0)
The result:
As the picture shown the content of the image is missing.
and it seems that it has something to do with my python, the icon is broken:
Please help me! I just want to use opencv for my school project...
If you just encounter the same problem, I can solve your problem. But you should take a look before you follow any further steps:
I will recommend you first delete OpenCV 3.2 from your mac.
Don't know how to delele? Here are the steps:
Read this answer first if you want to know what the following command do in details, then run the following command in your Terminal:
$> sudo find / -name "*opencv*" -exec rm -i {} \;
Please read every delete-checking message carefully, or you may delete some of your files containing "opencv" in filename, which may not related to OpenCV but may be your personal files.
Your cv2.so will still alive somewhere in your disk, go checkout where it is with the following command in Terminal:
$> ls -l /usr/local/lib/python3.6/site-packages/
In my case I found the cv2.so at .../python3.6/..., you should press 'tab' at /usr/local/lib/python then check out the site-packages folder for each python version (,which maybe you're about to re-install the OpenCV,) to search cv2.so. if you found it, delete it.
Install OpenCV3.2 with Homebrew for Python2.7 / 3.6. Just follow all the steps, and keep in mind that Homebrew is your best friend.
Edit: The link works for both Python2.7 and 3.6.
I ran into a similar issue but on the C++ API perspective. Credits go out to mattmyne.
Window autosize was not working for macOS using cocoa. The window's image dimensions could not be found. This has been fixed by removing IP64 specific synthesize in window_cocoa.mm that was causing null reference for the window's contentView image property in cvShowImage (image reference was not linked to _image).
In a nutshell, OpenCV tried to support both 32 and 64-bit ObjC compilers but since Apple no longer supports 32-bit, some image synthesizing operations resulted in null references in 64-bit machines. More info
To resolve this, locate the file window_cocoa.mm; if built from source it'll be in opencv/modules/highgui/src.
Change this
#implementation CVView
#if defined(__LP64__)
#synthesize image;
#else // 32-bit Obj-C does not have automatic synthesize
#synthesize image = _image;
#endif
To this
#implementation CVView
#synthesize image = _image;
Do the same thing for the CVWindow and CVSlider implementations to accommodate videos as well.
Recompile OpenCV and test out your code.
Related
When I use a plugin that requires python, it can't find it and barfs.
The places that seem to being searched are:
Using -version I see both:
+python/dyn
+python3/dyn
However :echo has("python3") returns 0.
I'm not sure if this is compile time config, or runtime-configurable via .vimrc.
I'm not a python developer, and the few times I've ventured into that world were in the middle of the python2/python3 mess that turned me off completely. I've played around enough to have configured pyenv it seems, and get
╰─$ which python
/Users/benlieb/.pyenv/shims/python
╰─$ python --version
Python 3.10.3
Can anyone help shed light on what to do to get python3 findable/usable in my vim?
Update:
Following #romainl's suggestion below I set in my .vimrc
set pythonthreedll=/Users/benlieb/.pyenv/shims/python
But getting the following error:
+python/dyn and +python3/dyn are described here: :help python-dynamic.
By default, :help 'pythonthreedll' points to:
/opt/homebrew/Frameworks/Python.framework/Versions/3.10/Python
because MacVim is built against that version. The message in your screenshot says that there is nothing at that path. In order to have a working Python 3 interface, you can either:
install Python 3.10 via homebrew,
or point pythonthreedll to a valid path.
For example, I don't use Homebrew so the default value is useless to me, but I use MacPorts so this is my pythonthreedll:
set pythonthreedll=/opt/local/Library/Frameworks/Python.framework/Versions/3.10/lib/libpython3.10.dylib
After some time, I found the following works, thought it was not a fun path of discovery.
let &pythonthreedll = trim(system("pyenv which python"))
I have VS Code on a Mac.
Pillow is installed and version verified as 8.3.2 via Pip list in the terminal window of VS Code. I have confirmed via the pillow docs that the ImageOps.contain() is part of 8.3.
My problem is that when I use the terminal, type python and run the following, it works perfectly:
from PIL import Image, ImageOps
im = Image.open("images/Barcelona.jpg")
print(im.format, im.size, im.mode)
im = ImageOps.contain(im, (800, 800), method=3)
im.show()
Preview pops right up and shows me the picture.
When I put the exact code into VS Code or build a .py file with Nano, I get an error message which is shown in this image:
I've verified the right version of Python, Pillow, and such. Any help or pointers would be greatly appreciated.
This turns out to be a problem with what I can only call nested environments and/or a conflict between Anaconda and Workspaces. I'm not really sure but when I used the _version import to figure out a) what VS Code thought and then b) figured out the environment Pip was reporting on, I deactivated up one level, upgraded the (base) to the 8.3 version and all ran fine. The knowledge on importing the version variable to see precisely what the code is importing came from the question asked below and was invaluable.
I want to have python save an image file of the whole screen as a variable with ctypes so that I could access the screen in a program and do something with it (like put it on a pygame window). I can't use any other libraries unless they are included with python (no installing or pip). Does anyone know how to do this?
Edit: I'm using windows 10.
PIL.ImageGrab is from PILLOW (a python image library fork which you can install with pip). You can give a bounding box or capture the entire screen.
Update: OP now mentions he can't use external libraries.
Then you could virtually hit printscreen and read the clipboard. The code of PILLOW is open-source feel free to use it.
Remember that you can always call a command from within python:
>>> import os
>>> os.system("pip install pillow")
Or download the zip of the library and import it in your code.
Hi can anyone help. I am getting glitching on pygame sprite. The sprites are 50x50 pixels 72 res created in Photoshop. I am using:
tile.image = pygame.image.load(tile.name) to load adding them to a pygroup tileGroup.add(tile) then just doing a regular tileGroup.draw(screen)
I have tried the code on a Windows PC and it works fine. I can only assume it is a MAC thing. Can anyone shed any light?
I had the same problem and I fixed it by downgrading from SDL v1.2.15 to 1.2.10. SDL Library has this nasty bug exclusively on El Capitan and on versions higher than 1.2.10.
To downgrade via Homebrew, you should:
Go to "/usr/local/Library/Formula", find "sdl_image.rb" and rename it to something in case to backup it.
In Terminal, use "brew create https://www.libsdl.org/projects/SDL_image/release/SDL_image-1.2.10.tar.gz". It should create new "sdl_image.rb" in the same location.
Open the new "sdl_image.rb" and the old one; Copy the lines that starts with "depends_on" and whole "install" function from the old image file and then replace "install" function in the new file with these lines.
In Terminal, use "brew install sdl_image".
This also sometimes happens with the Tkinter module, and mostly on mac (when you draw things on the screen it lgitches a lot.)
I believe it is a mac problem, so you could try the following:
You could use a different image,
you could .convert() the image
you could .convert_alpha() the image
I am trying to import the brew installed version of python by emulating the Global Libraries structure existing for the (mostly) working mac os built-in 2.7.2. However IJ is unable to infer the types or to create the library properly.
Update this is a large existing project. Creating a new project just to get a different version of python is not an option.
Here are the steps:
Try to create new Global Library: Fail : no python .
OK, so I use Copy to clone the built-in SDK:
Now - let us try to emulate the paths included in the original built-in but with the brew base dir: here is a starting point:
And here is one of the exact entries from the builtin library:
So let us clikc on the + to add it:
So .. IJ is unable to handle it properly. I also tried a half dozen others - all with same shrug result from IJ.
So then what is the correct process?
Update Here is the project SDK dialog (thanks to scribbles).
And trying to add: **but the "OK" button is not enabled! So then IJ is not able to load it..
New Project -> Select SDK.
See this video if you still have any questions.
EDIT: Is this more along the lines of what you're looking for (link)?
This is old, but but I ran into the same problem with the current Python 2 install from homebrew in High Sierra. Instead of choosing a directory like it needed in the previous setup, I just setup the Python SDK pointing to the python executable link in /usr/local/opt/python/libexec/bin (which is the directory I added to my path for Python 2. It seems to be working just fine now.
Hopefully this will help someone.