3

I am working on a GoPiGo and i'm trying to make this robot to move when the camera detect a circle.

The mainly problem i have here is that when i try to use the gopigo library in order to use functions as fwd(),stop(), etc, if i do NOT use sudo in the command line, and just type "python CircleDetector_MOVEMENT.py" it detects the gopigo library, but doesn't detect the picamera.array:

Traceback (most recent call last):
  File "CircleDetector_MOVEMENT.py", line 2, in <module>
    from picamera.array import PiRGBArray
ImportError: No module named picamera.array

which i import from PIRGBarray. And when i use sudo python myprogram.py, it does NOT detect the gopigo library, and the error is the next:

Traceback (most recent call last):
   File "CircleDetector_MOVEMENT.py", line 8, in <module>
    from gopigo import *        #Has the basic functions for controlling the          GoPiGo Robot
ImportError: No module named gopigo

I guess it can be something related with permission, but i have no idea how to solve it.

So, if you please know what can be happening here, i'll be grateful. In their forum have told me that is an I2C issue, but i'm a noob in all this whole thing and i don't know how to solve it.

Any Help is appreciated.

P.S. Here you are my code, if it helps:

#import everything i need to get working all modules.
from picamera.array import PiRGBArray
from picamera import PiCamera
import time
import cv2
import os
import numpy as np
from gopigo import *    #Has the basic functions for controlling the GoPiGo     Robot
import sys  #Used for closing the running program
os.system('sudo modprobe bcm2835-v4l2')

h=200
w=300

camera = PiCamera()
camera.resolution = (w, h)
camera.framerate = 5
rawCapture = PiRGBArray(camera, size=(w, h))
time.sleep(0.1)


for frame in camera.capture_continuous(rawCapture, format="bgr",     use_video_port=True):
imagen_RGB = frame.array
copia_RGB = imagen_RGB.copy()



     gris = cv2.cvtColor(imagen_RGB, cv2.COLOR_BGR2GRAY)
     gris = cv2.medianBlur(gris,9)



    img_circulos = None
    img_circulos = cv2.HoughCircles(gris, cv2.cv.CV_HOUGH_GRADIENT, 1, 20, param1=50, param2=50, minRadius=0, maxRadius=0)


    if img_circulos is not None:

        v = 1
        img_circulos = np.round(img_circulos[0, :]).astype("int")


        for (x, y, r) in img_circulos:

            cv2.circle(copia_RGB, (x, y), r, (0, 255, 0), 3)
            cv2.rectangle(copia_RGB, (x - 5, y - 5),(x + 5, y + 5), (0, 128, 255, -1))
    if v == 1
       fwd()

    cv2.imshow("Imagen Combinada", copia_RGB)

    key = cv2.waitKey(1) & 0xFF
    rawCapture.truncate(0)
    if key == ord("q"):
        break
Dave
  • 41
  • 5

1 Answers1

0

Are you using a virtual environment to run the OpenCV code? If yes then you might have to copy gopigo.py to your virtual environment and run python <filename> to have it working.