Notes![what is notes.io? What is notes.io?](/theme/images/whatisnotesio.png)
![]() ![]() Notes - notes.io |
from picamera.array import PiRGBArray
from picamera import PiCamera
import RPi.GPIO as GPIO
import time
import cv2
import numpy as np
MOTOR1B=17 #Left Motor
MOTOR1E=18
MOTOR2B=22 #Right Motor
MOTOR2E=23
centerx=80
centery=64
GPIO.setmode(GPIO.BCM)
GPIO.setwarnings(False)
GPIO.setup(MOTOR1B, GPIO.OUT)
GPIO.setup(MOTOR1E, GPIO.OUT)
GPIO.setup(MOTOR2B, GPIO.OUT)
GPIO.setup(MOTOR2E, GPIO.OUT)
#alt ve üst threshold sınırları 2 adet 1x3 olarak veya 1 adet 1x3 olarak verilebilir.
#gece doğal sarı ışık altında
#lowerhsv=np.array([50,30,30])
#upperhsv=np.array([75,240,240])
#gündüz doğal ışıkta
lowerhsv=np.array([41,30,30])
upperhsv=np.array([75,240,240])
#gece doğal sarı ışık altında
#lowerycr=np.array([62,46,71]) 147, 112, 114
#upperycr=np.array([159,88,129]) 72, 98, 112
#gündüz doğal ışıkta
lowerycr=np.array([53, 62, 27])
upperycr=np.array([133, 142, 107])
kernelOpen = np.ones((8,8),np.uint8)
kernelClose = np.ones((5,5),np.uint8)
def forward():
GPIO.output(MOTOR1B, GPIO.HIGH)
GPIO.output(MOTOR1E, GPIO.LOW)
GPIO.output(MOTOR2B, GPIO.HIGH)
GPIO.output(MOTOR2E, GPIO.LOW)
def reverse():
GPIO.output(MOTOR1B, GPIO.LOW)
GPIO.output(MOTOR1E, GPIO.HIGH)
GPIO.output(MOTOR2B, GPIO.LOW)
GPIO.output(MOTOR2E, GPIO.HIGH)
def rightturn():
GPIO.output(MOTOR1B,GPIO.LOW)
GPIO.output(MOTOR1E,GPIO.HIGH)
GPIO.output(MOTOR2B,GPIO.HIGH)
GPIO.output(MOTOR2E,GPIO.LOW)
def leftturn():
GPIO.output(MOTOR1B,GPIO.HIGH)
GPIO.output(MOTOR1E,GPIO.LOW)
GPIO.output(MOTOR2B,GPIO.LOW)
GPIO.output(MOTOR2E,GPIO.HIGH)
def stop():
GPIO.output(MOTOR1E,GPIO.LOW)
GPIO.output(MOTOR1B,GPIO.LOW)
GPIO.output(MOTOR2E,GPIO.LOW)
GPIO.output(MOTOR2B,GPIO.LOW)
camera = PiCamera()
camera.resolution = (160, 128)
camera.framerate = 16
rawCapture = PiRGBArray(camera, size=(160, 128))
time.sleep(0.001)
for image in camera.capture_continuous(rawCapture, format="bgr", use_video_port=True):
img = image.array
horizontal_img = cv2.flip( img, 0 )
hsvimg= cv2.cvtColor(img,cv2.COLOR_BGR2HSV)
hsvimgfiltered= cv2.GaussianBlur(hsvimg,(5,5),0)
maskhsv=cv2.inRange(hsvimg,lowerhsv,upperhsv)
maskOpenhsv=cv2.morphologyEx(maskhsv,cv2.MORPH_OPEN,kernelOpen)
maskClosehsv=cv2.morphologyEx(maskOpenhsv,cv2.MORPH_CLOSE,kernelClose)
cv2.imshow("hsvmask", maskClosehsv)
ycrimg= cv2.cvtColor(img,cv2.COLOR_BGR2YCrCb)
ycrimgfiltered= cv2.GaussianBlur(ycrimg,(5,5),0)
maskycr=cv2.inRange(ycrimg,lowerycr,upperycr)
maskOpenycr=cv2.morphologyEx(maskycr,cv2.MORPH_OPEN,kernelOpen)
maskCloseycr=cv2.morphologyEx(maskOpenycr,cv2.MORPH_CLOSE,kernelClose)
cv2.imshow("ycrmask", maskCloseycr)
combine = cv2.bitwise_and(maskClosehsv, maskClosehsv, mask = maskCloseycr)
cv2.imshow("combine", combine)
_, contours, hierarchy=cv2.findContours(combine.copy(),cv2.RETR_EXTERNAL,cv2.CHAIN_APPROX_SIMPLE)
cv2.line(img,(80,0),(80,128),(0,255,0), 1)
cv2.line(img,(0,64),(160,64),(0,255,0),1)
cv2.circle(img, (centerx, centery), 2, (0, 0, 255), 1)
limit1=100
limit2=4500
area1=0
for i, contour in enumerate(contours):
cnt=contours[i]
M = cv2.moments(cnt)
area=cv2.contourArea(cnt)
print("area", area)
if len(cnt) > 0:
area1=area
(x, y), radius = cv2.minEnclosingCircle(cnt)
center = (int(x), int(y))
radius = int(radius)
img = cv2.circle(img, center, radius, (255, 0, 0), 2)
img = cv2.circle(img, center, 1, (0, 0, 255), 3)
print(center, radius)
else:
continue
if area1 < 10:
print("stop1")
time.sleep(1.005)
print("leftturn1")
time.sleep(1.005)
print("forward1")
time.sleep(1.005)
print("rightturn1")
time.sleep(1.005)
print("forward1")
time.sleep(1.005)
elif area1 >= 10:
print("stop2")
time.sleep(1.005)
if (int(x)-centerx) < -10:
print("leftturn21")
time.sleep(1.005)
elif (int(x)-centerx) > 10:
print("rightturn22")
time.sleep(1.005)
else:
if area1 <= limit1:
print("forward211")
time.sleep(1.005)
elif area1 > limit2:
print("reverse212")
time.sleep(1.005)
else:
print("stop12")
time.sleep(1.005)
#cv2.drawContours(img,contours,-1,(0,255,0),3)
cv2.imshow("final", img)
rawCapture.truncate(0)
key = cv2.waitKey(1) & 0xFF
if key == ord("q"):
break
cv2.destroyAllWindows()
GPIO.cleanup()
![]() |
Notes is a web-based application for online taking notes. You can take your notes and share with others people. If you like taking long notes, notes.io is designed for you. To date, over 8,000,000,000+ notes created and continuing...
With notes.io;
- * You can take a note from anywhere and any device with internet connection.
- * You can share the notes in social platforms (YouTube, Facebook, Twitter, instagram etc.).
- * You can quickly share your contents without website, blog and e-mail.
- * You don't need to create any Account to share a note. As you wish you can use quick, easy and best shortened notes with sms, websites, e-mail, or messaging services (WhatsApp, iMessage, Telegram, Signal).
- * Notes.io has fabulous infrastructure design for a short link and allows you to share the note as an easy and understandable link.
Fast: Notes.io is built for speed and performance. You can take a notes quickly and browse your archive.
Easy: Notes.io doesn’t require installation. Just write and share note!
Short: Notes.io’s url just 8 character. You’ll get shorten link of your note when you want to share. (Ex: notes.io/q )
Free: Notes.io works for 14 years and has been free since the day it was started.
You immediately create your first note and start sharing with the ones you wish. If you want to contact us, you can use the following communication channels;
Email: [email protected]
Twitter: http://twitter.com/notesio
Instagram: http://instagram.com/notes.io
Facebook: http://facebook.com/notesio
Regards;
Notes.io Team