Skip to content

Commit

Permalink
Merge branch 'main' of github.com:97hackbrian/embedded-labs
Browse files Browse the repository at this point in the history
  • Loading branch information
97hackbrian committed Nov 16, 2023
2 parents 0e404c2 + a5992bd commit c994220
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 38 deletions.
68 changes: 33 additions & 35 deletions Raspberry/Lab9/ej7.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion Raspberry/lab8/ej6.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@

if __name__ == "__main__":
camara=Camara(0)
camara.videoCanny(img,0,130,3,3)
camara.videoCanny(img,0,130,7,7)
4 changes: 2 additions & 2 deletions tankbot/scr/ex2P2.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -134,4 +134,4 @@ def FocalLength(measured_distance, real_width, width_in_rf_image):
break

cap.release()
cv2.destroyAllWindows()
cv2.destroyAllWindows()

0 comments on commit c994220

Please sign in to comment.