Exemple #1
0
def loop():
    try:
        camera.loop()
        cam_id = sys.argv[1]
        imgs = camera.get_image()
        data = {'parking': imgs[0], 'background': imgs[1]}
        print requests.post(config.url + '/api/set/' + cam_id, files=data).text
    except:
        print 'error'
Exemple #2
0
 def get_photo_data(self):
     image = camera.get_image()
     res = rq.post(url=self.address,
                   files={"file": open("opencv.png", "rb").read()})
     print(res.text)
     result = json.loads(res.text)
     result.sort(key=operator.itemgetter('confidence'))
     if len(result) == 0:
         print("No objects found")
         return None
     return result[0]
Exemple #3
0
def loop():
	try:
		camera.loop()
		cam_id = sys.argv[1]
		imgs = camera.get_image()
		data = {
			'parking' : imgs[0],
			'background' : imgs[1]
		}
		print requests.post(config.url + '/api/set/' + cam_id, files = data).text
	except:
		print 'error'
Exemple #4
0
def handle_msg(socket, msg):
    msg = msg['robot']

    print(msg)

    # TODO: specify resolution here?
    if 'get_image' in msg:
        #width, height = msg['get_image']
        image = camera.get_image()
        server.send_array(socket, image)

    if 'stop' in msg:
        drive.stop()
Exemple #5
0
 def __init__(self, args):
     image = camera.get_image()
     ngrok_data = args[1] if len(args) > 1 else ""
     self.address = "http://" + str(ngrok_data) + ".ngrok.io/"
     result = self.get_photo_data()
     if not result:
         sys.exit(0)
     else:
         self.goal = result.get("name")
         self.goal_coordinates = {
             "x": (result.get("start_x") + result.get('end_x')) / 2,
             "y": (result.get("start_y") + result.get('end_y')) / 2
         }
         self.distance.get_connection()
         distances = self.distance.get_distance_list()
         self.initial_distance = distances[4]
         self.calculate_initial_turn(result.get("image_width"))
Exemple #6
0
def free_mode():

    takes_list = []

    background = cv2.imread("background2.png", 1)
    cv2.imshow("window", background)
    cv2.waitKey(50)            
    while ("true"):

        mode = GPIO.input(13) # reads the circle switch

        if (mode == False or len(takes_list) < 3):
            cv2.imshow("window", background)
        else:
            cv2.imshow("window", image.averager(takes_list)) # displays a weighed average of the last 3 pictures taken
        cv2.waitKey(100)

        button_value = button.waitpressedbutton("free")

        if (button_value == "mode"):         # The mode is no longer freemode, we have to return to go to the selected mode
            return

        if (button_value == "record"):                        # takes and displays a picture
            cv2.imshow("window", background)
            cv2.waitKey(10)
            takes_list.append(camera.get_image())
            cv2.imshow("window", takes_list[len(takes_list) - 1])
            cv2.waitKey(200)

        if (button_value == "delete" and len(takes_list) > 0): # deletes the last picture taken
            img_supp = cv2.imread("img_supp.png", 1)
            cv2.imshow("window", img_supp)
            cv2.waitKey(10)
            del takes_list[-1]
            cv2.imshow("window", background)
            cv2.waitKey(300)
        if (button_value == "save"):                        # saves the cartoon and returns

            if (len(os.listdir("/media")) >= 2):
                os.system("mount /dev/sdb1 /home/pi/Pas_a_pas/bla")
                playing.save_other(takes_list)
                os.system("umount /home/pi/Pas_a_pas/bla")
            playing.save(takes_list)
            return
        if (button_value == "play"):                        # plays the cartoon
            playing.play(takes_list)
Exemple #7
0
def free_mode():

    takes_list = []

    background = cv2.imread("background2.png", 1)
    cv2.imshow("window", background)
    cv2.waitKey(50)
    while ("true"):

        mode = GPIO.input(13)  # reads the circle switch

        if (mode == False or len(takes_list) < 3):
            cv2.imshow("window", background)
        else:
            cv2.imshow(
                "window", image.averager(takes_list)
            )  # displays a weighed average of the last 3 pictures taken
        cv2.waitKey(100)

        button_value = button.waitpressedbutton("free")

        if (
                button_value == "mode"
        ):  # The mode is no longer freemode, we have to return to go to the selected mode
            return

        if (button_value == "record"):  # takes and displays a picture
            cv2.imshow("window", background)
            cv2.waitKey(10)
            takes_list.append(camera.get_image())
            cv2.imshow("window", takes_list[len(takes_list) - 1])
            cv2.waitKey(200)

        if (button_value == "delete"
                and len(takes_list) > 0):  # deletes the last picture taken
            del takes_list[-1]
            cv2.imshow("window", background)
            cv2.waitKey(300)
        if (button_value == "save"):  # saves the cartoon and returns
            playing.save(takes_list)
            return
        if (button_value == "play"):  # plays the cartoon
            playing.play(takes_list)
