I am trying to capture an image from my web camera on windows using Python 3.
I checked already openCV, but the support of python-3 is missing.
Is there any other way to do so?
In the meantime, OpenCV 3.1 was released and works with Python 3 (since OpenCV 3.0). Pre-compiled Windows binaries can be found here: http://www.lfd.uci.edu/~gohlke/pythonlibs/#opencv
you can try OpenCV, SimpleCV.
using SimpleCV:
from SimpleCV import Image, Camera
cam = Camera()
img = cam.getImage()
img.save("filename.jpg")
using OpenCV:
from cv2 import *
# initialize the camera
cam = VideoCapture(0) # 0 -> index of camera
s, img = cam.read()
if s: # frame captured without any errors
namedWindow("cam-test",CV_WINDOW_AUTOSIZE)
imshow("cam-test",img)
waitKey(0)
destroyWindow("cam-test")
imwrite("filename.jpg",img) #save image
using pygame:
import pygame
import pygame.camera
pygame.camera.init()
pygame.camera.list_camera() #Camera detected or not
cam = pygame.camera.Camera("/dev/video0",(640,480))
cam.start()
img = cam.get_image()
pygame.image.save(img,"filename.jpg")
Install OpenCV:
install python-opencv bindings, numpy
Install SimpleCV:
install python-opencv, pygame, numpy, scipy, simplecv
get latest version of SimpleCV
Install pygame:
install pygame
Related
I purchased a M1 Mac. Is anyone having issues with imshow with opencv. I did pip install opencv-python and brew install opencv and brew install opencv as well.
import cv2
import urllib
import numpy as np
import requests
url = 'https://www.visitcalifornia.com/sites/visitcalifornia.com/files/styles/welcome_image/public/vc_crtr_borntobewild_module_mendocino_st_rf_623667652_1280x640.jpg'
from skimage import io
img = io.imread(url)
img = cv2.cvtColor(img, cv2.COLOR_RGB2BGR)
cv2.imshow('URL Image', img)
cv2.waitKey()
and also
import cv2
cv2.namedWindow("preview")
vc = cv2.VideoCapture(0)
if vc.isOpened(): # try to get the first frame
rval, frame = vc.read()
else:
rval = False
while rval:
cv2.imshow("preview", frame)
rval, frame = vc.read()
key = cv2.waitKey(20)
if key == 27: # exit on ESC
break
cv2.destroyWindow("preview")
vc.release()
does not work for me
It was solved by
pip install opencv-python opencv-python-headless
I was able to solve this by building from the source code of OpenCV 4.5, use this link to get the source code
Try to install Miniconda from https://docs.conda.io/en/latest/miniconda.html
then activate it and try to install cv2 pip install opencv-python
getting 80-90 FPS for just reading image & showing
from my side, all are working in M1 using Miniconda
Opening the terminal in rosetta and doing a pip install(inside virtual environment) helped me build the opencv. Before this , while I was doing it with the M1 terminal, it was giving errors stating some architecture issue. Guess this did the trick to me.
Create Virtual Environment -> Activate it -> (Rosetta Terminal) -> pip3 install opencv-python
Install OpenCV using pip. This normally gives a ffmpeg error, so install that first
First do:
pip3 install ffmpeg
and then
pip3 install opencv-python
I thought I had the same issue. The window was not popping up when using cv2.imshow() or cv2.namedWindow(). I realized hours later that the window was there in the Mac menu bar, I just had to click on it.
I have a Python/OpenCV project and I am trying to use the xfeatures2d module from opencv-contrib. I am using a Mac and my IDE is PyCharm. I have installed the packages opencv-contrib-python and opencv-python through Preferences > Project Intepreter.
However, when I try to run the code below, I get a the following error:
import cv2
import numpy as np
img = cv2.imread("NotreDame.jpg", 0)
sift = cv2.xfeatures2d.SIFT_create()
line 6, in <module>
sift = cv2.xfeatures2d.SIFT_create()
cv2.error: OpenCV(4.1.0) /Users/travis/build/skvark/opencv-python/opencv_contrib/modules/xfeatures2d/src/sift.cpp:1207: error: (-213:The function/feature is not implemented) This algorithm is patented and is excluded in this configuration; Set OPENCV_ENABLE_NONFREE CMake option and rebuild the library in function 'create'
I have installed opencv and opencv-contrib on my computer using:
$ pip install opencv-python==3.4.2.17
$ pip install opencv-contrib-python==3.4.2.17
I am not sure how I can resolve this error. Any insights are appreciated.
Been experimenting with using Ruby inside a jupyter notebook. With Python I can do this
import matplotlib.image as mpimg
Does anyone know the equivalent with Ruby, I have not been able to find it in any of the iRuby or sciruby documentation?
To clarify a little, In my gemfile I have this
gem 'iruby'
gem 'cztop'
gem 'matplotlib'
But cannot seem to get access to the image part of matplotlib that I am use to using in python.
I am trying to find the Ruby version of what, in Python, I would write like this
#importing some useful packages
import matplotlib.pyplot as plt
import matplotlib.image as mpimg
...
%matplotlib inline
#reading in an image
image = mpimg.imread('test_images/solidWhiteRight.jpg')
#printing out some stats and plotting
print('This image is:', type(image), 'with dimesions:', image.shape)
plt.imshow(image) #call as plt.imshow(gray, cmap='gray') to show a grayscaled image
Thanks so much for any suggestions
This is how far I can get it to work in jupyter notebook on MacOSX:
require 'matplotlib/pyplot'
plt = Matplotlib::Pyplot
image = plt.imread 'test.png'
puts "This image's dimensions: #{image.shape}"
plt.imshow(image)
plt.show()
I used your Gemfile with the additional gem rbczmq to avoid the kernel dying (hint found here):
gem 'iruby'
gem 'cztop'
gem 'matplotlib'
gem 'rbczmq'
Note that I used a .png because matplotlib can only read PNGs natively without PIL installed.
This is how the result will look like:
Displaying the result inline as in the python version:
seems to be impossible.
I am trying to create an uin8 image with a colormap using pillow. I did the following:
from PIL import Image
import numpy as np
im = np.hstack( (np.ones((200,100))*255, np.zeros((200,100)) )).astype(np.uint8)
pim = Image.new("L", im.shape, 0)
print(im.min(), im.max())
pim.putdata(im)
pim.save("out.gif")
This should create a black and white image, but for some reason its just pitch black. What am i doing wrong here?
I am using: Pillow 4.2.1 (python 3.6)
I'm new to OpenCV and am having a problem with cv2.imshow. Here's my code:
import numpy as np
import cv2
print("Version is", cv2.__version__)
print("Build info", cv2.getBuildInformation())
img = cv2.imread('../coelacanth.jpeg', cv2.IMREAD_COLOR)
if img is None:
print("no image")
else:
print("there is an image")
cv2.line(img, (0,0), (150, 150), (255, 255, 255), 15)
cv2.imshow('image', img)
cv2.waitKey(0)
cv2.destroyAllWindows()
I get this error:
line 16, in <module>
cv2.imshow('image', img)
line 16, in <module>
cv2.imshow('image', img)
cv2.error: /Users/travis/build/skvark/opencv-python/opencv/modules/highgui/src/window.cpp:583: error: (-2) The function is not implemented. Rebuild the library with Windows, GTK+ 2.x or Carbon support. If you are on Ubuntu or Debian, install libgtk2.0-dev and pkg-config, then re-run cmake or configure script in function cvShowImage
The call to cv2.line seems to work. If try cv2.waitKey(0) without the imshow, I get the same error.
I installed OpenCV3 with
brew install --with-examples --with-contrib --with-python3 --with-qt --without-python -v opencv3
So, clearly I need to
Rebuild the library with Windows, GTK+ 2.x or Carbon support
but I don't know how to do that and haven't been able to work that out from searching other questions. Does anyone have any suggestions?
It was a pathing problem. In .bash_profile, we commented out
#PATH="/Library/Frameworks/Python.framework/Versions/3.6/bin:${PATH}"
#export PATH
Then uninstalled with brew uninstall opencv3 and reinstalled with the brew command given in the original question.