python rotate an image around an axis - python

I thought I had found the solution to my probelm (and the code) fro Idan:
MoviePy + Vapory code
from moviepy.editor import concatenate, ImageClip, VideoClip
from vapory import *
img_path = "E:/Programming/Python/coffee.png"
img_clip = ImageClip(img_path)
W, H = img_clip.w, img_clip.h
AR = 1.0*W/H
t_rev = 2.0
t_half = t_rev/2.0 # The time required for a half revolution
t_still = 0.8 # How long (in seconds) to hold the half rotated image still
cam = Camera('location', [ 0, 0, -1],
'look_at', [ 0, 0, 0])
light = LightSource([0, 0, -1]) # Light at camera location
bg = Background('color', [0, 0, 0]) # Black background
def scene(t):
""" Returns the scene at time 't' (in seconds) """
s = Scene(camera = cam, objects = [light, bg])
s = s.add_objects([
Box([0, 0, 0],
[W, H, 0],
Texture(Pigment(ImageMap('"{}"'.format(img_path), 'once')),
Finish('ambient', 1.0)),
'translate', [-0.5, -0.5, 0],
'scale', [AR, 1, 0],
'rotate', [0, (360/t_rev)*t, 0])])
return s
def make_frame(t):
return scene(t).render(width=W, height=H, antialiasing=0.1)
still_1 = VideoClip(make_frame).to_ImageClip(t=0).set_duration(t_still)
half_1 = VideoClip(make_frame).subclip(0, t_half)
still_2 = VideoClip(make_frame).to_ImageClip(t=t_half).set_duration(t_still)
half_2 = VideoClip(make_frame).subclip(t_half, t_rev)
final_clip = concatenate([still_1, half_1, still_2, half_2])
final_clip.write_gif("E:/Programming/Python/coffee_rot.gif", fps=15)
BUT when I try to run it with Python 3.6 I get (full traceback):
Hope this makes things clearer
Traceback (most recent call last):
File "C:\Users\Us\AppData\Local\Programs\Python\Python36\test2a.py", line 44, in <module>
still_1 = VideoClip(make_frame).to_ImageClip(t=0).set_duration(t_still)
File "C:\Users\Us\AppData\Local\Programs\Python\Python36\lib\site-packages\moviepy\video\VideoClip.py", line 86, in __init__
self.size = self.get_frame(0).shape[:2][::-1]
File "<decorator-gen-10>", line 2, in get_frame
File "C:\Users\Us\AppData\Local\Programs\Python\Python36\lib\site-packages\moviepy\decorators.py", line 89, in wrapper
return f(*new_a, **new_kw)
File "C:\Users\Us\AppData\Local\Programs\Python\Python36\lib\site-packages\moviepy\Clip.py", line 94, in get_frame
return self.make_frame(t)
File "C:\Users\Us\AppData\Local\Programs\Python\Python36\test2a.py", line 41, in make_frame
return scene(t).render(width=W, height=H, antialiasing=0.1)
File "C:\Users\Us\AppData\Local\Programs\Python\Python36\lib\site-packages\vapory\vapory.py", line 102, in render
quality, antialiasing, remove_temp)
File "C:\Users\Us\AppData\Local\Programs\Python\Python36\lib\site-packages\vapory\io.py", line 106, in render_povstring
stdout=subprocess.PIPE)
File "C:\Users\Us\AppData\Local\Programs\Python\Python36\lib\subprocess.py", line 710, in __init__
restore_signals, start_new_session)
File "C:\Users\Us\AppData\Local\Programs\Python\Python36\lib\subprocess.py", line 998, in _execute_child
startupinfo)
FileNotFoundError: [WinError 2] The system cannot find the file specified
Searches find similar errors but none relevant to my situation. Help much appreciated. Idan are you still there?
Could comment re windows file paths be expanded a little?

Related

How to retrieve conflicting location in shapely TopologicalError?

