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)
Related
With seaborn 0.11.1 and matplotlib 3.3.4 this...
import matplotlib as mpl
from matplotlib import pyplot as plt
print(sns.__version__, mpl.__version__)
import seaborn as sns
sns.set_theme(style="ticks")
exercise = sns.load_dataset("exercise")
g = sns.catplot(x="time", y="pulse", hue="kind", data=exercise)
plt.show()
...the result is supposed to look like this:
However, when I do that in JupyterLab or Plotly-Dash I get:
I deleted ~/.config/matplotlib and setup a clean conda environment with minimal packages. Same result.
plt.rcParams['figure.autolayout'] = False
fixes it.
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.
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 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
I'm attempting to create graphs using pandas on Python 2.7 OSX 10.
import numpy as np
import pandas as pd
import Quandl
pd.options.display.mpl_style = 'default'
TOKEN = 'tWquoUMLCebqSBMbTFNg'
print 'Pandas Version', pd.__version__
print 'Numpy version', np.__version__
uk_df = Quandl.get('OECD/HEALTH_STAT_CICDHOCD_TXCMILTX_GBR', authtoken=TOKEN)
print uk_df.head(8)
uk_df.plot()
Output:
Pandas Version 0.12.0
Numpy version 1.8.0
…and then some data. The Python GUI spaceship attempts to open, but bounces forever. What am I missing here?
I have the latest matplotlib installed as well.