I install opencv in python with running $ sudo apt-get install python-opencv and installed successfully. but when run this code
import opencv
import opencv.highgui
import time
import commands
def get_image():
image = opencv.highgui.cvQueryFrame(camera)
return opencv.adaptors.Ipl2PIL(image)
camera = opencv.highgui.cvCreateCameraCapture(-1)
while 1:
image = get_image()
image.thumbnail((32, 24, ))
image = tuple(ord(i) for i in image.tostring())
x = int((int((max(image) / 256.0) * 10) + 1) ** 0.5 / 3 * 10)
cmd = ("sudo su -c 'echo " + str(x) +
" > /sys/devices/virtual/backlight/acpi_video0/brightness'")
status, output = commands.getstatusoutput(cmd)
assert status is 0
Got follow error
$ python bright.py
Traceback (most recent call last):
File "bright.py", line 1, in <module>
import opencv
ImportError: No module named opencv
Could you please help me?
You should be importing is cv2 not opencv, there is also no highgui. You might want to check out the docs
To install opencv for python you need the command
$ pip install opencv-python
To import it so as to use in applications the import to call the package is
import cv2
Related
I am trying to use LiveSpeech with my model and dictionary which I have trained:
#!/usr/bin/env python
from pocketsphinx import LiveSpeech
hmm = '/home/ridwan/sphinx/other1/output/other1.ci_cont' #folder of the acoustic model
lm = '/home/ridwan/sphinx/other1/output/other1.lm.DMP' #language model
dict = '/home/ridwan/sphinx/other1/output/other1.dic' #the phonetic dictionary
recognizer = LiveSpeech (verbose = False, sampling_rate = 16000, buffer_size = 2048,
no_search = False, full_utt = False,
hmm = hmm, lm = lm, dic = dict)
for phrase in recognizer:
print (phrase)
But I am getting the following error:
Traceback (most recent call last):
File "./main.py", line 3, in
from pocketsphinx import LiveSpeech
ImportError: cannot import name LiveSpeech
NOTE: I have successfully installed pocketsphinx from CMU Sphinx
I had an old version of pocketsphinx.
Make sure to have the latest installed.
# Make sure we have up-to-date versions of pip, setuptools and wheel:
$ pip install --upgrade pip setuptools wheel
$ pip install --upgrade pocketsphinx
I've installed the pptx package using the following command:
pip install python-pptx
However, When ever I try to import the package this is the output I receive:
Traceback (most recent call last):
File "/Users/divyabahri/Documents/hello.py", line 5, in <module>
import pptx
ModuleNotFoundError: No module named 'pptx
Can someone please guide me regarding the latter issues, Thanks in Advance!
Mismatch in the python version could be the cause of the error. The problem can be fixed by explicitly using PIP version 3 and also Python version 3.
Working demo:
Step 1: Install python-pptx and its dependencies using pip version 3
$ pip3 install python-pptx
$ pip3 install lxml ---> dependency
$ pip3 install pillow ---> dependency
Step 2: Python 3 program to create a pptx file
# File name: demo.py
from pptx import Presentation
prs = Presentation()
title_slide_layout = prs.slide_layouts[0]
slide = prs.slides.add_slide(title_slide_layout)
title = slide.shapes.title
subtitle = slide.placeholders[1]
title.text = "Hello, World!"
subtitle.text = "python-pptx was here!"
prs.save('test.pptx')
Step 3: Execute the program using Python version 3
$ python3 demo.py
Step 4: Verify that the test.pptx file got created.
There can be many reasons for that:
1.- Python pptx only supports python version 3.6 or less here is the documentation https://python-pptx.readthedocs.io/en/latest/user/install.html
2.- Check also your path, check if python version that is availabel for pptx is on the path, here you can see how to check your path, https://winaero.com/blog/how-to-see-names-and-values-of-environment-variables-in-windows-10/
3.- pip is outdated, try to upgrade your pip
4.- maybe you import bad the library, here you can see how to import it, https://python-pptx.readthedocs.io/en/latest/user/quickstart.html
I'm trying to run this code:
http://forumbilder.se/H8CIL/skarmavbild-2018-10-08-kl-21-22-19
so I change it to this one:
and then I got this:
http://forumbilder.se/H8CIL/skarmavbild-2018-10-08-kl-21-22-47
What's wrong? I'm a newbie, and fyi, I'm only have anaconda installed to my Python 3.6.6 .
Regards,
--
and in code:
from skimage import data
photo_data = misc.imageio('./wifire/sd-3layers.jpg')
type(photo_data)
and i get this error:
---------------------------------------------------------------------------
AttributeError Traceback (most recent call last)
<ipython-input-9-c8186ae7b8e9> in <module>()
1 from skimage import data
2
----> 3 photo_data = misc.imageio('./wifire/sd-3layers.jpg')
4
5 type(photo_data)
AttributeError: module 'scipy.misc' has no attribute 'imageio'
So I change it to:
You have to import imageio. You might have to install the library if you don't have it yet (on your terminal):
pip install imageio
(If you don't have pip install yet, you can do on your terminal sudo easy_install pip, see here: How do I install pip on macOS or OS X?)
And then your code to use read the image with imageio:
import imageio
im = imageio.imread('./wifire/sd-3layers.jpg')
type(im)
To display your image, you can use visvis library (https://imageio.readthedocs.io/en/stable/examples.html). Then you total code would be:
import imageio
import visvis as vv
im = imageio.imread('./wifire/sd-3layers.jpg')
vv.imshow(im)
I cannot seem to figure out how to fix a problem with my code regarding import ImageTK from PIL. I have searched and downloaded Pillow different ways and the error of the code is still the same.
Traceback (most recent call last):
File "8_Age_Calculator_App.py", line 3, in <module>
from PIL import Image, ImageTK
ImportError: cannot import name 'ImageTK'
These are the import codes of the file
import PIL
from PIL import Image, ImageTK
import tkinter as tk
import datetime
and this is the code that is trying to import the image
main_image = Image.open('/Users/Brenden/Documents/Python_OOP/old-people-
running-illo_h.jpg')
main_image.thumbnail((100,100), Image.ANTIALIAS)
main_photo = ImageTK.Photoimage(main_image)
main_label_image = tk.Label(image=main_photo)
main_label.grid(column=1, row=0)
How may I fix this problem?
Use this command for Python 3
sudo apt-get install python3-pil.imagetk
You have a typo in the module you want to import. The k in ImageTk should be lower case:
from PIL import Image, ImageTk
this should solve your problem
and in your script you have another case typo, PhotoImage is CamelCase:
main_photo = ImageTk.PhotoImage(main_image)
Install it using this command.
sudo apt-get install python-imaging-tk
ImageTK is k(small letter) not K (capital letter)
from PIL import Image, ImageTk
To install for python2 type in terminal:
sudo apt-get install python-pil.imagetk
For python3 type:
sudo apt-get install python3-pil.imagetk
To import Image and ImageTk:
from PIL import Image, ImageTk
There's a typo in your script, it will be PhotoImage:
main_photo = ImageTk.PhotoImage(main_image)
Try to write this command in the terminal:
pip install pillow
It will install PIL packages
>>> import cv2
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ImportError: No module named cv2
>>>
I installed openCV from here in my root directory. I am not able to use it in my project.
Any suggestions?
Download the latest package from this link
http://opencv.org/downloads.html
Try building and installing opencv from this link.
http://rodrigoberriel.com/2014/10/installing-opencv-3-0-0-on-ubuntu-14-04/
Ahh! finally after all struggle i made it.
This is the fresh start from beginning:
Step 1: Remove previously installed openCV from your system
sudo apt-get autoremove opencv-doc opencv-data libopencv-dev libopencv2.4-java libopencv2.4-jni python-opencv libopencv-core2.4 libopencv-gpu2.4 libopencv-ts2.4 libopencv-photo2.4 libopencv-contrib2.4 libopencv-imgproc2.4 libopencv-superres2.4 libopencv-stitching2.4 libopencv-ocl2.4 libopencv-legacy2.4 libopencv-ml2.4 libopencv-video2.4 libopencv-videostab2.4 libopencv-objdetect2.4 libopencv-calib3d2.4
Step 2: Follow this guide step by step: http://foxrow.com/installing-opencv-in-a-virtualenv/