diff --git a/Raspberry/Lab9/ej7.py b/Raspberry/Lab9/ej7.py index 5d9fdca..9ffb74e 100644 --- a/Raspberry/Lab9/ej7.py +++ b/Raspberry/Lab9/ej7.py @@ -31,9 +31,9 @@ lower_green = np.array([0, 0, 0]) upper_green = np.array([0, 0, 0]) lower_red1 = np.array([0, 50, 50]) - upper_red1 = np.array([10, 150, 255]) - lower_red2 = np.array([160, 50, 50]) - upper_red2 = np.array([180, 150, 255]) + upper_red1 = np.array([10, 255, 255]) + lower_red2 = np.array([0, 50, 0])### + upper_red2 = np.array([10, 255, 255]) # Create masks for the colors mask_blue = cv2.inRange(frame_hsv, lower_blue, upper_blue) @@ -49,40 +49,38 @@ # Find contours in the combined mask contours, _ = cv2.findContours(mask, cv2.RETR_EXTERNAL, cv2.CHAIN_APPROX_SIMPLE) - - for cnt in contours: - # Calculate area and remove small elements - area = cv2.contourArea(cnt) - if len(cnt)>=2: - Leds.write(1,1,0,0) - sleep(0.5) - Leds.write(0,0,1,1) - sleep(0.5) - motors.stop() - - if area > 1000: - if len(cnt)>=2: - Leds.write(1,1,0,0) - sleep(0.5) - Leds.write(0,0,1,1) - sleep(0.5) - motors.stop() - - else: - x, y, w, h = cv2.boundingRect(cnt) - center_x = x + w // 2 + print(len(contours)) + if len(contours)>=25: + for cnt in contours: + # Calculate area and remove small elements + area = cv2.contourArea(cnt) + + + if area > 10000: + print("cnt ",len(cnt)) + if len(cnt)>=2000: + Leds.write(1,1,0,0) + sleep(0.01) + Leds.write(0,0,1,1) + sleep(0.01) + motors.stop() - if center_x > 420: - print("derecha") - motors.move(70, -70) - elif center_x < 210: - print("izquierda") - motors.move(-84, 84) else: - print("centro") - motors.stop() - if len(contours)==0: - motors.move(-70, 75) + x, y, w, h = cv2.boundingRect(cnt) + center_x = x + w // 2 + + if center_x > 420: + print("derecha") + motors.move(70, -70) + elif center_x < 210: + print("izquierda") + motors.move(-84, 84) + else: + print("centro") + motors.stop() + else: + print("AQUI!!!!!!!!!!") + motors.move(-75, 75) cv2.imshow("Frame", frame) cv2.imshow("Mask", mask) diff --git a/Raspberry/lab8/ej6.py b/Raspberry/lab8/ej6.py index ecb89c2..6c13406 100644 --- a/Raspberry/lab8/ej6.py +++ b/Raspberry/lab8/ej6.py @@ -3,4 +3,4 @@ if __name__ == "__main__": camara=Camara(0) - camara.videoCanny(img,0,130,3,3) \ No newline at end of file + camara.videoCanny(img,0,130,7,7) diff --git a/tankbot/scr/ex2P2.py b/tankbot/scr/ex2P2.py index 4fc1239..a703151 100644 --- a/tankbot/scr/ex2P2.py +++ b/tankbot/scr/ex2P2.py @@ -112,7 +112,7 @@ def FocalLength(measured_distance, real_width, width_in_rf_image): #dir=FocalLength(ra,10,10) if area<=50000: - motors.move(70,70) + motors.move(60,60) print("avanzar!") else: motors.stop() @@ -134,4 +134,4 @@ def FocalLength(measured_distance, real_width, width_in_rf_image): break cap.release() -cv2.destroyAllWindows() \ No newline at end of file +cv2.destroyAllWindows()