Exemple #8
0
def move_eye_camera(robotID, x, y, z):
    cam_link_state = p.getLinkState(robotID,
                                    linkIndex=7,
                                    computeForwardKinematics=1)
    camera_pos_W = cam_link_state[-2]
    camera_ort_W = cam_link_state[-1]

    roll = 0.0  #this will cause end effector to rotate on its axis
    pitch = 0.0
    yaw = 0.0
    cameraTargetPos = [x, y, z]
    cameraTargetOrn = p.getQuaternionFromEuler([roll, pitch, yaw])
    new_camera_pos_W, new_camera_ort_W = p.multiplyTransforms(
        camera_pos_W, camera_ort_W, cameraTargetPos, cameraTargetOrn)
    # print('new_camera_ort_W',new_camera_ort_W)
    #following is the new function defined above in this file
    accurateIK(robotID,
               7,
               new_camera_pos_W,
               new_camera_ort_W,
               useNullSpace=False)
    return get_image(robotID)
    # Vc[1] = temp[1]
    # Vc[2] = -temp[0]
    # temp = Vc[2]
    # Vc[2] = -Vc[0]
    # Vc[0] = temp
    # temp = Wc[2]
    # Wc[2] = -Wc[0]
    # Wc[0] = temp

    # Qc = p.getQuaternionFromEuler(Wc)
    # Vc,c = relative_ee_pose_to_ee_world_pose1(roboId,Vc,Qc)
    V = np.concatenate((Vc,Wc))
    # print(pos)
    return V

I,Dbuf,Sbuf = get_image(kukaId)
sx,sy,sz = mask_points(Sbuf,Dbuf,appleId)
r,cx,cy,cz = sphereFit(sx,sy,sz)
pos = np.array((cx,cy,cz))[:,0]
ort = np.array((0.0,0.0,0.0))
# pos2,ort2 = relative_ee_pose_to_ee_world_pose1(roboId,pos,cubeStartOrientation)
# accurateIK(roboId,7,pos2,ort2,useNullSpace=False)
# c = input('press enter to end')
Ve = visual_servo_control(pos,ort)
error_list = []
target_pos_list = []
ee_pos_list = []



for i in range (100):
Exemple #10
0
def assisted_mode():

    # The model is loaded first
    model_list = selection.select_cartoon("/media/PAP/models/", "assisted")
    if model_list == None:
        return

    takes_list = []
    background = cv2.imread("background2.png", 1)
    model_cursor = 0
    takes_cursor = 0

    # When this condition is false, the program saves automatically the cartoon and returns
    while (len(model_list) > len(takes_list)):

        if ((GPIO.input(6) == False) or (len(takes_list) == 0)):
            cv2.imshow("window", model_list[model_cursor % len(model_list)])
            cv2.waitKey(100)
        else:
            cv2.imshow("window", takes_list[takes_cursor % len(takes_list)])
            cv2.waitKey(100)

        # I move the window again because of a window issue, that still occurs the first time model_cursor = 1
        cv2.moveWindow("window", 0, -30)

        button_value = button.waitpressedbutton("assisted")
        if (button_value == "mode"):
            return

        if (button_value == "record"):  # take the picture
            model_cursor += 1
            cv2.imshow("window", background)
            cv2.waitKey(20)
            takes_list.append(camera.get_image())

        if (button_value == "delete" and len(takes_list) >
                0):  # delete the last picture from takes_list
            del (takes_list[-1])
            cv2.waitKey(300)

        if (button_value == "save"):  # save the cartoon and returns
            if not os.path.exists("/media/PAP/cartoons"):
                cv2.imshow("window", cv2.imread("./save_failed"))
                cv2.waitKey(100)
            else:
                playing.save(takes_list)
                return

        if (button_value == "play"):  # plays the cartoon
            playing.play(takes_list)
        if (button_value == "next"):  # move to next image
            if (GPIO.input(6) == False):
                model_cursor += 1
            else:
                takes_cursor += 1
            cv2.waitKey(100)

        if (button_value == "prev"):  # move to previous image
            if (GPIO.input(6) == False):
                model_cursor -= 1
            else:
                takes_cursor -= 1
            cv2.waitKey(100)

    # end of while loop, save and return
    if not os.path.exists("/media/PAP/cartoons"):
        cv2.imshow("window", cv2.imread("./save_failed"))
        cv2.waitKey(100)
    else:
        playing.save(takes_list)
        return
