def save_snaps(width=0, height=0, name="snapshot", folder=".", raspi=False):

    if raspi:
        os.system('sudo modprobe bcm2835-v4l2')
    if (not USING_DRONE):
        cap = cv2.VideoCapture(0)
        if width > 0 and height > 0:
            print("Setting the custom Width and Height")
            cap.set(cv2.CAP_PROP_FRAME_WIDTH, width)
            cap.set(cv2.CAP_PROP_FRAME_HEIGHT, height)
    else:
        drone = DroneObject()
        drone.setup()
        cap = drone.tello.get_frame_read()
        time.sleep(5)

    try:
        if not os.path.exists(folder):
            os.makedirs(folder)
            # ----------- CREATE THE FOLDER -----------------
            folder = os.path.dirname(folder)
            try:
                os.stat(folder)
            except:
                os.mkdir(folder)
    except:
        pass

    nSnap   = 0
    if (not USING_DRONE):
        w       = cap.get(cv2.CAP_PROP_FRAME_WIDTH)
        h       = cap.get(cv2.CAP_PROP_FRAME_HEIGHT)

    fileName    = "%s/%s_%d_%d_" %(folder, name, w, h)
    while True:
        if (not USING_DRONE):
            ret, frame = cap.read()
        else:
            frame = cap.frame
        cv2.imshow('camera', frame)

        key = cv2.waitKey(1) & 0xFF
        if key == ord('q'):
            break
        if key == ord(' '):
            print("Saving image ", nSnap)
            cv2.imwrite("%s%d.jpg"%(fileName, nSnap), frame)
            nSnap += 1

    cap.release()
    cv2.destroyAllWindows()
Ejemplo n.º 2
0
def save_snaps(width=0, height=0, name="snapshot", folder=".", raspi=False):

    drone = DroneObject()
    drone.setup()
    cap = drone.tello.get_frame_read()
    time.sleep(5)

    try:
        if not os.path.exists(folder):
            os.makedirs(folder)
            # ----------- CREATE THE FOLDER -----------------
            folder = os.path.dirname(folder)
            try:
                os.stat(folder)
            except:
                os.mkdir(folder)
    except:
        pass

    nSnap = 0
    w = 0
    h = 0
    fileName = "%s/%s_%d_%d_" % (folder, name, w, h)
    while True:

        frame = cap.frame
        cv2.imshow('camera', frame)

        key = cv2.waitKey(1) & 0xFF
        if key == ord('q'):
            break
        if key == ord(' '):
            print("Saving image ", nSnap)
            cv2.imwrite("%s%d.jpg" % (fileName, nSnap), frame)
            nSnap += 1

    cap.release()
    cv2.destroyAllWindows()
Ejemplo n.º 3
0
    elif ((orientation > 310 and orientation <= 360)
          or (orientation >= 0 and orientation <= 30)):
        RightSide = ((coordinates[0][1][0] - coordinates[0][0][0])**2 +
                     (coordinates[0][1][1] - coordinates[0][0][1])**2)**0.5
        LeftSide = ((coordinates[0][2][0] - coordinates[0][3][0])**2 +
                    (coordinates[0][2][1] - coordinates[0][3][1])**2)**0.5
        Ratio = (1.0 * RightSide / LeftSide)
        cv2.putText(frame, ("Ratio is %s" % Ratio), (400, 15),
                    cv2.FONT_HERSHEY_SIMPLEX, .5, (0, 0, 0), 2, cv2.LINE_AA)
    return Ratio


if __name__ == "__main__":
    #Create drone object and set up communication
    drone = DroneObject()
    drone.setup()
    frame_read = drone.tello.get_frame_read()
    time.sleep(5)

    angle = 0
    KNOWN_WIDTH = 9.7
    FOCAL_LENGTH = 630
    tilt = 0

    while (True):
        #retrieve frame and convert to black and white
        frame = frame_read.frame
        gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)

        #Detect 6X6 marker
Ejemplo n.º 4
0

def DetermineFocalLength(blueRect, redRect):

    return ((redRect[2]+blueRect[2]) * 15/ 8)

def StateTransition(orientation):
    if (orientation < 100 and orientation > 80):
        drone.on_event("take_off")


    elif (orientation < 280 and orientation > 260):
        drone.on_event("land")

if __name__ == "__main__":
    drone = DroneObject()
    drone.setup()
    frame_read = drone.tello.get_frame_read()
    time.sleep(5)
    FOCAL_LENGTH = 1000
    KNOWN_WIDTH = 8
    FPS = 30

    while True:
        frame = frame_read.frame
        blue = cv2.inRange(frame, blueLower, blueUpper)
        blue = cv2.GaussianBlur(blue, (3, 3), 0)

        (cnts, _) = cv2.findContours(blue.copy(), cv2.RETR_EXTERNAL, cv2.CHAIN_APPROX_SIMPLE)
        # find the largest contour. must use the copy otherwise will destroy the original
from StateMachine.DroneObject import DroneObject
import time
drone = DroneObject()
time.sleep(1)
drone.on_event("take_off")
print(drone.state)
time.sleep(2)
drone.on_event("take_off")
time.sleep(2)
drone.on_event("track")
time.sleep(3)
drone.on_event("land")
time.sleep(2)
drone.on_event("idle")
time.sleep(10)
Ejemplo n.º 6
0
from StateMachine.DroneObject import DroneObject
import time
import cv2

drone = DroneObject()

drone.setup()
frame_read = drone.tello.get_frame_read()
frame = frame_read.frame
cv2.imshow("frame", frame)
time.sleep(1)

drone.on_event("take_off")
drone.action()
time.sleep(5)

drone.on_event("land")
drone.action()
Ejemplo n.º 7
0
    return ((redRect[2] + blueRect[2]) * 15 / 8)


def StateTransition(orientation):
    if (orientation < 100 and orientation > 80):
        drone.on_event("take_off")

    elif (orientation < 280 and orientation > 260):
        drone.on_event("land")


if __name__ == "__main__":
    camera = cv2.VideoCapture(0)
    FOCAL_LENGTH = 500
    KNOWN_WIDTH = 8
    drone = DroneObject()

    while True:
        (grabbed, frame) = camera.read()

        blue = cv2.inRange(frame, blueLower, blueUpper)
        blue = cv2.GaussianBlur(blue, (3, 3), 0)

        (cnts, _) = cv2.findContours(blue.copy(), cv2.RETR_EXTERNAL,
                                     cv2.CHAIN_APPROX_SIMPLE)
        #find the largest contour. must use the copy otherwise will destroy the original

        red = cv2.inRange(frame, redLower, redUpper)
        red = cv2.GaussianBlur(red, (3, 3), 0)
        (redcnts, _) = cv2.findContours(red.copy(), cv2.RETR_EXTERNAL,
                                        cv2.CHAIN_APPROX_SIMPLE)