Home Python shows error "name 'resized' is not defined" on compiling the following code
Reply: 1

Python shows error "name 'resized' is not defined" on compiling the following code

Harshit
1#
Harshit Published in 2018-02-13 08:40:17Z

I'm trying to implement line detection on python using raspberry pi 3 and picam

import picamera
import picamera.array
import time
import cv2
import numpy as np

#Initialize camera
camera = picamera.PiCamera()
camera.resolution = (640,480)
rawCapture = picamera.array.PiRGBArray(camera)
#Let camera warm up
time.sleep(0.1)

#Capture image
camera.capture(rawCapture, format="bgr")
img = rawCapture.array

#Convert to Grayscale
gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)

#Blur image to reduce noise
blurred = cv2.GaussianBlur(gray, (9, 9), 0)

#Perform canny edge-detection
edged = cv2.Canny(blurred, 50, 150)

#Perform hough lines probalistic transform
lines = cv2.HoughLinesP(edged,1,np.pi/180,10,80,1)

#Draw lines on input image
if(lines != None):
    for x1,y1,x2,y2 in lines[0]:
        cv2.line(resized,(x1,y1),(x2,y2),(0,255,0),2)

cv2.imshow("line detect test", img) 
cv2.waitKey(0)

The following error is displayed:

Traceback (most recent call last): File "/home/pi/picam lane detection.py", line 33, in cv2.line(resize,(x1,y1),(x2,y2),(0,255,0),2) NameError: name 'resize' is not defined

Please help me figure out the issue.

wang.xuhao
2#
wang.xuhao Reply to 2018-02-13 10:42:56Z

I think the resized is not defined. Maybe you can change resized to img.

import picamera
import picamera.array
import time
import cv2
import numpy as np

#Initialize camera
camera = picamera.PiCamera()
camera.resolution = (640,480)
rawCapture = picamera.array.PiRGBArray(camera)
#Let camera warm up
time.sleep(0.1)

#Capture image
camera.capture(rawCapture, format="bgr")
img = rawCapture.array

#Convert to Grayscale
gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)

#Blur image to reduce noise
blurred = cv2.GaussianBlur(gray, (9, 9), 0)

#Perform canny edge-detection
edged = cv2.Canny(blurred, 50, 150)

#Perform hough lines probalistic transform
lines = cv2.HoughLinesP(edged,1,np.pi/180,10,80,1)

#Draw lines on input image
if(lines != None):
    for x1,y1,x2,y2 in lines[0]:
        cv2.line(img,(x1,y1),(x2,y2),(0,255,0),2)

cv2.imshow("line detect test", img) 
cv2.waitKey(0)
You need to login account before you can post.

About| Privacy statement| Terms of Service| Advertising| Contact us| Help| Sitemap|
Processed in 0.295636 second(s) , Gzip On .

© 2016 Powered by mzan.com design MATCHINFO