Issue with TextDetectorCNN_create - opencv

I am running opencv 4.1.0 Windows 10 64 bit with python 3.7.
My code is:
img = cv2.imread('C:/projects/kort/Hjerter/IMG_2383.jpg')
det = cv2.text.TextDetectorCNN_create("c:/projects/Caffe/textbox.prototxt", "c:/projects/Caffe/TextBoxes_icdar13.caffemodel")
rects, probs = det.detect(img)
Here is the error I get (below). Any hints?
rects, probs = det.detect(img)
Traceback (most recent call last):
File "", line 1, in
cv2.error: OpenCV(4.1.0) C:\projects\opencv-python\opencv_contrib\modules\text\src\text_detectorCNN.cpp:66: error: (-2:Unspecified error) in function 'void cdecl cv::text::TextDetectorCNNImpl::detect(const class cv::InputArray &,class std::vector > &,class std::vector &)'
(expected: 'inputImage.channels() == inputChannelCount_'), where
'inputImage_.channels()' is 1
must be equal to
'inputChannelCount_' is 3

Related

TypeError: Image data of dtype object cannot be converted to float as cv2 is not reading any image but the path is right

I am trying to load an image in Python Jupyter notebook but I am getting an error as it is showing they are not getting any image.
img = cv2.imread(r"C:\Users\DELL\Desktop\download.jpg")
plt.imshow(img)
The output I am getting is :
TypeError Traceback (most recent call last)
<ipython-input-24-639b020df6f2> in <module>()
1 img = cv2.imread(r"C:\Users\DELL\Desktop\download.jpg")
----> 2 plt.imshow(img)
5 frames
/usr/local/lib/python3.7/dist-packages/matplotlib/image.py in set_data(self, A)
692 not np.can_cast(self._A.dtype, float, "same_kind")):
693 raise TypeError("Image data of dtype {} cannot be converted to "
--> 694 "float".format(self._A.dtype))
695
696 if not (self._A.ndim == 2
TypeError: Image data of dtype object cannot be converted to float

OpenCV TextReconitionModel failed with CTC-prefix-beam-search

usage:
OpenCV 4.5.3-dev
I followed this example: https://github.com/opencv/opencv/blob/master/samples/dnn/scene_text_spotting.cpp
It is use:
for the detection model: DB_TD500_resnet50.onnx
for the recognition model : crnn_cs.onnx
for the vocabulary: alphabet_94.txt
the decode type is set to: "CTC-prefix-beam-search"
These settings received the following error:
OpenCV(4.5.3-dev) C:\DevTools\opencv\modules\dnn\src\model.cpp:745: error: (-2:Unspecified error) in function 'class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > __cdecl cv::dnn::TextRecognitionModel_Impl::ctcPrefixBeamSearchDecode(const class cv::Mat &)'
> (expected: 'prediction.size[2] == (int)vocabulary.size() + 1'), where
> 'prediction.size[2]' is 96
> must be equal to
> '(int)vocabulary.size() + 1' is 95
Add one empty line at the end of the vocabulary or push_back one more item in the vocabulary vector.
I don't know if is only a workaround or a real solution...

AttributeError 'NoneType' object has no attribute 'shape'

I am trying to add random noise to images. When I try to print the shape of the image, it seem to print correctly but, there is this error which says "'NoneType' object has no attribue 'shape'"
Platform: Ubuntu 16.04;
Python ver.: 3.7.3;
Opencv ver: 4.1.0
def rand_noise(image,prob):
print("Check",image.shape)
output = np.zeros(image.shape,np.uint8)
thres = 1 - prob
for i in range(image.shape[0]):
for j in range(image.shape[1]):
rdn = random.random()
if rdn < prob:
output[i][j] = 0
elif rdn > thres:
output[i][j] = 255
else:
output[i][j] = image[i][j]
return output
On removing the print function, the same error is shown for the next line.
This is the error message:
Check (720, 1280, 3)
Traceback (most recent call last):
File "noise&blur.py", line 71, in <module>
noise_imgR = sp_noise(imageR,0.005)
File "noise&blur.py", line 11, in sp_noise
print("Check",image.shape)
AttributeError: 'NoneType' object has no attribute 'shape'

when i tried show 2 image together using opencv

import cv2
import numpy as np,sys
img1 = cv2.imread('Pictures/orange.jpg')
img2 = cv2.imread('pictures/orange.jpg')
cv2.imshow('apple', img1)
cv2.imshow('orange', img2)
cv2.waitKey(0)
cv2.destroyAllWindows()
when i try to run this code.
error Traceback (most recent call last)
in ()
6
7 cv2.imshow('apple', img1)
----> 8 cv2.imshow('orange', img2)
9 cv2.waitKey(0)
10
error: OpenCV(3.4.1) /io/opencv/modules/highgui/src/window.cpp:356: error: (-215) size.width>0 && size.height>0 in function imshow
i am getting this error.

OpenCL Theano - How to forcefully disable CUDA?

After a series of pains, I have installed Theano on a machine with AMD graphics card - Radeon HD 5450 (Cedar).
Now, consider a following code.
import numpy
import theano
import theano.tensor as T
rng = numpy.random
N = 400 #number of samples
feats = 784 #dimensionality of features
D = (rng.randn(N, feats), rng.randint(size=N, low=0, high=2))
training_steps = 10000
# theano symbolic variables
x = T.matrix("x")
y = T.vector("y")
w = theano.shared(rng.randn(784), name="w")
b = theano.shared(0., name="b")
print("Initial Model:")
print(str(w.get_value()) + " " + str(b.get_value()) )
p_1 = 1/(1 + T.exp(-T.dot(x, w) - b)) # probability of target being 1
prediction = p_1 > 0.5 # prediction threshold
xent = -y * T.log(p_1) - (1-y)*T.log(1-p_1) # cross-entropy loss function
cost = xent.mean() + 0.01 * (w**2).sum() # cost - to be minimized
gw, gb = T.grad(cost, [w, b])
#compile it
train = theano.function(
inputs = [x, y],
outputs = [prediction, xent],
updates = {w: w - 0.1*gw, b: b - 0.1*gb} )
predict = theano.function(inputs = [x], outputs = prediction)
#train it
for i in range (training_steps):
pred, err = train(D[0], D[1])
print("Final Model: ")
print(str(w.get_value()) + " " + str(b.get_value()) )
print("Target values for D: " + str(D[1]))
print("Predictions on D: " + str(D[0]))
I think this code should work just fine. But I get a series of errors:
ERROR (theano.gof.opt): Optimization failure due to: local_gpua_hgemm
ERROR (theano.gof.opt): node: dot(x.T, Elemwise{sub,no_inplace}.0)
ERROR (theano.gof.opt): TRACEBACK:
ERROR (theano.gof.opt): Traceback (most recent call last):
File "/home/user/anaconda3/lib/python3.5/site-packages/theano/gof/opt.py", line 1772, in process_node
replacements = lopt.transform(node)
File "/home/user/anaconda3/lib/python3.5/site-packages/theano/sandbox/gpuarray/opt.py", line 140, in local_opt
new_op = maker(node, context_name)
File "/home/user/anaconda3/lib/python3.5/site-packages/theano/sandbox/gpuarray/opt.py", line 732, in local_gpua_hgemm
if nvcc_compiler.nvcc_version < '7.5':
TypeError: unorderable types: NoneType() < str()
And I get the same set of messages multiple times. Then at the end:
File "/home/user/anaconda3/lib/python3.5/site-packages/pygpu-0.2.1-py3.5-linux-x86_64.egg/pygpu/elemwise.py", line 286, in __init__
**self.flags)
File "pygpu/gpuarray.pyx", line 1950, in pygpu.gpuarray.GpuKernel.__cinit__ (pygpu/gpuarray.c:24214)
File "pygpu/gpuarray.pyx", line 467, in pygpu.gpuarray.kernel_init (pygpu/gpuarray.c:7174)
pygpu.gpuarray.UnsupportedException: ('The following error happened while compiling the node', GpuElemwise{Composite{((-i0) - i1)}}[(0, 0)]<gpuarray>(GpuFromHost<None>.0, InplaceGpuDimShuffle{x}.0), '\n', b'Device does not support operation')
Does this mean I cannot use this GPU or I have done something wrong in my code. Moreover, from the errors, it seems there is been a search for nvcc. But I do not have CUDA, I have opencl.
>>> import theano
Mapped name None to device opencl0:0: Cedar
also:
>>> from theano import config
>>> config.device
'opencl0:0'
>>> config.cuda
<theano.configparser.AddConfigVar.<locals>.SubObj object at 0x7fba9dee7d30>
>>> config.nvcc
<theano.configparser.AddConfigVar.<locals>.SubObj object at 0x7fba9e5967f0>
>>> config.gpu
<theano.configparser.AddConfigVar.<locals>.SubObj object at 0x7fbaa9f61828>
So how do I go from here? Is there way to make sure clcc is searched instead of nvcc.
PS_1: hello world works.
PS_2: System = 14.04 64 bit
OpenCL is not yet supported by Theano. As a result, only NVIDIA GPUs are supported.
The status of OpenCL is recorded on GitHub.
You need to disable GPU operation by setting device=cpu in your Theano config. There are multiple ways to do this (i.e. via THEANO_FLAGS environment variable or via a .theanorc file; see documentation).
Before running the script, try setting
export THEANO_FLAGS=device=cpu,floatX=float64
Your situation may need additional configuration options. See the documentation for more.

Resources