logo
Tags down

shadow

"ZeroDivisionError: float division by zero" for image processing code using Rapberry Pi3 and camera


By : Crimson.King
Date : October 15 2020, 08:10 AM
fixed the issue. Will look into that further I have edited these code, and these are the code: , This block
code :
M = cv2.moments(c)
cX = int((M["m10"] / M["m00"]) * ratio)
cY = int((M["m01"] / M["m00"]) * ratio)
from pyimagesearch.shapedetector import ShapeDetector
import argparse
import imutils
import cv2

ap = argparse.ArgumentParser()
ap.add_argument("-v", "--video",help="path to the (optional) video file")
ap.add_argument("-b", "--buffer",type=int, default=64,help="max buffer size")
args = vars(ap.parse_args())

if not args.get("video", False):
    camera = cv2.VideoCapture(0)
else:
    camera = v2.VideoCapture(args["video"])

while True:
    (grabbed, frame) = camera.read()
     if args.get("video") and not grabbed:
         break

     frame = imutils.rotate(frame, angle=180)
     resized = imutils.resize(frame, width=300)
     ratio = frame.shape[0] / float(resized.shape[0])

     gray = cv2.cvtColor(resized, cv2.COLOR_BGR2GRAY)
     blurred = cv2.GaussianBlur(gray, (5, 5), 0)
     thresh = cv2.threshold(blurred, 60, 255, cv2.THRESH_BINARY)[1]

     cnts = cv2.findContours(thresh.copy(), cv2.RETR_EXTERNAL,
                        cv2.CHAIN_APPROX_SIMPLE)
     cnts = imutils.grab_contours(cnts)
     sd = ShapeDetector()


     for c in cnts:
         M = cv2.moments(c)
         if(M["m00"]==0): # this is a line
             shape = "line" 
         else: 
             cX = int((M["m10"] / M["m00"]) * ratio)
             cY = int((M["m01"] / M["m00"]) * ratio)
             shape = sd.detect(c)

             c = c.astype("float")
             c *= ratio
             c = c.astype("int")
             cv2.drawContours(frame, [c], -1, (0, 255, 0), 2)
             cv2.putText(frame, shape, (cX, cY), cv2.FONT_HERSHEY_SIMPLEX,
                0.5, (255, 255, 255), 2)

             cv2.imshow("Gambar", frame)
             key = cv2.waitKey(1) & 0xFF

    # if the 'q' key is pressed, stop the loop
        if key == ord("q"):
            break
camera.release()
cv2.destroyAllWindows()


Share : facebook icon twitter icon

ZeroDivisionError: float division


By : Ishan
Date : March 29 2020, 07:55 AM
it should still fix some issue I have got this code to solve Newton's method. But it gives a zero division error. I cannot figure out what is wrong. Thank you. , You have a basic bug here:
code :
for i, start_time in enumerate(tlist):
    end_time = tlist[i]
for i, start_time in enumerate(tlist[:-1]):
    end_time = tlist[i+1]

ZeroDivisionError: float division by zero in a code for Surface plot


By : user2008724
Date : March 29 2020, 07:55 AM
I think the issue was by ths following , If I have understood the code correctly, there is a problem with zVals in mayavi.mlab.surf.
According to the documentation of the function, s is the elevation matrix, a 2D array, where indices along the first array axis represent x locations, and indices along the second array axis represent y locations. Your file reader seems to return a 1D vector instead of an array.
code :
import mayavi.mlab as ml
import numpy

def plot_data(filename):
    data = numpy.loadtxt(filename)
    xvals = data[:,0]
    yvals = data[:,1]
    zvals = data[:,2] * 1000.
    return ml.points3d(x, y, z)

plot_data('data')   
import mayavi.mlab as ml
import numpy
importt matplotlib.pyplot as plt

# whatever you have as the number of points per row
columns = 13

data = numpy.loadtxt(filename)

# draw the data points into a XY plane to check that they really for a rectangular grid:
plt.plot(data[:,0], data[:,1])

# draw the surface
zvals = data[:,2].reshape(-1,columns)
ml.surf(zvals, warp_scale='auto')

How to fix "ZeroDivisionError: float division by zero"


By : user2287836
Date : March 29 2020, 07:55 AM
To fix this issue The ZeroDivisionError happens when you try to divide a number by 0, which as you know is a mathematical impossibility, just change the value of the dividend.

Need help solving "ZeroDivisionError: division by zero"


By : Maoc
Date : March 29 2020, 07:55 AM
should help you out your getRate method returns zero when you define rate_Nok_Eur = getRate('NOK', 'EUR'), so amount_nok / rate_Nok_Eur will gave you the error,
you need to specify the case when you have getRate('NOK', 'EUR')

