import skimage
image = skimage.data.imread("my_image.png")
I used this code to read an image, but I got an error as "skimage.data" has no attribute "imread".
My skimage version is 0.18.1. What has to be changed in this to read an image?
The error is straightforward. You try to call the imread function in the data module, but there is no such function in this module. Call
skimage.io.imread('blah.png')
instead.
Related
I'm trying to examine multiple tone-mapping operators in Open CV, using Python.
Various sources use four operators (Drago, Durand, Reinhard, Mantiuk). Three of them work. However, when I call up cv2.createTonemapDurand(), I get this error:
AttributeError: module 'cv2.cv2' has no attribute 'createTonemapDurand'
Is it possible to call the Durand operator somehow, or did Open CV drop that one recently?
Thanks!
I'll switch from comment to answer to have a better representation.
you just have to :
import cv2
cv2.xphoto.createTonemapDurand()
Be aware that, if u compiled opencv by yourself, you had to check OPENCV_ENABLE_NONFREE.
Please post your code where you import cv2 and call the function. If you want to look for some functions, attributes or whatever either look in the documentation of the package or use dir() and type(). For your example you can use this:
import cv2
from re import match
cv2_filtered = filter(lambda v: match('.*Tonemap', v), dir(cv2))
[print(val) for val in cv2_filtered]
Returns:
Tonemap
TonemapDrago
TonemapMantiuk
TonemapReinhard
createTonemap
createTonemapDrago
createTonemapMantiuk
createTonemapReinhard
Seems like there is no function createTonemapDurand in cv2.
I want to use OpenCV's perceptual hashing functions from Python.
This isn't working.
import cv2
a_1 = cv2.imread('a.jpg')
cv2.img_hash_BlockMeanHash.compute(a_1)
I get:
TypeError: descriptor 'compute' requires a 'cv2.img_hash_ImgHashBase' object but received a 'numpy.ndarray'
And this is failing too
a_1_base = cv2.img_hash_ImgHashBase(a_1)
cv2.img_hash_BlockMeanHash.compute(a_1_base)
I get:
TypeError: Incorrect type of self (must be 'img_hash_ImgHashBase' or its derivative)
Colab notebook showing this:
https://colab.research.google.com/drive/1x5ZxMBD3wFts2WKS4ip3rp4afDx0lGhi
It's a common compatibility gap that the OpenCV python interface has with the C++ interface (i.e. the classes don't inherit from each other the same way). There are the *_create() static functions for that.
So you should use:
hsh = cv2.img_hash.BlockMeanHash_create()
hsh.compute(a_1)
In a copy of your collab notebook:
https://colab.research.google.com/drive/1CLJNPPbeO3CiQ2d8JgPxEINpr2oNMWPh#scrollTo=OdTtUegmPnf2
pip install opencv-python
pip install opencv-contrib-python #img_hash in this one
(https://pypi.org/project/opencv-python/)
Here I show you how to compute 64-bit pHash with OpenCV.
I defined a function which returns unsigned, 64-bit integer pHash from a color BGR cv2 image passed-in:
import cv2
def pHash(cv_image):
imgg = cv2.cvtColor(cv_image, cv2.COLOR_BGR2GRAY);
h=cv2.img_hash.pHash(imgg) # 8-byte hash
pH=int.from_bytes(h.tobytes(), byteorder='big', signed=False)
return pH
You need to have installed and import cv2 for this to work.
When attempting to pass my RNN call, I call tf.nn.rnn_cell and I receive the following error:
AttributeError: module 'tensorflow.python.ops.nn' has no attribute 'rnn_cell'
Which is odd, because I'm sure I imported everything correctly:
from __future__ import print_function, division
from tensorflow.contrib import rnn
import numpy as np
import tensorflow as tf
import matplotlib.pyplot as plt
But looking at the docs, things have moved around between tensorflow versions.
what would you all recommend to fix this??
Line, I'm getting the error against:
state_per_layer_list = tf.unstack(init_state, axis=0)
rnn_tuple_state = tuple(
[tf.nn.rnn_cell.LSTMStateTuple(state_per_layer_list[idx][0], state_per_layer_list[idx][1])
for idx in range(num_layers)]
)
Specifically:
tf.nn.rnn_cell
I'm using anaconda 3 to manage all of this so, the dependancies should all be taken care of. I have already tried working around a damn rank/shape error with Tensor shapes which took ages to resolve.
Cheers in advance.
Replace tf.nn.rnn_cell with tf.contrib.rnn
Since version 1.0, rnn implemented as part of the contrib module.
More information can be found here
https://www.tensorflow.org/api_guides/python/contrib.rnn
I am using opencv3.1.0.
While I am trying to run:
import cv2.cv as cv
import cv2
cascade = cv.Load('/usr/share/OpenCV/haarcascades/haarcascade_frontalface_alt2.xml')
I find that cv2.cv is not in opencv3, so I change cv2.cv to cv2
and then I get the error message in the title.
Any thoughts?
Many thanks.
You are trying to load a classifier from a file, correct?
According to the OpenCV3 documentation you should use CascadeClassifier for this.
Example:
import cv2
cascade = cv2.CascadeClassifier('/usr/share/OpenCV/haarcascades/haarcascade_frontalface_alt2.xml')
Source: http://docs.opencv.org/3.0-beta/modules/objdetect/doc/cascade_classification.html
I have freshly installed opencv, and checked that its properly installed by typing:
pkg-config --modversion opencv
at the command terminal.
I started using pything-opencv for reading and displaying an image, but when I run my code, it throws an error:
TypeError: 'NoneType' object has no attribute '__getitem__'
My code is very minimal, but not getting where is there error.
The code which I am running is:
import cv2
import numpy as np
from matplotlib import pyplot as plt
import argparse
img = cv2.imread('messi5.jpg')
print(img)
print("end of file")
It gives the output:
None
end of file
When I write two more lines as this:
px = img[100,100]
print(px)
then it throws error:
Traceback (most recent call last):
File "testing_opencv_python.py", line 23, in
px = img[100,100]
TypeError: 'NoneType' object has no attribute 'getitem'
The same code runs perfectly on other systems.
I would be thankful if you can point out the mistake.
I basically want to install caffe, but when i did that i was getting error, and seems like it depends on opencv, thats whey I have installed opencv.
Thanks and regards.
The returned image is None (you can see it when you print it), which is causing the other error down the line.
This is most likely due to specifying the wrong image path ('messi5.jpg'). In the the documentation here, it states:
Warning Even if the image path is wrong, it won’t throw any error, but print img will give you None
Either provide a correct path to 'messi5.jpg', or copy the image into your current directory (where you execute the python script).