1

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:

OpenCV empty image window 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:

broken python icon

Please help me! I just want to use opencv for my school project...


Kindred
  • 1,229
  • 14
  • 41
  • 1
    The icon does not have anything to do with it, mine works fine and the icon still appears as such. Someone had the same problem the other day. I cannot find the question, but there wasn't an answer when I saw it, anyways. Do you have this same problem when running it as a script as opposed to in the interpreter? If `cv2` is importing fine (which it clearly is) then I don't think it's a problem with your install. – alkasm Jun 10 '17 at 09:13
  • I'm very appreciated for your kind reply, big thanks for you first. I'm happy to know about the information you just provided. Now I'm just removing it, and re-installing it with python2.7 through Homebrew. Yes, I've tried both methods. :)@AlexanderReynolds – Kindred Jun 10 '17 at 09:21
  • Hmm, I installed with the same tutorial with `python 3.6.1` also with `opencv 3.2.0`. But sure, give it a go in 2.7 and see what your results are. Did you test if `cv2.imwrite()` works? – alkasm Jun 10 '17 at 09:24
  • No, I'm new to OpenCV actually. I just read the documentation/tutorial and followed it. I will try your suggestion after finishing the installation. :) @AlexanderReynolds – Kindred Jun 10 '17 at 09:28

2 Answers2

1

If you just encounter the same problem, I can solve your problem. But you should take a look before you follow any further steps:

  1. I will recommend you first delete OpenCV 3.2 from your mac.

    Don't know how to delele? Here are the steps:

    1. 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 {} \;
      
    2. 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.

    3. 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.

  2. 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.

Kindred
  • 1,229
  • 14
  • 41
  • 1
    If he's trying to install OpenCV with the *modern version* of Python, why would you suggest he install with the older version of Python? You can absolutely get OpenCV 3.2.0 working with Python 3.6.1 on a Mac. – alkasm Jun 11 '17 at 03:07
  • Sorry for my misleading words. But actually the link I provided could work for both Python2.7 and Python3.6, and the link has step by step to let the reader setup for both. @AlexanderReynolds – Kindred Jun 11 '17 at 03:17
  • Ah--you should edit the link text then, as it links to tutorials for 2.7 *and* 3. As an FYI, that was the tutorial the OP was using in the first place. – alkasm Jun 11 '17 at 03:19
1

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.

eshirima
  • 3,837
  • 5
  • 37
  • 61