{"id":563,"date":"2026-06-11T13:05:01","date_gmt":"2026-06-11T05:05:01","guid":{"rendered":"https:\/\/projectleon.net\/make\/blog\/agv-line-follower-opencv-raspberry-pi-factory-farsi\/"},"modified":"2026-06-11T13:05:02","modified_gmt":"2026-06-11T05:05:02","slug":"agv-line-follower-opencv-raspberry-pi-factory-farsi","status":"publish","type":"post","link":"https:\/\/projectleon.net\/make\/blog\/agv-line-follower-opencv-raspberry-pi-factory-farsi\/","title":{"rendered":"\u0633\u0627\u062e\u062a AGV \u062f\u0646\u0628\u0627\u0644\u200c\u06a9\u0646\u0646\u062f\u0647 \u062e\u0637 \u0628\u0627 OpenCV \u0648 Raspberry Pi: \u0645\u0627\u0634\u06cc\u0646 \u0647\u0648\u0634\u0645\u0646\u062f \u06a9\u0627\u0631\u062e\u0627\u0646\u0647 (\u0641\u0627\u0631\u0633\u06cc)"},"content":{"rendered":"<div class='hero-image-container' style='margin-bottom:28px;border-radius:14px;overflow:hidden;box-shadow:0 4px 18px rgba(0,0,0,0.08)'>\n<img src='https:\/\/projectleon.net\/make\/wp-content\/uploads\/2026\/06\/post86-agv-linefollower.jpg' alt='AGV \u062f\u0646\u0628\u0627\u0644\u200c\u06a9\u0646\u0646\u062f\u0647 \u062e\u0637 OpenCV Raspberry Pi' style='width:100%;height:auto;display:block' loading='eager'\/>\n<\/div>\n<div class='beginner-intro' style='background:#f0f7ff;border-right:4px solid #2e5fb6;padding:16px 20px;border-radius:10px;margin-bottom:22px'>\n<h2 style='margin-top:0'>AGV \u062f\u0646\u0628\u0627\u0644\u200c\u06a9\u0646\u0646\u062f\u0647 \u062e\u0637 \u0628\u0627 OpenCV \u0686\u06cc\u0633\u062a\u061f (\u0645\u0628\u062a\u062f\u06cc)<\/h2>\n<p>\u062f\u0631 \u06a9\u0627\u0631\u062e\u0627\u0646\u0647\u200c\u0647\u0627\u06cc \u0645\u062f\u0631\u0646\u060c <strong>AGV<\/strong>\u0647\u0627 (\u0631\u0628\u0627\u062a\u200c\u0647\u0627\u06cc \u062d\u0645\u0644\u200c\u0648\u0646\u0642\u0644 \u062e\u0648\u062f\u06a9\u0627\u0631) \u0645\u0639\u0645\u0648\u0644\u0627\u064b \u06cc\u06a9 <strong>\u062e\u0637 \u0631\u0646\u06af\u06cc \u0631\u0648\u06cc \u06a9\u0641<\/strong> \u0631\u0627 \u062f\u0646\u0628\u0627\u0644 \u0645\u06cc\u200c\u06a9\u0646\u0646\u062f \u2014 \u06cc\u06a9 \u0646\u0648\u0627\u0631 \u0632\u0631\u062f \u06cc\u0627 \u0633\u0641\u06cc\u062f \u06a9\u0647 \u0645\u0633\u06cc\u0631 \u062d\u0631\u06a9\u062a \u0631\u0627 \u0645\u0634\u062e\u0635 \u0645\u06cc\u200c\u06a9\u0646\u062f. \u0627\u06cc\u0646 \u0631\u0648\u0634 \u0633\u0627\u062f\u0647\u200c\u062a\u0631 \u0648 \u0627\u0631\u0632\u0627\u0646\u200c\u062a\u0631 \u0627\u0632 GPS \u06cc\u0627 LiDAR \u0627\u0633\u062a.<\/p>\n<p><strong>OpenCV<\/strong> \u06cc\u06a9 \u06a9\u062a\u0627\u0628\u062e\u0627\u0646\u0647 \u067e\u0631\u062f\u0627\u0632\u0634 \u062a\u0635\u0648\u06cc\u0631 \u0645\u062a\u0646\u200c\u0628\u0627\u0632 \u0627\u0633\u062a \u06a9\u0647 \u0631\u0648\u06cc Raspberry Pi \u0627\u062c\u0631\u0627 \u0645\u06cc\u200c\u0634\u0648\u062f. \u062f\u0648\u0631\u0628\u06cc\u0646 <strong>Pi Camera<\/strong> \u062a\u0635\u0648\u06cc\u0631 \u06a9\u0641 \u0631\u0627 \u0645\u06cc\u200c\u06af\u06cc\u0631\u062f\u060c OpenCV \u062e\u0637 \u0631\u0627 \u0634\u0646\u0627\u0633\u0627\u06cc\u06cc \u0645\u06cc\u200c\u06a9\u0646\u062f\u060c \u0648 \u06cc\u06a9 \u06a9\u0646\u062a\u0631\u0644\u0631 <strong>PID<\/strong> \u0645\u0648\u062a\u0648\u0631\u0647\u0627 \u0631\u0627 \u062a\u0646\u0638\u06cc\u0645 \u0645\u06cc\u200c\u06a9\u0646\u062f \u062a\u0627 \u0631\u0628\u0627\u062a \u0631\u0648\u06cc \u062e\u0637 \u0628\u0645\u0627\u0646\u062f.<\/p>\n<\/div>\n<div style='border:1px solid #d8d8d8;padding:18px 20px;border-radius:12px;background:#fafafa;margin-bottom:22px'>\n<h2 style='margin-top:0'>\u0645\u062d\u0635\u0648\u0644\u06cc \u06a9\u0647 \u0645\u06cc\u200c\u0633\u0627\u0632\u06cc\u062f<\/h2>\n<p>\u06cc\u06a9 AGV \u062f\u0646\u0628\u0627\u0644\u200c\u06a9\u0646\u0646\u062f\u0647 \u062e\u0637 \u0628\u0627 Pi Camera \u0648 OpenCV \u0628\u0627 \u0633\u0631\u0639\u062a \u06f0.\u06f5m\/s.<\/p>\n<ul>\n<li><strong>\u0647\u0632\u06cc\u0646\u0647:<\/strong> \u06f2 \u062a\u0627 \u06f3 \u0645\u06cc\u0644\u06cc\u0648\u0646 \u062a\u0648\u0645\u0627\u0646<\/li>\n<li><strong>\u0633\u0631\u0639\u062a:<\/strong> \u06f0.\u06f3-\u06f0.\u06f5 m\/s<\/li>\n<li><strong>\u062f\u0642\u062a:<\/strong> \u00b1\u06f1cm \u0627\u0632 \u0645\u0631\u06a9\u0632 \u062e\u0637<\/li>\n<\/ul>\n<\/div>\n<p><svg viewBox='0 0 860 200' width='100%' xmlns='http:\/\/www.w3.org\/2000\/svg' style='background:#f5f5f5;border:1px solid #e0e0e0;border-radius:12px;margin-bottom:22px'>\n<rect x='0' y='0' width='860' height='200' rx='12' fill='#f5f5f5'\/>\n<line x1='430' y1='20' x2='430' y2='180' stroke='#ffeb3b' stroke-width='20' opacity='0.8'\/>\n<rect x='360' y='80' width='140' height='60' rx='10' fill='#555' stroke='#333'\/>\n<text x='430' y='113' text-anchor='middle' font-size='11' font-family='Tahoma' fill='#fff'>AGV + Pi Camera<\/text>\n<circle cx='385' cy='178' r='15' fill='#333'\/>\n<circle cx='475' cy='178' r='15' fill='#333'\/>\n<line x1='430' y1='160' x2='430' y2='195' stroke='#e53935' stroke-width='2' stroke-dasharray='4,2'\/>\n<text x='450' y='50' font-size='11' font-family='Tahoma' fill='#888'>\u062e\u0637 \u0632\u0631\u062f<\/text>\n<text x='620' y='113' font-size='11' font-family='Tahoma' fill='#e53935'>\u062e\u0637\u0627\u06cc \u0627\u0646\u062d\u0631\u0627\u0641 = \u06f2cm<\/text>\n<text x='430' y='195' text-anchor='middle' font-size='13' font-family='Tahoma' fill='#888'>Pi Camera \u2192 OpenCV \u2192 PID \u2192 \u0645\u0648\u062a\u0648\u0631<\/text>\n<\/svg><\/p>\n<h2>\u06a9\u062f Python \u2014 Line Following \u0628\u0627 OpenCV<\/h2>\n<pre style='background:#1e1e1e;color:#d4d4d4;padding:16px;border-radius:10px;overflow-x:auto;font-size:13px'><code class='language-python'>\nimport cv2\nimport numpy as np\nimport RPi.GPIO as GPIO\nimport time\n\n# \u062a\u0646\u0638\u06cc\u0645 \u0645\u0648\u062a\u0648\u0631 L298N\nIN1,IN2,IN3,IN4=17,18,27,22\nENA,ENB=12,13  # PWM\nGPIO.setmode(GPIO.BCM)\nfor p in [IN1,IN2,IN3,IN4,ENA,ENB]: GPIO.setup(p,GPIO.OUT)\npwmA = GPIO.PWM(ENA,100); pwmB = GPIO.PWM(ENB,100)\npwmA.start(0); pwmB.start(0)\n\ndef setMotors(l,r):\n    l = max(-100, min(100, l))\n    r = max(-100, min(100, r))\n    GPIO.output(IN1, l>0); GPIO.output(IN2, l<0)\n    GPIO.output(IN3, r>0); GPIO.output(IN4, r<0)\n    pwmA.ChangeDutyCycle(abs(l)); pwmB.ChangeDutyCycle(abs(r))\n\ncap = cv2.VideoCapture(0)\ncap.set(3,320); cap.set(4,240)\n\nKp,Ki,Kd = 0.5, 0.001, 0.1\nintegral = prev_error = 0\n\nwhile True:\n    ret, frame = cap.read()\n    roi = frame[180:240, :]        # \u0641\u0642\u0637 \u06f6\u06f0 \u067e\u06cc\u06a9\u0633\u0644 \u067e\u0627\u06cc\u06cc\u0646\n    gray = cv2.cvtColor(roi, cv2.COLOR_BGR2GRAY)\n    _, binary = cv2.threshold(gray, 80, 255, cv2.THRESH_BINARY_INV)\n\n    M = cv2.moments(binary)\n    if M[\"m00\"] > 0:\n        cx = int(M[\"m10\"] \/ M[\"m00\"])\n        error = cx - 160          # \u0627\u0646\u062d\u0631\u0627\u0641 \u0627\u0632 \u0645\u0631\u06a9\u0632\n        integral += error\n        derivative = error - prev_error\n        correction = Kp*error + Ki*integral + Kd*derivative\n        prev_error = error\n        setMotors(int(60-correction), int(60+correction))\n    else:\n        setMotors(0,0)   # \u062e\u0637 \u067e\u06cc\u062f\u0627 \u0646\u0634\u062f\n<\/code><\/pre>\n<h2>\u0686\u06a9\u200c\u0644\u06cc\u0633\u062a \u062a\u0646\u0638\u06cc\u0645 PID<\/h2>\n<table style='width:100%;border-collapse:collapse;margin-bottom:18px'>\n<thead>\n<tr style='background:#e8f0fe'>\n<th style='padding:9px;border:1px solid #ddd;text-align:right'>\u0645\u0634\u06a9\u0644<\/th>\n<th style='padding:9px;border:1px solid #ddd;text-align:right'>\u062a\u0646\u0638\u06cc\u0645<\/th>\n<\/tr>\n<\/thead>\n<tbody>\n<tr>\n<td style='padding:8px;border:1px solid #ddd'>\u0631\u0628\u0627\u062a \u062a\u0646\u062f \u0686\u0631\u062e \u0645\u06cc\u200c\u0632\u0646\u062f<\/td>\n<td style='padding:8px;border:1px solid #ddd'>Kp \u0631\u0627 \u06a9\u0627\u0647\u0634 \u062f\u0647\u06cc\u062f<\/td>\n<\/tr>\n<tr style='background:#fafafa'>\n<td style='padding:8px;border:1px solid #ddd'>\u0631\u0628\u0627\u062a \u0627\u0632 \u062e\u0637 \u062e\u0627\u0631\u062c \u0645\u06cc\u200c\u0634\u0648\u062f<\/td>\n<td style='padding:8px;border:1px solid #ddd'>Kp \u0631\u0627 \u0627\u0641\u0632\u0627\u06cc\u0634 \u062f\u0647\u06cc\u062f<\/td>\n<\/tr>\n<tr>\n<td style='padding:8px;border:1px solid #ddd'>\u0644\u0631\u0632\u0634 \u062f\u0631 \u0645\u0633\u06cc\u0631 \u0645\u0633\u062a\u0642\u06cc\u0645<\/td>\n<td style='padding:8px;border:1px solid #ddd'>Kd \u0631\u0627 \u0627\u0641\u0632\u0627\u06cc\u0634 \u062f\u0647\u06cc\u062f<\/td>\n<\/tr>\n<tr style='background:#fafafa'>\n<td style='padding:8px;border:1px solid #ddd'>\u062f\u0631 \u067e\u06cc\u0686 \u062e\u0627\u0631\u062c \u0645\u06cc\u200c\u0634\u0648\u062f<\/td>\n<td style='padding:8px;border:1px solid #ddd'>Ki \u0631\u0627 \u06a9\u0645\u06cc \u0627\u0641\u0632\u0627\u06cc\u0634 \u062f\u0647\u06cc\u062f<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p><svg viewBox='0 0 860 200' width='100%' xmlns='http:\/\/www.w3.org\/2000\/svg' style='background:#fff;border:1px solid #e0e0e0;border-radius:12px;margin-bottom:22px'>\n<rect x='40' y='75' width='155' height='60' rx='12' fill='#8bd3dd' stroke='#1f6f78' stroke-width='2'\/>\n<rect x='245' y='75' width='155' height='60' rx='12' fill='#f7d794' stroke='#a06d00' stroke-width='2'\/>\n<rect x='450' y='75' width='155' height='60' rx='12' fill='#b7e4a0' stroke='#3a7a1e' stroke-width='2'\/>\n<rect x='655' y='75' width='165' height='60' rx='12' fill='#e8f4ff' stroke='#3a60c0' stroke-width='2'\/>\n<line x1='195' y1='105' x2='245' y2='105' stroke='#555' stroke-width='2.5'\/>\n<line x1='400' y1='105' x2='450' y2='105' stroke='#555' stroke-width='2.5'\/>\n<line x1='605' y1='105' x2='655' y2='105' stroke='#555' stroke-width='2.5'\/>\n<text x='117' y='100' text-anchor='middle' font-size='12' font-family='Tahoma'>Pi Camera<\/text>\n<text x='117' y='115' text-anchor='middle' font-size='11' font-family='Tahoma'>\u06f3\u06f2\u06f0\u00d7\u06f2\u06f4\u06f0px<\/text>\n<text x='322' y='100' text-anchor='middle' font-size='12' font-family='Tahoma'>OpenCV<\/text>\n<text x='322' y='115' text-anchor='middle' font-size='11' font-family='Tahoma'>Threshold+Moment<\/text>\n<text x='527' y='100' text-anchor='middle' font-size='12' font-family='Tahoma'>PID Controller<\/text>\n<text x='527' y='115' text-anchor='middle' font-size='11' font-family='Tahoma'>\u062e\u0637\u0627 \u2192 \u062a\u0635\u062d\u06cc\u062d<\/text>\n<text x='737' y='100' text-anchor='middle' font-size='12' font-family='Tahoma'>L298N<\/text>\n<text x='737' y='115' text-anchor='middle' font-size='11' font-family='Tahoma'>\u0645\u0648\u062a\u0648\u0631 AGV<\/text>\n<text x='430' y='175' text-anchor='middle' font-size='13' font-family='Tahoma' fill='#666'>AGV \u062e\u0637\u200c\u0631\u0648 \u2014 Pi Camera \u2192 OpenCV \u2192 PID \u2192 \u0645\u0648\u062a\u0648\u0631<\/text>\n<\/svg><\/p>\n<h2>\u0648\u06cc\u062f\u0626\u0648\u0647\u0627\u06cc \u0622\u0645\u0648\u0632\u0634\u06cc<\/h2>\n<div style='display:grid;grid-template-columns:repeat(auto-fit,minmax(300px,1fr));gap:18px;margin:20px 0'>\n<iframe width='100%' height='315' src='https:\/\/www.youtube.com\/embed\/5YCZXeGW8s0' title='AGV Line Follower OpenCV Raspberry Pi' frameborder='0' allow='accelerometer;autoplay;clipboard-write;encrypted-media;gyroscope;picture-in-picture' allowfullscreen><\/iframe><br \/>\n<iframe width='100%' height='315' src='https:\/\/www.youtube.com\/embed\/Nd2au1BKWZ8' title='PID Line Following Robot Python OpenCV' frameborder='0' allow='accelerometer;autoplay;clipboard-write;encrypted-media;gyroscope;picture-in-picture' allowfullscreen><\/iframe>\n<\/div>\n<h2>\u0645\u0646\u0627\u0628\u0639 \u0628\u06cc\u0634\u062a\u0631<\/h2>\n<ul>\n<li><a href='https:\/\/www.aparat.com\/result\/AGV_%D8%AF%D9%86%D8%A8%D8%A7%D9%84_%D8%AE%D8%B7_%D8%B1%D8%A8%D8%A7%D8%AA' target='_blank'>\u0622\u067e\u0627\u0631\u0627\u062a: AGV \u062f\u0646\u0628\u0627\u0644 \u062e\u0637 \u0631\u0628\u0627\u062a \u0641\u0627\u0631\u0633\u06cc<\/a><\/li>\n<li><a href='https:\/\/docs.opencv.org\/4.x\/d7\/d4d\/tutorial_py_thresholding.html' target='_blank'>OpenCV: Image Thresholding Tutorial<\/a><\/li>\n<\/ul>\n","protected":false},"excerpt":{"rendered":"<p>\u0622\u0645\u0648\u0632\u0634 \u0633\u0627\u062e\u062a AGV \u062f\u0646\u0628\u0627\u0644\u200c\u06a9\u0646\u0646\u062f\u0647 \u062e\u0637 \u0628\u0627 \u062f\u0648\u0631\u0628\u06cc\u0646 Pi Camera \u0648 OpenCV\u061b \u062a\u0634\u062e\u06cc\u0635 \u062e\u0637 \u0628\u0627 Binary Thresholding\u060c \u06a9\u0646\u062a\u0631\u0644 PID\u060c \u0633\u0631\u0639\u062a \u06f0.\u06f5 \u0645\u062a\u0631 \u0628\u0631 \u062b\u0627\u0646\u06cc\u0647\u060c \u0645\u0646\u0627\u0633\u0628 \u0628\u0631\u0627\u06cc \u0634\u0628\u06cc\u0647\u200c\u0633\u0627\u0632\u06cc \u062e\u0637 \u06a9\u0627\u0631\u062e\u0627\u0646\u0647.<\/p>\n","protected":false},"author":1,"featured_media":562,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"pagelayer_contact_templates":[],"_pagelayer_content":"","footnotes":""},"categories":[16,20],"tags":[59,349,73,23,50,348,235,350],"class_list":["post-563","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-ugv","category-projects-2","tag-agv","tag-opencv","tag-pid","tag-raspberry-pi","tag-50","tag-348","tag-235","tag-350"],"_links":{"self":[{"href":"https:\/\/projectleon.net\/make\/wp-json\/wp\/v2\/posts\/563","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/projectleon.net\/make\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/projectleon.net\/make\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/projectleon.net\/make\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/projectleon.net\/make\/wp-json\/wp\/v2\/comments?post=563"}],"version-history":[{"count":1,"href":"https:\/\/projectleon.net\/make\/wp-json\/wp\/v2\/posts\/563\/revisions"}],"predecessor-version":[{"id":564,"href":"https:\/\/projectleon.net\/make\/wp-json\/wp\/v2\/posts\/563\/revisions\/564"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/projectleon.net\/make\/wp-json\/wp\/v2\/media\/562"}],"wp:attachment":[{"href":"https:\/\/projectleon.net\/make\/wp-json\/wp\/v2\/media?parent=563"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/projectleon.net\/make\/wp-json\/wp\/v2\/categories?post=563"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/projectleon.net\/make\/wp-json\/wp\/v2\/tags?post=563"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}