Skip to content Skip to sidebar Skip to footer

Getting Division By Zero Error With Python And Opencv

I am using this code to remove the lines from the following image: I don't know the reason, but it gives me as output ZeroDivisionError: division by zero error on line 34 - x0, x1

Solution 1:

Well the cause of the error is that the length is 0 of either y0_list or y1_list (or both). Since you initialize them in this for loop :

for x0,y0,x1,y1 in lines:
    if x0 == 0:
        y0_list.append(y0)
    if x1 == im_wb.shape[1]:
        y1_list.append(y1)

You can narrow your error down to either lines not having the expected values or your 2 if statements being faulty. I believe the problem is caused by the latter but the easiest check you can do is print out lines and check manually if your if statements would be triggered.

Post a Comment for "Getting Division By Zero Error With Python And Opencv"