Gtk Warning Theme parsing error, trying to do some facial recognition - python

i'm having what i think is a gtk error in python while trying to recognize some faces and then apply a gaussian blur, i'm new in python! Here is the error:
*Gtk-WARNING *: 00:11:03.559: Theme parsing error: gtk.css:6321:10: "height" is not a valid property name
i'm currently using Archlinux and python 3+, i checked ~/.config and my Gtk is 2.0, idk if that is the issue and i also don't know how to change it/ update it.
Here is the code i'm triying to compile:
from skimage.filters import gaussian
from skimage import color
from skimage import data
import scipy.misc
import os
import sys
import plots
import matplotlib.pyplot as plt
from PIL import Image
path = "/home/carlos/python/img/jaja.jpeg"
img = plt.imread("/home/carlos/python/img/girl.jpeg")
#plt.show(img)
trained_file = data.lbp_frontal_face_cascade_filename()
detector = Cascade(trained_file)
detected = detector.detect_multi_scale(img=img, scale_factor=1.2, step_ratio=1, min_size=(50,50), max_size=(200,200))
print(detected)

Related

How to define a function using cwt in Python

I am trying to define a function using cwt in Python, however, I get the error message
global name 'cwt' is not defined
This is the code that I am using:
import os
import matplotlib.pyplot as plt
from matplotlib import cm
from matplotlib.pyplot import specgram
import librosa
import librosa.display
import numpy as np
from ssqueezepy import cwt
from ssqueezepy.visuals import plot, imshow
from numba import jit
#jit
def scaleogram_convert(data):
Wx, scales = cwt(data, 'morlet')
Wx = abs(Wx) # remove complex component
return Wx
img3 = scaleogram_convert(trimmed)
How can I get this function to work correctly when called?
Any help is greatly appreciated!

Getting Error with "from_raster" attribute in pysheds

This is my first time asking a question. I am trying to use "pysheds" to analyze some hydrologic DEM files. The developer as some pretty thorough "how to" videos but when I try to load the DEM file in the way that they show I get the following error:
module 'pysheds.grid' has no attribute 'from_raster'
here's my code
import numpy as np
import matplotlib.pyplot as plt
import matplotlib.colors as colors
import geopandas as gpd
import pysheds
import pysheds.grid as Grid
import mplleaflet
grid = Grid.from_raster('path.tif', data_name = 'dem')`
I checked the print(dir(Grid)) in the console and didn't see this attribute listed.
Am I missing something?
Thanks!
According to documentation, you should import Grid from pysheds.grid like this:
from pysheds.grid import Grid
grid = Grid.from_raster('n30w100_con', data_name='dem')
grid.read_raster('n30w100_dir', data_name='dir')
grid.view('dem')
instead of
import pysheds.grid as Grid

Using ImageGrab with bbox from pywin32's GetWindowRect

I want to use PIL's ImageGrab to capture a specific window. What my code below does is that it uses pywin32's FindWindow to get the handle of my wanted window then get its size and location with GetWindowRect. I then use ImageGrab with a bbox equal to the result that I got from GetWindowRect. However, this does not capture the whole window; a big chunk of the window is not shown. What did I do wrong? Here is my code and the result I get:
import win32gui
import cv2
from PIL import ImageGrab
import numpy as np
fceuxHWND = win32gui.FindWindow(None, 'FCEUX 2.1.4a: Super Mario Bros. (JU)
[!]')
rect = win32gui.GetWindowRect(fceuxHWND)
screen = np.array(ImageGrab.grab(bbox=rect), dtype=np.uint8)
cv2.imshow('test',cv2.cvtColor(screen,cv2.COLOR_BGR2RGB))
Result of code
Your DPI settings is at 125% and your process is not DPI aware. Call SetProcessDPIAware as follows
import ctypes
...
ctypes.windll.user32.SetProcessDPIAware()

Import Issue with Matplotlib and Pyplot (Python / Tkinter)

I am having an issue where I cannot call the 'pyplot' element of 'matplotlib'. From the code below you can see I've had to add a "TkAgg" for the mattplotlib element to work, which is a common issue.
import matplotlib
matplotlib.use("TkAgg")
However, now I cannot add the '.pyplot' to the import. I've tried the following:
import matplotlib.pyplot as plt
plt.use("TkAgg")
But this gives me the error:
AttributeError: module 'matplotlib.pyplot' has no attribute 'use'
How can I get around this as my code requires pyplot to function, but I cannot work out how to import it while still having to use ".use("TkAgg").
I am running Python 3.6.2 and I am using Tkinter to develop my program
Those are two entirely different things. You import matplotlib to be able to set the backend. Then you need to still import pyplot to be able to use it afterwards.
import matplotlib
matplotlib.use("TkAgg")
import matplotlib.pyplot as plt
# ... rest of code
If you use the use() function, this must be done before importing matplotlib.pyplot. Calling use() after pyplot has been imported will have no effect.
import matplotlib
matplotlib.use("TkAgg")
import matplotlib.pyplot as plt
check with :
matplotlib.get_backend()

Quickest way to preview a PIL image

I'm now working with PIL images in Python. What's the quickest way to preview a PIL image in the Python shell? Saving to a file and then opening it in my OS is pretty cumbersome.
The Image class has a show(self, title=None, command=None) method, which you can use.
After installing iPython and PyQT, you can display PIL images inline in ipython qtconsole after executing the following code:
# display_pil.py
# source: http://mail.scipy.org/pipermail/ipython-user/2012-March/009706.html
# by 'MinRK'
import Image
from IPython.core import display
from io import BytesIO
def display_pil_image(im):
"""displayhook function for PIL Images, rendered as PNG"""
b = BytesIO()
im.save(b, format='png')
data = b.getvalue()
ip_img = display.Image(data=data, format='png', embed=True)
return ip_img._repr_png_()
# register display func with PNG formatter:
png_formatter = get_ipython().display_formatter.formatters['image/png']
png_formatter.for_type(Image.Image, display_pil_image)
Example of usage:
import Image
import display_pil
im = Image.open('test.png')
im
ipython qtconsole will display the loaded image inline.
I would recommend to use iPython rather than the vanilla python interpreter. Then you can use matplotlib.pyplot.imshow function with ease, and with the Qt console you can even get the images plotted inline in the interpreter.

Categories