I am trying to use vtkImageStencil in python.
I am using the standard pip package "vtk 8.1.1"
import vtk
stencil = vtk.vtkImageStencil
image = vtk.vtkImageData()
stencil.SetInputData( image )
I am getting the following error:
Traceback (most recent call last):
File "<ipython-input-89-52c6c4badec2>", line 1, in <module>
stencil.SetInputData( image )
TypeError: no overloads of SetInputData() take 0 arguments
This does not make sense to me. Am I passing the wrong type?
Is there a workaround?
Stupid mistake, do not forget the parentheses when creating an object.
Change the example to:
stencil = vtk.vtkImageStencil()
This happens, when converting c++ code to python code.
Related
When I call the OpenCV Structured Forests Edge Detection in Python as shown below, I get an error:
import numpy as np
import cv2
img = cv2.imread('2009_005193.jpg')
gray_img = np.asarray(img.mean(axis=2) / 255, np.float32)
out = cv2.ximgproc_StructuredEdgeDetection.detectEdges(gray_img)
The error I get is:
Traceback (most recent call last):
File "gop1.py", line 19, in <module>
out = cv2.ximgproc_StructuredEdgeDetection.detectEdges(gray_img)
TypeError: descriptor 'detectEdges' requires a 'cv2.ximgproc_StructuredEdgeDetection' object but received a 'numpy.ndarray'
In the documentation (link to documentation), it is present under ximgproc_StructuredEdgeDetection, as a function detectEdges().
As in the documentation, it will require 3-channel float 32 image. Perhaps you need to create the StructuredEdgeDetection Object first.
However, this worked for me:
imgrgb=cv2.cvtColor(img,cv2.COLOR_BGR2RGB)/255
imgrgb=imgrgb.astype(np.float32)
model='structured edge/model.yml'
retval=cv2.ximgproc.createStructuredEdgeDetection(model)
out=retval.detectEdges(imgrgb)
I tried to add a new node following the example but:
myitems = ruamel.yaml.load(inp, ruamel.yaml.RoundTripLoader)
myitems['abc'].append('test')
gives me an error:
Traceback (most recent call last):
File "item_updater.py", line 148, in <module>
myitems['wohnung'].append('test')
AttributeError: 'CommentedMap' object has no attribute 'append'
I am using ruamel.yaml v0.13.7
What am I doing wrong?
Your error doesn't come from the example you indicated, as in the inp of the example there is no wohnung that shows up in your error.
You probably forgot a - somewhere:
wohnung:
a: 1
instead of:
wohnung:
- a: 1
only on the latter you can append using myitems['wohnung'].append('test').
The example works, but without showing your real YAML input it is difficult to see what is the exact cause of your error.
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).
I currently am trying to use
paraview.simple.Histogram(Input, params)
as
paraview.simple.Histogram(q, BinCount = 30)
in the shell where q is a variable data set from my "out.e" ExodusII file. I'm getting the error
Traceback (most recent call last):
File "<console>", line 1, in <module>
NameError: name 'q' is not defined
I've tried to search the literature on python shell scripting in Paraview but it seems to be eluding me. I know this is a quick fix. Thanks
Try this instead:
Histogram(SelectInputArray="q", BinCount=30)
This assumes you currently have the reader as the active object in the Pipeline browser.
I was able to answer this problem using the following.
outset = Reader(FileName=['/dir/out.e'])
and for the Histogram
histogram1_1 = Histogram(Input=outset)
histogram1_1.SelectInputArray = ['CELLS', 'q']
histogram1_1.BinCount = 30
Note for anyone who comes into this issue, the TRACE option in the Python Shell will build a script for you when you do anything in the GUI.
I have a problem with using DLL function in python.
I looked the name of function by dint of "dumpbin".
For example
_xGraphics3D#20
I tried to call the function like this:
from ctypes import *
xorsLib = cdll.LoadLibrary("Xors3D.dll")
width = c_int(800)
height = c_int(600)
depth = c_int(32)
mode = c_int(0)
vsync = c_int(0)
xGraphics3D = getattr(xorsLib,"_xGraphics3D#20")
xGraphics3D(width, height, depth, mode, vsync)
but it's cause the error:
Traceback (most recent call last):
File "D:/Coding/Python/pyASG/main", line 11, in <module>
xGraphics3D(width, height, depth, mode, vsync)
ValueError: Procedure called with not enough arguments (20 bytes missing) or wrong calling convention
what am i doing wrong?
p.s. i haven't know python, but i learn it. i read ctype-manual and tried to find answer...
p.p.s sorry for my awful english.
Try use windll instead of cdll.
xorsLib = windll.LoadLibrary("xors3d.dll")
http://docs.python.org/release/3.1.5/library/ctypes.html
The reason is the same as martineau commented.