When trying to plot a 2D array in cartopy projected axes using contourf, I am receiving a TopologicalError. This is the code:
import cartopy.crs as ccrs
import matplotlib.pyplot as plt
import numpy as np
from shapely.geos import TopologicalError
data = np.array(
[[ 8, 10, 2, 5, 3, 6, 5, 3, 0, 0, 0, 0, 0, 0, 0],
[ 7, 5, 3, 6, 5, 4, 2, 1, 1, 0, 0, 0, 0, 0, 0],
[ 8, 10, 2, 7, 1, 2, 1, 0, 0, 1, 0, 0, 0, 0, 0],
[14, 8, 12, 9, 3, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0],
[15, 8, 10, 5, 2, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0],
[ 7, 7, 9, 5, 2, 2, 1, 0, 0, 0, 0, 0, 0, 0, 0],
[ 4, 5, 1, 2, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0],
[ 2, 4, 1, 3, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
[ 2, 0, 0, 1, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
[ 0, 0, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
])
x = np.array([-9.05365, -9.05266, -9.05167, -9.05068, -9.04969,
-9.0487, -9.04771, -9.04672, -9.04573, -9.04474,
-9.04375, -9.04276, -9.04177, -9.04078, -9.03979])
y = np.array([53.2024, 53.203, 53.2036, 53.2042, 53.2048,
53.2054, 53.206, 53.2065, 53.2071, 53.2077])
data = np.ma.masked_where(data==0, data)
ax = plt.axes(projection=ccrs.Mercator(central_longitude=-9))
try:
ax.contourf(x, y, data, transform=ccrs.PlateCarree())
except TopologicalError as exc:
pass # Do something to get the conflicting location (x, y)
When running this code, I am getting the TopologyException message below, followed by a rather long traceback (see below). The TopologyException is:
TopologyException: side location conflict at -9.0506799999999998 53.206000000000003
Now, under the except block, I would like to fix the array in the location indicated by the TopologyException (-9.0506799999999998 53.206000000000003), and try to plot it again. I would use a while loop to fix the array as many times as needed, retrieving the conflicting location and fixing the array at that location. I have to repeat this procedure for many other arrays like this.
Even though the message is displayed in the screen, I don't know how to get the location -9.0506799999999998 53.206000000000003 from the script, since I can't find it in exc. I would be very grateful if somebody could explain how to get those numbers as new variables lon and lat.
This error can be avoided if not using a masked array, but I am masking the 0's because I don't want to plot them.
Below is the traceback. Many thanks.
TopologyException: side location conflict at -9.0506799999999998 53.206000000000003
TopologyException: side location conflict at -9.0506799999999998 53.206000000000003
Error in callback <function install_repl_displayhook.<locals>.post_execute at 0x00000204E9F74280> (for post_execute):
Traceback (most recent call last):
File "C:\Users\dpereiro\Miniconda3\envs\opendrift\lib\site-packages\shapely\predicates.py", line 15, in __call__
return self.fn(this._geom, other._geom, *args)
File "C:\Users\dpereiro\Miniconda3\envs\opendrift\lib\site-packages\shapely\geos.py", line 584, in errcheck_predicate
raise PredicateError("Failed to evaluate %s" % repr(func))
PredicateError: Failed to evaluate <_FuncPtr object at 0x00000204EB13ED40>
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "C:\Users\dpereiro\Miniconda3\envs\opendrift\lib\site-packages\matplotlib\pyplot.py", line 139, in post_execute
draw_all()
File "C:\Users\dpereiro\Miniconda3\envs\opendrift\lib\site-packages\matplotlib\_pylab_helpers.py", line 137, in draw_all
manager.canvas.draw_idle()
File "C:\Users\dpereiro\Miniconda3\envs\opendrift\lib\site-packages\matplotlib\backend_bases.py", line 2055, in draw_idle
self.draw(*args, **kwargs)
File "C:\Users\dpereiro\Miniconda3\envs\opendrift\lib\site-packages\matplotlib\backends\backend_agg.py", line 406, in draw
self.figure.draw(self.renderer)
File "C:\Users\dpereiro\Miniconda3\envs\opendrift\lib\site-packages\matplotlib\artist.py", line 74, in draw_wrapper
result = draw(artist, renderer, *args, **kwargs)
File "C:\Users\dpereiro\Miniconda3\envs\opendrift\lib\site-packages\matplotlib\artist.py", line 51, in draw_wrapper
return draw(artist, renderer, *args, **kwargs)
File "C:\Users\dpereiro\Miniconda3\envs\opendrift\lib\site-packages\matplotlib\figure.py", line 2790, in draw
mimage._draw_list_compositing_images(
File "C:\Users\dpereiro\Miniconda3\envs\opendrift\lib\site-packages\matplotlib\image.py", line 132, in _draw_list_compositing_images
a.draw(renderer)
File "C:\Users\dpereiro\Miniconda3\envs\opendrift\lib\site-packages\matplotlib\artist.py", line 51, in draw_wrapper
return draw(artist, renderer, *args, **kwargs)
File "C:\Users\dpereiro\Miniconda3\envs\opendrift\lib\site-packages\cartopy\mpl\geoaxes.py", line 558, in draw
return matplotlib.axes.Axes.draw(self, renderer=renderer, **kwargs)
File "C:\Users\dpereiro\Miniconda3\envs\opendrift\lib\site-packages\matplotlib\artist.py", line 51, in draw_wrapper
return draw(artist, renderer, *args, **kwargs)
File "C:\Users\dpereiro\Miniconda3\envs\opendrift\lib\site-packages\matplotlib\_api\deprecation.py", line 431, in wrapper
return func(*inner_args, **inner_kwargs)
File "C:\Users\dpereiro\Miniconda3\envs\opendrift\lib\site-packages\matplotlib\axes\_base.py", line 2921, in draw
mimage._draw_list_compositing_images(renderer, self, artists)
File "C:\Users\dpereiro\Miniconda3\envs\opendrift\lib\site-packages\matplotlib\image.py", line 132, in _draw_list_compositing_images
a.draw(renderer)
File "C:\Users\dpereiro\Miniconda3\envs\opendrift\lib\site-packages\matplotlib\artist.py", line 51, in draw_wrapper
return draw(artist, renderer, *args, **kwargs)
File "C:\Users\dpereiro\Miniconda3\envs\opendrift\lib\site-packages\matplotlib\collections.py", line 1012, in draw
super().draw(renderer)
File "C:\Users\dpereiro\Miniconda3\envs\opendrift\lib\site-packages\matplotlib\artist.py", line 51, in draw_wrapper
return draw(artist, renderer, *args, **kwargs)
File "C:\Users\dpereiro\Miniconda3\envs\opendrift\lib\site-packages\matplotlib\collections.py", line 352, in draw
transform, transOffset, offsets, paths = self._prepare_points()
File "C:\Users\dpereiro\Miniconda3\envs\opendrift\lib\site-packages\matplotlib\collections.py", line 329, in _prepare_points
paths = [transform.transform_path_non_affine(path)
File "C:\Users\dpereiro\Miniconda3\envs\opendrift\lib\site-packages\matplotlib\collections.py", line 329, in <listcomp>
paths = [transform.transform_path_non_affine(path)
File "C:\Users\dpereiro\Miniconda3\envs\opendrift\lib\site-packages\matplotlib\transforms.py", line 2396, in transform_path_non_affine
return self._a.transform_path_non_affine(path)
File "C:\Users\dpereiro\Miniconda3\envs\opendrift\lib\site-packages\cartopy\mpl\geoaxes.py", line 186, in transform_path_non_affine
geoms = cpatch.path_to_geos(src_path,
File "C:\Users\dpereiro\Miniconda3\envs\opendrift\lib\site-packages\cartopy\mpl\patch.py", line 178, in path_to_geos
collection[-1][0].contains(geom.exterior)):
File "C:\Users\dpereiro\Miniconda3\envs\opendrift\lib\site-packages\shapely\geometry\base.py", line 747, in contains
return bool(self.impl['contains'](self, other))
File "C:\Users\dpereiro\Miniconda3\envs\opendrift\lib\site-packages\shapely\predicates.py", line 18, in __call__
self._check_topology(err, this, other)
File "C:\Users\dpereiro\Miniconda3\envs\opendrift\lib\site-packages\shapely\topology.py", line 35, in _check_topology
raise TopologicalError(
TopologicalError: The operation 'GEOSContains_r' could not be performed. Likely cause is invalidity of the geometry <shapely.geometry.polygon.Polygon object at 0x000002048290D820>
TopologyException: side location conflict at -9.0506799999999998 53.206000000000003
Traceback (most recent call last):
File "C:\Users\dpereiro\Miniconda3\envs\opendrift\lib\site-packages\shapely\predicates.py", line 15, in __call__
return self.fn(this._geom, other._geom, *args)
File "C:\Users\dpereiro\Miniconda3\envs\opendrift\lib\site-packages\shapely\geos.py", line 584, in errcheck_predicate
raise PredicateError("Failed to evaluate %s" % repr(func))
PredicateError: Failed to evaluate <_FuncPtr object at 0x00000204EB13ED40>
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "C:\Users\dpereiro\Miniconda3\envs\opendrift\lib\site-packages\IPython\core\formatters.py", line 341, in __call__
return printer(obj)
File "C:\Users\dpereiro\Miniconda3\envs\opendrift\lib\site-packages\IPython\core\pylabtools.py", line 253, in <lambda>
png_formatter.for_type(Figure, lambda fig: print_figure(fig, 'png', **kwargs))
File "C:\Users\dpereiro\Miniconda3\envs\opendrift\lib\site-packages\IPython\core\pylabtools.py", line 137, in print_figure
fig.canvas.print_figure(bytes_io, **kw)
File "C:\Users\dpereiro\Miniconda3\envs\opendrift\lib\site-packages\matplotlib\backend_bases.py", line 2230, in print_figure
self.figure.draw(renderer)
File "C:\Users\dpereiro\Miniconda3\envs\opendrift\lib\site-packages\matplotlib\artist.py", line 74, in draw_wrapper
result = draw(artist, renderer, *args, **kwargs)
File "C:\Users\dpereiro\Miniconda3\envs\opendrift\lib\site-packages\matplotlib\artist.py", line 51, in draw_wrapper
return draw(artist, renderer, *args, **kwargs)
File "C:\Users\dpereiro\Miniconda3\envs\opendrift\lib\site-packages\matplotlib\figure.py", line 2790, in draw
mimage._draw_list_compositing_images(
File "C:\Users\dpereiro\Miniconda3\envs\opendrift\lib\site-packages\matplotlib\image.py", line 132, in _draw_list_compositing_images
a.draw(renderer)
File "C:\Users\dpereiro\Miniconda3\envs\opendrift\lib\site-packages\matplotlib\artist.py", line 51, in draw_wrapper
return draw(artist, renderer, *args, **kwargs)
File "C:\Users\dpereiro\Miniconda3\envs\opendrift\lib\site-packages\cartopy\mpl\geoaxes.py", line 558, in draw
return matplotlib.axes.Axes.draw(self, renderer=renderer, **kwargs)
File "C:\Users\dpereiro\Miniconda3\envs\opendrift\lib\site-packages\matplotlib\artist.py", line 51, in draw_wrapper
return draw(artist, renderer, *args, **kwargs)
File "C:\Users\dpereiro\Miniconda3\envs\opendrift\lib\site-packages\matplotlib\_api\deprecation.py", line 431, in wrapper
return func(*inner_args, **inner_kwargs)
File "C:\Users\dpereiro\Miniconda3\envs\opendrift\lib\site-packages\matplotlib\axes\_base.py", line 2921, in draw
mimage._draw_list_compositing_images(renderer, self, artists)
File "C:\Users\dpereiro\Miniconda3\envs\opendrift\lib\site-packages\matplotlib\image.py", line 132, in _draw_list_compositing_images
a.draw(renderer)
File "C:\Users\dpereiro\Miniconda3\envs\opendrift\lib\site-packages\matplotlib\artist.py", line 51, in draw_wrapper
return draw(artist, renderer, *args, **kwargs)
File "C:\Users\dpereiro\Miniconda3\envs\opendrift\lib\site-packages\matplotlib\collections.py", line 1012, in draw
super().draw(renderer)
File "C:\Users\dpereiro\Miniconda3\envs\opendrift\lib\site-packages\matplotlib\artist.py", line 51, in draw_wrapper
return draw(artist, renderer, *args, **kwargs)
File "C:\Users\dpereiro\Miniconda3\envs\opendrift\lib\site-packages\matplotlib\collections.py", line 352, in draw
transform, transOffset, offsets, paths = self._prepare_points()
File "C:\Users\dpereiro\Miniconda3\envs\opendrift\lib\site-packages\matplotlib\collections.py", line 329, in _prepare_points
paths = [transform.transform_path_non_affine(path)
File "C:\Users\dpereiro\Miniconda3\envs\opendrift\lib\site-packages\matplotlib\collections.py", line 329, in <listcomp>
paths = [transform.transform_path_non_affine(path)
File "C:\Users\dpereiro\Miniconda3\envs\opendrift\lib\site-packages\matplotlib\transforms.py", line 2396, in transform_path_non_affine
return self._a.transform_path_non_affine(path)
File "C:\Users\dpereiro\Miniconda3\envs\opendrift\lib\site-packages\cartopy\mpl\geoaxes.py", line 186, in transform_path_non_affine
geoms = cpatch.path_to_geos(src_path,
File "C:\Users\dpereiro\Miniconda3\envs\opendrift\lib\site-packages\cartopy\mpl\patch.py", line 178, in path_to_geos
collection[-1][0].contains(geom.exterior)):
File "C:\Users\dpereiro\Miniconda3\envs\opendrift\lib\site-packages\shapely\geometry\base.py", line 747, in contains
return bool(self.impl['contains'](self, other))
File "C:\Users\dpereiro\Miniconda3\envs\opendrift\lib\site-packages\shapely\predicates.py", line 18, in __call__
self._check_topology(err, this, other)
File "C:\Users\dpereiro\Miniconda3\envs\opendrift\lib\site-packages\shapely\topology.py", line 35, in _check_topology
raise TopologicalError(
TopologicalError: The operation 'GEOSContains_r' could not be performed. Likely cause is invalidity of the geometry <shapely.geometry.polygon.Polygon object at 0x00000204E87FDD90>
<Figure size 432x288 with 1 Axes>

Keep getting this same error with my code - TypeError: 'float' object cannot be interpreted as an integer

Have a section of code, but it says that my float can't be interpreted as an integer, i don't know how to change this though - anyone have an idea?
import numpy as np
import matplotlib.pyplot as plt
from pandas import DataFrame # to build our table of data from the video. import glob import pims # to import the video. from pims import pipeline # a decorator to allow dynamic loading of videos
import scipy.ndimage as nd # for Gaussian filter.
import trackpy as tp # for object tracking functions.
crop = (slice(100, 1000), slice(500, 1250), 0)
thresh = 130
x = glob.glob('/Users/charlieargent/Extended Report /Potassium nitrate 1 hour//')
def readvid(x):
frames = pims.Video(x)
return(frames)
#pipeline
def crop_frame(frame):
return frame[crop]
#pipeline
def filter_frame(frame):
return nd.filters.gaussian_filter( crop_frame(frame), [2, 2] )
#pipeline
def binary_inv_frame(frame):
return ( (255 - filter_frame(frame) > thresh)*255 ).astype('uint8')
for i in x:
find_cells = tp.batch( binary_inv_frame(readvid(i)), 21, minmass = 200, invert = False )
tracks = tp.link_df( find_cells, 25, memory = 0 )
tracks_long = tp.filter_stubs( tracks, 5 )
msds = tp.imsd( tracks_long, 1, 25 )
y = i.split("/")[-3], i.split("/")[-2], i.split("/")[-1]
msds.to_csv("{}.csv".format(y))
Error:
File "", line 1, in
runfile('/Users/charlieargent/Extended Report /Analysis/untitled1.py', wdir='/Users/charlieargent/Extended Report /Analysis')
File "/anaconda3/lib/python3.7/site-packages/spyder_kernels/customize/spydercustomize.py", line 786, in runfile
execfile(filename, namespace)
File "/anaconda3/lib/python3.7/site-packages/spyder_kernels/customize/spydercustomize.py", line 110, in execfile
exec(compile(f.read(), filename, 'exec'), namespace)
File "/Users/charlieargent/Extended Report /Analysis/untitled1.py", line 45, in
find_cells = tp.batch( binary_inv_frame(readvid(i)), 21, minmass = 200, invert = False )
File "/anaconda3/lib/python3.7/site-packages/slicerator/init.py", line 687, in process
return Pipeline(proc_func, *ancestors)
File "/anaconda3/lib/python3.7/site-packages/slicerator/init.py", line 415, in init
self._len = len(ancestors[0])
TypeError: 'float' object cannot be interpreted as an integer

OSError: [Errno 9] Bad file descriptor while saving image with PIL

i amusing PIL to write some text inside and an image and then saving it at the same location. Following is my function which does this
from PIL import Image
from PIL import ImageFont
from PIL import ImageDraw
def add_text_to_image(image_path):
img = Image.open(image_path)
img = img.convert('RGB')
widht, height = img.size
draw = ImageDraw.Draw(img)
font = ImageFont.truetype("helvetica.ttf", 20)
draw.text((0, 0), "Some text", (0, 0, 0), font=font)
img.save(image_path)
But i am getting following error.
Traceback (most recent call last): File
"/usr/local/lib/python3.6/site-packages/background_task/tasks.py",
line 43, in bg_runner func(*args, **kwargs) File
"/home/paksign/app/app/document/tasks.py", line 74, in
document_status_changed_to_completed
add_branding_texts_to_document_images(meta) File
"/home/paksign/app/app/document/utils.py", line 277, in
add_branding_texts_to_document_images for snapshot in snapshots: File
"/home/paksign/app/app/document/utils.py", line 270, in
add_text_to_image img.save(image_path) File
"/usr/local/lib/python3.6/site-packages/PIL/Image.py", line 1994, in
save save_handler(self, fp, filename) File
"/usr/local/lib/python3.6/site-packages/PIL/JpegImagePlugin.py", line
761, in _save ImageFile._save(im, fp, [("jpeg", (0, 0)+im.size, 0,
rawmode)], bufsize) File
"/usr/local/lib/python3.6/site-packages/PIL/ImageFile.py", line 519,
in _save s = e.encode_to_file(fh, bufsize) OSError: [Errno 9] Bad file
descriptor Marking task
document.tasks.document_status_changed_to_completed as failed
i have tried some solution from internet but nothing is working and i don't know what i am doing wrong here. any help is appreciated

IOError: broken data stream when reading image file

This is the code(a simple python code which could add a number to a picture):
from PIL import Image, ImageDraw, ImageFont
def addnum(number, filepath):
img = Image.open(filepath)
width, height = img.size
draw = ImageDraw.Draw(img)
front_size = height/4
ttf_front = ImageFont.truetype('Arial.ttf', front_size)
draw.text((width - front_size, 0), number, (255, 0, 0), font = ttf_front)
del draw
img.save('wechat_addnum.jpg')
img.show()
if __name__ == '__main__':
addnum('4','wechat.jpg')
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/Users/JourneyWoo/anaconda/lib/python2.7/site-packages/spyder/utils/site/sitecustomize.py", line 866, in runfile
execfile(filename, namespace)
File "/Users/JourneyWoo/anaconda/lib/python2.7/site-packages/spyder/utils/site/sitecustomize.py", line 94, in execfile
builtins.execfile(filename, *where)
File "/Users/JourneyWoo/Python/python100/python001/python000.py", line 27, in <module>
addnum('4','wechat.jpg')
File "/Users/JourneyWoo/Python/python100/python001/python000.py", line 16, in addnum
draw = ImageDraw.Draw(img)
File "/Users/JourneyWoo/anaconda/lib/python2.7/site-packages/PIL/ImageDraw.py", line 299, in Draw
return ImageDraw(im, mode)
File "/Users/JourneyWoo/anaconda/lib/python2.7/site-packages/PIL/ImageDraw.py", line 60, in __init__
im.load()
File "/Users/JourneyWoo/anaconda/lib/python2.7/site-packages/PIL/ImageFile.py", line 244, in load
raise_ioerror(err_code)
File "/Users/JourneyWoo/anaconda/lib/python2.7/site-packages/PIL/ImageFile.py", line 59, in raise_ioerror
raise IOError(message + " when reading image file")
IOError: broken data stream when reading image file
I don't know the real problem, and from the google and other questions from stackoverflow I cannot find the method which could solve this problem.
Thank you!!
This is a know issue. Try to update Pillow using pip install Pillow --upgrade

TypeError: dst is not a numpy array, neither a scalar

I use anaconda2 in python script, but it showed me these error information:
Traceback (most recent call last):
File "main.py", line 16, in <module>
clip = source.fl_image(lane_detector.run)
File "E:\Anaconda2\Lib\site-packages\moviepy\video\VideoClip.py", line 533, in fl_image
return self.fl(lambda gf, t: image_func(gf(t)), apply_to)
File "E:\Anaconda2\Lib\site-packages\moviepy\Clip.py", line 136, in fl
newclip = self.set_make_frame(lambda t: fun(self.get_frame, t))
File "<decorator-gen-57>", line 2, in set_make_frame
File "E:\Anaconda2\Lib\site-packages\moviepy\decorators.py", line 14, in outpl ace
f(newclip, *a, **k)
File "E:\Anaconda2\Lib\site-packages\moviepy\video\VideoClip.py", line 694, in set_make_frame
self.size = self.get_frame(0).shape[:2][::-1]
File "<decorator-gen-14>", line 2, in get_frame
File "E:\Anaconda2\Lib\site-packages\moviepy\decorators.py", line 89, in wrapp er
return f(*new_a, **new_kw)
File "E:\Anaconda2\Lib\site-packages\moviepy\Clip.py", line 95, in get_frame
return self.make_frame(t)
File "E:\Anaconda2\Lib\site-packages\moviepy\Clip.py", line 136, in <lambda>
newclip = self.set_make_frame(lambda t: fun(self.get_frame, t))
File "E:\Anaconda2\Lib\site-packages\moviepy\video\VideoClip.py", line 533, in <lambda>
return self.fl(lambda gf, t: image_func(gf(t)), apply_to)
File "C:\Users\shihaohou\Desktop\lane-line-detection-master\detector.py", line 655, in run
warped = self.__perspective_transform(preprocessed,pers_mat)
File "C:\Users\shihaohou\Desktop\lane-line-detection-master\detector.py", line 328, in __perspective_transform
warped = cv2.warpPerspective(img, mat, img_size, cv2.INTER_LINEAR)
TypeError: dst is not a numpy array, neither a scalar
The relative code in detetor.py is :
def __perspective_transform(self, img, mat):
'''
Method to transform the image
:param img: the image to be transformed
:param mat: the perspective matrix
:return: the transformed image
'''
img_size = (img.shape[1], img.shape[0])
warped = cv2.warpPerspective(img, mat, img_size, cv2.INTER_LINEAR)
return warped
if self.ENABLE_LOGS:
cv2.imwrite('./test/def_' + str(self.processed_frames) + '.jpg', img)
# undistort the image using the calibrated values
undistorted = self.__undistort(img,self.mtx, self.dist)
# pass the distortion corrected image through the threshold pipeline
preprocessed = self.__prepocess(undistorted)
if self.ENABLE_LOGS:
cv2.imwrite('./debug/preprocessed_' + str(self.processed_frames) + '.jpg', img)
# get the current region of interest and load the perspective and inverse perspective matrix
src, dest = self.__get_current_roi()
pers_mat, inv_mat = self.__load_perspective_matrix(src, dest)
# transform the thresholded image to a bird's eye view
warped = self.__perspective_transform(preprocessed,pers_mat)
I looked the cv2.warpPerspective function,does this error means this function isn't use correctly? Thank you for help!
You need to call it as:
warped = cv2.warpPerspective(img, mat, img_size, flags=cv2.INTER_LINEAR)

Categories

Resources