ZeroDivisionError: float division by zero?


By : user3414826
Date : March 29 2020, 07:55 AM
To fix this issue When I add the suggestions of using abs() and ** and then catch the exception I get code like this:
code :
def fx(x):
    v = float(x*x*x - 5*x - 7)
    return v


err = int(input("Enter zeroes in approxiamtion in solution: "))
b = float(input("Enter upper limit for root: "))
a = float(input("Enter lower limit for root: "))
c = 0.0

while abs(fx(c)) > ( 10 ** -err):
    try:
        c = b - ((b - a)/(fx(b) - fx(a))) * fx(b)
    except ZeroDivisionError:
        break
    print(a, b, c, sep=', ')
    a = b
    b = c
    c = 0
    print()
print("The root is approximately = ", b)
Enter zeroes in approxiamtion in solution: 3
Enter upper limit for root: 2
Enter lower limit for root: 1
1.0, 2.0, 6.5

2.0, 6.5, 2.1658986175115205

6.5, 2.1658986175115205, 2.302797651275858

( steps omitted )

2.7473464241055843, 2.7473465403033757, 2.747346540307211

2.7473465403033757, 2.747346540307211, 2.747346540307211

The root is approximately =  2.747346540307211
Related Posts Related Posts :
  • I'm getting positional argument in Django rest framework APIView class empty. Why? And how to pass value into it?
  • Create an array according to index in another array in Python
  • Matplotlib multiple Y-axes, xlabels disappear?
  • feedparser for reddit returning empty
  • physical dimensions and array dimensions
  • can't get my program to return to main loop
  • how to read image into tensor from url directly
  • Can't find a combination of keywords on an xml page using python and beautiful soup
  • Find the rotation of a quad (4 points, planar)
  • Class method input variables
  • Pandas Dataframe, how to group columns together in Python
  • What does "auth.User" in Django do?
  • Python - Get Last Element after str.split()
  • How to access a variable in one python function in another function
  • Manually computed validation loss different from reported val_loss when using regularization
  • Filtering with a only one conditional
  • How to set specific faker random string of specific length and using underscores for spaces?
  • seaborn FacetGrid+map_dataframe fails (but not when using map)
  • How to get GraphQL schema with Python?
  • Python - How to send values between functions once
  • Loop sum find and multiple
  • Map & append multiple values (per each key) from a dict to different columns of a dataframe
  • Python list of dictionaries incrementation error
  • Filtering Spark Dataframe
  • pytest: How to test project-dependent directory creation?
  • Python Group by and Sum with a Blank space
  • Reorder and return the whole of nested dictionary
  • Finding element from one list in nested second list
  • Calculating AUC for Unsupervised LOF in sklearn
  • Storing Specific Whole Numbers - Python
  • Simulate SHL and SHR ASM instructions in Python
  • AttributeError: type object 'DirectView' has no attribute 'as_view'
  • Iterate through list and print 'true' if list element is of a certain type
  • Web scraping: How to test if the root tag has a particular CSS class?
  • Bar Graph in Python with 2 scales (y-axis) with matplotlib import
  • Use of Breakpoint Method
  • pdf file generated using reportlab , getting saved as plain text
  • Pandas DataFrame: programmatic rows split of a dataframe on multiple columns conditions
  • Combine the data based on common index with dates
  • Accessing Tags within HTML comments
  • how to conditionally change array values
  • Numpy failing in Python3 Google App Flexible Engine
  • Fastest way to delete/extract a submatrix from a numpy matrix
  • Pandas dividing distance by timedelta
  • Enforce minimum spacing between non-zero elements in array
  • Convert web scraped string list to formatted CSV
  • How to clear value from cell if value in another column is present?
  • what use tensorflow estimator create multi-input
  • Selenium: Find an element stored in a container
  • specify *.pyd output path?
  • Looping through pixels with Cython still slow
  • Python - Recursive Function does not work with len() despite the returned value being a list
  • Having trouble reading Pandas dataframe with SciLearn Kit
  • Reshape vertical series to horizontal in Python
  • Removing background from galaxy photos using Python
  • Failed to verify: !m_var2expr.empty() on z3 python
  • what does [:, :, ::-1] mean in python?
  • Conditional loop for pandas dataframe rows
  • Check the value in next row in order to apply certain rules to current rows in Python
  • Python getting the grouped values from positive look ahead
  • shadow
    Privacy Policy - Terms - Contact Us © voile276.org