2

So here is my code:

import cv2
img = cv2.imread('new.bmp')
cv2.imshow('FRAME', img)
cv2.waitKey(0)
cv2.destroyAllWindows()

From what I have gathered on the internet, this is supposed to display the image 'new.bmp' in a window called'FRAME'. But all that happens is this!. Can anyone help me?

rjpj1998
  • 297
  • 1
  • 6
  • 23
  • does it load the image? the code seems to be ok, but it could be that it could not find the image or load it correctly... – api55 May 28 '17 at 14:59
  • @api55 It doesn't show any errors. How can I confirm if the image is loaded? I even tried loading the image though PIL then dumping its numpy array. I am quite familiar with PIL and can confirm the image was loaded. – rjpj1998 May 28 '17 at 15:46
  • 1
    Try grabbing a random JPG, GIF, or PNG from somewhere on the Web, and loading that instead to rule out any Microsoft madness in BMP files. – Mark Setchell May 28 '17 at 16:14
  • Nope. Not working. Exactly the same as before. – rjpj1998 May 28 '17 at 16:17
  • Which python are you using and how did you install it? Which OpenCV are you using and how did you install it? – Mark Setchell May 28 '17 at 16:38
  • @MarkSetchell I have python 3.6.0, homebrewed. Opencv 3.2, I installed it with the help of a tutorial from pyimagesearch.com. However I didn't install it in a virtual environment – rjpj1998 May 28 '17 at 16:45
  • I am no expert on Python (or OpenCV) but when I installed `Python3` via `homebrew`, I noticed that gave me a new binary called `/usr/local/bin/pip3` and it seems that if I use that (rather than plain `pip`) the packages I install are available in the `Python3` which I `homebrewed` whereas I believe anything I install with plain `pip` becomes associated with the Apple-supplied Python 2.x. – Mark Setchell May 28 '17 at 17:05
  • @MarkSetchell I didn't have to use pip to install opencv. – rjpj1998 May 28 '17 at 17:08
  • If you want to confirm if the image has been loaded, just check the dimensions of img by doing `height, width, channels = img.shape ` –  May 29 '17 at 08:59
  • @SembeiNorimaki I can confirm the image has loaded. I am reinstalling opencv on a shitty internet connection, will report tommorow probably. – rjpj1998 May 29 '17 at 10:21

2 Answers2

2

It was a silly installation problem.

I wholeheartedly apologize.

rjpj1998
  • 297
  • 1
  • 6
  • 23
  • Hi Sir, i'm facing the exact problem followed the same guide, it might also be a stupid mistake i made, i wonder where did your installation went wrong?, Sincerely [And here is a link to my question https://stackoverflow.com/questions/44603844/opencv-python-cv2-imshow-only-showing-top-bar-on-mac?noredirect=1#comment76219974_44603844] – libra Jun 21 '17 at 02:40
0

If anyone is facing this issue - please install pycharm and run your code there it will automatically open the webcam for you! hope this helps