def run_one_step(cap1,a,b, newcameramtx, roi, mtx, dist): ret1, frame1 = cap1.read() frame1 = undistort(frame1, newcameramtx, roi, mtx, dist) if ret1: corners1, ids1 = detectAruco(frame1) aruco.drawDetectedMarkers(frame1, corners1, ids1) if not(ids1 is None) and len(ids1)> 0 and (boatAV in ids1 and boatAR in ids1): #le bateau est sur la cam1 ou la cam2 (ou les deux en meme temps) theta = getCap(corners1, ids1) xBoat, yBoat = getPosition(corners1, ids1, frame1) # drawBoat(frame1, xBoat, yBoat) else: #le bateau n'est sur aucune camera print("ERROR : No boat detected") print("bordBasssin = ", bordBassin) print("ids = ", ids1) return None, None, None, 255 else: #le bateau n'est sur aucune camera print("ERROR : No image") return None, None, None, 255 # aruco.drawDetectedMarkers(frame1, corners1, ids1) cv2.imshow("Webcam", frame1) key = cv2.waitKey(1) & 0xFF if math.isnan(theta): return -1,-1,-1, key return xBoat, yBoat,theta, key
# -*- coding: utf-8 -*- """ Created on Wed Aug 14 10:53:47 2019 @author: Quentin """ from calibrate_camera import calibration, undistort import cv2 if __name__ == "__main__": adressCam1 = 'http://*****:*****@169.254.206.22/mjpg/video.mjpg' newcameramtx, roi, mtx, dist = calibration() cap1 = cv2.VideoCapture() cap1.open(adressCam1) ret, frame1 = cap1.read() if ret: frame1 = undistort(frame1, newcameramtx, roi, mtx, dist) cv2.imwrite('fondPlot.png', frame1) else: print("No Cam 1")
plt.xlim(-1, 5) plt.ylim(-1, 4) plt.xlabel('Red = No Calib, Green = Calib') plt.grid() plt.gca().set_aspect('equal', adjustable='box') plt.gca().invert_xaxis() #on inverse l'axe x (correspond au y de l'image) ax.yaxis.tick_right() while (True): key = cv2.waitKey(1) & 0xFF ret, frameNC = cap.read() frameC = undistort(frameNC, newcameramtx, roi, mtx, dist) cornerNC, idsNC = detectAruco(frameNC) aruco.drawDetectedMarkers(frameNC, cornerNC, idsNC) cornerC, idsC = detectAruco(frameC) aruco.drawDetectedMarkers(frameC, cornerC, idsC) cv2.imshow('Frame No Calib', resizeFrame(frameNC)) cv2.imshow('Frame Calib', resizeFrame(frameC)) xnc, ync = getPosition(cornerNC, idsNC, frameNC) xc, yc = getPosition(cornerC, idsC, frameC) if xc is None or xnc is None: print("xc or xnc is None")
y = bordBassin[2][1] - 10 h = abs(bordBassin[12][1] - bordBassin[2][1]) + 10 w = abs(bordBassin[2][0] - bordBassin[3][0]) + 10 crop_img = frame[x:x + w, y:y + h] return crop_img if __name__ == "__main__": newcameramtx, roi, mtx, dist = calibration() cap1 = cv2.VideoCapture() cap1.open(adressCam1) ret, frame1 = cap1.read() if ret: frame1 = undistort(frame1, newcameramtx, roi, mtx, dist) corner, ids = detectAruco(frame1) cap1.release() crop1 = cutImage(frame1, corner, ids, 1) # cv2.imshow("Frame 1", resizeFrame(crop1)) else: crop1 = np.ones((2000, 2000)) cap2 = cv2.VideoCapture() cap2.open(adressCam2) ret, frame2 = cap2.read() if ret: frame2 = undistort(frame2, newcameramtx, roi, mtx, dist) corner, ids = detectAruco(frame2) cap2.release() crop2 = cutImage(frame2, corner, ids, 2)
def chooseCap(newcameramtx, roi, mtx, dist, oldCap, x): """ mise en place d'un oldCap pour optimiser le temps de compilation /!\ Ouvrir et fermer des cap prends bcp de temps /!\ Ne va laguer que lors du changment de caméra renvoie le cap qui a le bateau sur son image """ if oldCap == 1: cap1 = cv2.VideoCapture() cap1.open(adressCam1) ret1, frame1 = cap1.read() frame1 = undistort(frame1, newcameramtx, roi, mtx, dist) corners1, ids1 = detectAruco(frame1) cap1.release() if 4 in ids1 and 5 in ids1: return frame1, corners1, ids1, 1 cap2 = cv2.VideoCapture() cap2.open(adressCam2) ret2, frame2 = cap2.read() frame2 = undistort(frame2, newcameramtx, roi, mtx, dist) corners2, ids2 = detectAruco(frame2) cap2.release() if 4 in ids2 and 5 in ids2: return frame2, corners2, ids2, 2 cap3 = cv2.VideoCapture() cap3.open(adressCam3) ret3, frame3 = cap3.read() frame3 = undistort(frame3, newcameramtx, roi, mtx, dist) corners3, ids3 = detectAruco(frame3) cap3.release() if 4 in ids3 and 5 in ids3: return frame3, corners3, ids3, 3 elif oldCap == 2: if x <= bordBassin[str(1)][0]: cap1 = cv2.VideoCapture() cap1.open(adressCam1) ret1, frame1 = cap1.read() frame1 = undistort(frame1, newcameramtx, roi, mtx, dist) corners1, ids1 = detectAruco(frame1) cap1.release() if 4 in ids1 and 5 in ids1: return frame1, corners1, ids1, 1 cap2 = cv2.VideoCapture() cap2.open(adressCam2) ret2, frame2 = cap2.read() frame2 = undistort(frame2, newcameramtx, roi, mtx, dist) corners2, ids2 = detectAruco(frame2) cap2.release() if 4 in ids2 and 5 in ids2: return frame2, corners2, ids2, 2 cap3 = cv2.VideoCapture() cap3.open(adressCam3) ret3, frame3 = cap3.read() frame3 = undistort(frame3, newcameramtx, roi, mtx, dist) corners3, ids3 = detectAruco(frame3) cap3.release() if 4 in ids3 and 5 in ids3: return frame3, corners3, ids3, 3 #on ne l'atteint jamais ??? cap1 = cv2.VideoCapture() cap1.open(adressCam1) ret1, frame1 = cap1.read() frame1 = undistort(frame1, newcameramtx, roi, mtx, dist) corners1, ids1 = detectAruco(frame1) cap1.release() if 4 in ids1 and 5 in ids1: return frame1, corners1, ids1, 1 elif oldCap == 3: if x <= bordBassin[str(2)][0]: cap2 = cv2.VideoCapture() cap2.open(adressCam2) ret2, frame2 = cap2.read() frame2 = undistort(frame2, newcameramtx, roi, mtx, dist) corners2, ids2 = detectAruco(frame2) cap2.release() if 4 in ids2 and 5 in ids2: return frame2, corners2, ids2, 2 cap3 = cv2.VideoCapture() cap3.open(adressCam3) ret3, frame3 = cap3.read() frame3 = undistort(frame3, newcameramtx, roi, mtx, dist) corners3, ids3 = detectAruco(frame3) cap3.release() if 4 in ids3 and 5 in ids3: return frame3, corners3, ids3, 3 cap2 = cv2.VideoCapture() cap2.open(adressCam2) ret2, frame2 = cap2.read() frame2 = undistort(frame2, newcameramtx, roi, mtx, dist) corners2, ids2 = detectAruco(frame2) cap2.release() if 4 in ids2 and 5 in ids2: return frame2, corners2, ids2, 2 cap1 = cv2.VideoCapture() cap1.open(adressCam1) ret1, frame1 = cap1.read() frame1 = undistort(frame1, newcameramtx, roi, mtx, dist) corners1, ids1 = detectAruco(frame1) cap1.release() if 4 in ids1 and 5 in ids1: return frame1, corners1, ids1, 1 return None, None, None, None