Kameraansteuerung
Die ganzen weiteren Fehler, die jetzt auftauchen werden, habe ich Dir schon in meiner ersten Antwort geschrieben. `contours.sort_contours` scheint irgendeine Funktion zu sein, die jemand, der so ein Tutorial zusammengeschustert hat, selbst programmiert oder selbst von irgendwo anders kopiert hat, oder von wo kopiert, wo es von woanders kopiert wurde, wo es von wo anders kopiert wurde, ...
Allerdings bekomme ich bei cv2. imread für gray und edged folgende Fehlermeldung:
Traceback (most recent call last):
File "ProjektOpenCV.py", line 45, in <module>
cv2.imread("gray",gray)
TypeError: only length-1 arrays can be converted to Python scalars
Danke für die Hilfe
Nicolas
Traceback (most recent call last):
File "ProjektOpenCV.py", line 45, in <module>
cv2.imread("gray",gray)
TypeError: only length-1 arrays can be converted to Python scalars
Danke für die Hilfe
Nicolas
-
- User
- Beiträge: 491
- Registriert: Mittwoch 13. November 2019, 08:38
Dabei handelt es sich um die `imutils`-Lib des Autos vom pyimagesearch-Blog. Hier mit einigen Beispielen zur Verwendung zu finden: https://github.com/jrosebr1/imutils.
Dann musst du mal prüfen, was in `gray` tatsächlich steckt. Da sollte ein einzelner Wert drin stecken. Ist das der Fall? Oder willst du eigentlich das Bild anzeigen und imshow("gray", gray) verwenden?
Dann musst du mal prüfen, was in `gray` tatsächlich steckt. Da sollte ein einzelner Wert drin stecken. Ist das der Fall? Oder willst du eigentlich das Bild anzeigen und imshow("gray", gray) verwenden?
@einfachTobi: Fehler behoben.
Allerdings wieder eine Fehlermledung:
Traceback (most recent call last):
File "ProjektOpenCV.py", line 76, in <module>
D = dist.euclidean ((tblX, tlblY), (trbrX, trbrY))
NameError: name 'tblX' is not defined
Code:
Allerdings wieder eine Fehlermledung:
Traceback (most recent call last):
File "ProjektOpenCV.py", line 76, in <module>
D = dist.euclidean ((tblX, tlblY), (trbrX, trbrY))
NameError: name 'tblX' is not defined
Code:
Code: Alles auswählen
from scipy.spatial import distance as dist
from imutils import perspective
from imutils import contours
import picamera
import RPi.GPIO as GPIO
import time
import imutils
import cv2
import numpy as np
import argparse
GPIO.setmode(GPIO.BCM)
GPIO.setup(26, GPIO.IN)
GPIO.input(26)
GPIO.setup(20, GPIO.OUT)
GPIO.setup(16, GPIO.OUT)
GPIO.setup(12, GPIO.OUT)
GPIO.setup(7, GPIO.OUT)
while True:
if GPIO.input(26) == 0:
#LOW - Pegel
# Setup the camera such that it closes
#when we are done with it.
print("About take a picture")
with picamera.PiCamera() as camera:
camera.resolution = (1280,720)
camera.capture("/var/www/html/Projekt/Laiserbild.jpg")
print("Picture taken.")
else:
#HIGH - Pegel
def midpoint(ptA, ptB):
return ((ptA[0] + ptB[0]) * 0.5, (ptA[1] + ptB[1]) * 0.5)
gray = cv2.imread ("/var/www/html/Projekt/Laiserbild.jpg")
edged = cv2.Canny(gray, 50,100)
edged = cv2.dilate(edged, None, iterations=1)
edged = cv2.erode(edged, None, iterations=1)
cnts = cv2.findContours(edged.copy(), cv2.RETR_EXTERNAL,
cv2.CHAIN_APPROX_SIMPLE)
cnts = imutils.grab_contours (cnts)
(cnts, _) = contours.sort_contours(cnts)
colors = ((0, 0, 255), (240, 0, 159), (0, 165, 255), (255, 255, 0), (255, 0, 255))
refObj = None
for c in cnts:
if cv2.contourArea(c) > 1:
continue
box = cv2. minAreaRect (c)
box = cv2. boxPoints (box) if imutils.is_cv2() else cv2.boxPoints (box)
box = np.array(box, dtype="int")
box = perspective.order_points(box)
cX = np.average(box[:,0])
cY = np.average(box[:, 1])
if refObj is None:
(tl, tr, br, bl) = box
(tlblX, tlblY) = midpoint(tl, bl)
(trbrX, trbrY) = midpoint (tr, br)
D = dist.euclidean ((tblX, tlblY), (trbrX, trbrY))
refObj = (box, (cX, CY), D / 0.21)
continue
orig = image.copy()
cv2.drawContrours(orig, [box.astype("int")],-1, (0,255, 0), 2)
cv2.drawContours(orig, [refObj[0].astype("int")], -1, (0, 255, 0), 2)
refCoords = np.vstack([refObj[0], refObj[1]])
objCoords = np.vstack([box, (cX, cY)])
for ((xA, yA), (xB, yB), color) in zip(refCoords, objCoords, colors):
cv2.circle(orig, (int(xA), int(yA)), 5, color, -1)
cv2.circle(orig, (int(xB), int(yB)), 5, color, -1)
cv2.line(orig, (int(xA), int(yA)), (int(xB), int(yB)),
color, 2)
D = dist.euclidean((xA, yA), (xB, yB)) / refObj[2]
(mX, mY) = midpoint((xA, yA), (xB, yB))
cv2.putText(orig, "{:.1f}in".format(D), (int(mX), int(mY - 10)),
cv2.FONT_HERSHEY_SIMPLEX, 0.55, color, 2)
if D <= 0.3:
GPIO.output(20, GPIO.HIGH)
GPIO.output(16, GPIO.LOW)
GPIO.output(12, GPIO.LOW)
GPIO.output(7, GPIO.LOW)
elif (D > 0.3) & (D <= 0.6):
GPIO.output(20, GPIO.LOW)
GPIO.output(16, GPIO.HIGH)
GPIO.output(12, GPIO.LOW)
GPIO.output(7, GPIO.LOW)
elif (D > 0.6) & (D <= 0.9):
GPIO.output(20, GPIO.LOW)
GPIO.output(16, GPIO.LOW)
GPIO.output(12, GPIO.HIGH)
GPIO.output(7, GPIO.LOW)
elif (D > 0.9 )& (D <= 1.2):
GPIO.output(20, GPIO.LOW)
GPIO.output(16, GPIO.LOW)
GPIO.output(12, GPIO.HIGH)
GPIO.output(7, GPIO.LOW)
elif D > 1.2:
GPIO.output(20, GPIO.LOW)
GPIO.output(16, GPIO.LOW)
GPIO.output(12, GPIO.LOW)
GPIO.output(7, GPIO.HIGH)
cv2.imshow("image", gray)
cv2.imshow("Copy", orig)
time.sleep(0.0001)
GPIO.cleanup()
-
- User
- Beiträge: 491
- Registriert: Mittwoch 13. November 2019, 08:38
Wenn dir dieser Fehler nichts sagt, mangelt es entscheidend an den Grundlagen. Mir scheint, dass du keine Ahnung hast, was du da überhaupt machst. Ich persönlich habe wenig Lust dir beim Zusammenschustern und -kopieren von Code zu helfen, den du eh nicht verstehst.
Bitte zunächst die Grundlagen lernen, dann weißt du auch was dieser Fehler bedeutet und wie man ihn behebt: https://docs.python.org/3/tutorial/.
Als weiterer Hinweis: https://www.dropbox.com/s/cqsxfws52gulkyx/drawing.pdf
Bitte zunächst die Grundlagen lernen, dann weißt du auch was dieser Fehler bedeutet und wie man ihn behebt: https://docs.python.org/3/tutorial/.
Als weiterer Hinweis: https://www.dropbox.com/s/cqsxfws52gulkyx/drawing.pdf