Exemple #11
0
def assisted_mode():

    # The model is loaded first
    model_list = selection.select_cartoon("/media/PAP/models/", "assisted")
    if model_list == None:
        return

    takes_list = []
    background = cv2.imread("background2.png", 1)
    model_cursor = 0
    takes_cursor = 0

    # When this condition is false, the program saves automatically the cartoon and returns
    while len(model_list) > len(takes_list):

        if (GPIO.input(6) == False) or (len(takes_list) == 0):
            cv2.imshow("window", model_list[model_cursor % len(model_list)])
            cv2.waitKey(100)
        else:
            cv2.imshow("window", takes_list[takes_cursor % len(takes_list)])
            cv2.waitKey(100)

        # I move the window again because of a window issue, that still occurs the first time model_cursor = 1
        cv2.moveWindow("window", 0, -30)

        button_value = button.waitpressedbutton("assisted")
        if button_value == "mode":
            return

        if button_value == "record":  # take the picture
            model_cursor += 1
            cv2.imshow("window", background)
            cv2.waitKey(20)
            takes_list.append(camera.get_image())

        if button_value == "delete" and len(takes_list) > 0:  # delete the last picture from takes_list
            del (takes_list[-1])
            cv2.waitKey(300)

        if button_value == "save":  # save the cartoon and returns
            if not os.path.exists("/media/PAP/cartoons"):
                cv2.imshow("window", cv2.imread("./save_failed"))
                cv2.waitKey(100)
            else:
                playing.save(takes_list)
                return

        if button_value == "play":  # plays the cartoon
            playing.play(takes_list)
        if button_value == "next":  # move to next image
            if GPIO.input(6) == False:
                model_cursor += 1
            else:
                takes_cursor += 1
            cv2.waitKey(100)

        if button_value == "prev":  # move to previous image
            if GPIO.input(6) == False:
                model_cursor -= 1
            else:
                takes_cursor -= 1
            cv2.waitKey(100)

    # end of while loop, save and return
    if not os.path.exists("/media/PAP/cartoons"):
        cv2.imshow("window", cv2.imread("./save_failed"))
        cv2.waitKey(100)
    else:
        playing.save(takes_list)
        return
Exemple #12
0


# load json and create model
json_file = open('model1.json', 'r')
loaded_model_json = json_file.read()
json_file.close()
loaded_model = model_from_json(loaded_model_json)
# load weights into new model
loaded_model.load_weights("model1.h5")
print("Loaded model from disk")

while True:

 try:
  image=np.array([camera.get_image()])
  image = image.astype('float32')
  image = image / 255.0

  prediction=loaded_model.predict(image)





  print(dataset[np.argmax(prediction)])


 except KeyboardInterrupt:
  exit()
os.environ['TF_CPP_MIN_LOG_LEVEL'] = '2'

# load model
model = load_model('picture_model.h5')
# summarize model.
model.summary()
# load dataset

# evaluate the model

input("hazırsan bir tuşa bas:")
#time.sleep(5)
print("Başladı")
start=datetime.now()
for item in range(1):
    features,orginal_image=camera.get_image()
X =impy.convert_images_to_prediction_dataset(features)
Xi=np.array([x[1] for x in X]).astype(np.float32)
Xim=[x[0] for x in X]



score = model.predict(Xi)
scores=[[Xim[x],score[x]] for x in range(len(score))]
print("Train edilmemiş tahmin:")
for score in scores:
    print("İmaj: ",score[0],convert_val_to_expression(score[1],"Alper"))

end=datetime.now()

result=float((end-start).microseconds/1000000)+(end-start).seconds