|
|
|
@ -8,6 +8,7 @@ from picamera2 import MappedArray, Picamera2, Preview
|
|
|
|
|
from picamera2.previews.qt import QGlPicamera2
|
|
|
|
|
import numpy as np
|
|
|
|
|
from pythonosc import udp_client
|
|
|
|
|
from libcamera import Transform
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def rectFromPoint(center, len, width, axis):
|
|
|
|
@ -85,9 +86,10 @@ def track(frame, roi, dKernel):
|
|
|
|
|
replaceCrop(frame, roiFineOuter, thresh)
|
|
|
|
|
|
|
|
|
|
meanCourse = pow(cropCoarse.mean(), 1)
|
|
|
|
|
#print(meanCourse)
|
|
|
|
|
mean = 0
|
|
|
|
|
direction = 1
|
|
|
|
|
if(meanCourse > 10):
|
|
|
|
|
if(meanCourse > 20):
|
|
|
|
|
# this could potentially be made more efficient by cropping from cropFineOuter
|
|
|
|
|
cropFineInner = crop(frame, roiFineInner)
|
|
|
|
|
# this could potentially be made more efficient by cropping from cropFineInner
|
|
|
|
@ -125,9 +127,9 @@ def picameraToCVTrack():
|
|
|
|
|
#frame = cv2.cvtColor(frame, cv2.COLOR_GRAY2RGB)
|
|
|
|
|
|
|
|
|
|
distanceX = track(frame, roiX, dilationKernel)
|
|
|
|
|
distanceY = track(frame, roiY, dilationKernel)
|
|
|
|
|
distanceY = track(frame, roiY, dilationKernel) * -1
|
|
|
|
|
|
|
|
|
|
oscClient.send_message("/distanceX", distanceX)
|
|
|
|
|
oscClient.send_message("/trackerpos", [distanceX, distanceY])
|
|
|
|
|
|
|
|
|
|
drawRoi(frame, roiX)
|
|
|
|
|
drawRoi(frame, roiY)
|
|
|
|
@ -205,11 +207,12 @@ class MainWindow(QGlPicamera2):
|
|
|
|
|
picam2 = Picamera2()
|
|
|
|
|
#picam2.start_preview(Preview.QTGL)
|
|
|
|
|
#max resolution is (4056, 3040) which is more like 10 fps
|
|
|
|
|
config = picam2.create_preview_configuration(main={"size": (2028, 1520)}, lores={"size": (768, 768), "format": "YUV420"})
|
|
|
|
|
#config = picam2.create_preview_configuration(main={"size": (2028, 1520)}, lores={"size": (768, 768), "format": "YUV420"}, transform=Transform(vflip=False))
|
|
|
|
|
config = picam2.create_preview_configuration(main={"size": (4056, 3040)}, lores={"size": (768, 768), "format": "YUV420"}, transform=Transform(vflip=False))
|
|
|
|
|
picam2.configure(config)
|
|
|
|
|
|
|
|
|
|
app = QApplication([])
|
|
|
|
|
qpicamera2 = MainWindow(picam2, width=1350, height=1350, keep_ar=False)
|
|
|
|
|
qpicamera2 = MainWindow(picam2, width=2000, height=2000, keep_ar=False)
|
|
|
|
|
qpicamera2.setWindowTitle("Qt Picamera2 App")
|
|
|
|
|
|
|
|
|
|
selectedAxis = 'x'
|
|
|
|
@ -218,8 +221,8 @@ l1 = 100
|
|
|
|
|
l2 = 300
|
|
|
|
|
l3 = 40
|
|
|
|
|
w = 20
|
|
|
|
|
roiXCenter = (507, 98)
|
|
|
|
|
roiYCenter = (306, 275)
|
|
|
|
|
roiXCenter = (384, 20)
|
|
|
|
|
roiYCenter = (20, 384)
|
|
|
|
|
roiX = rectsFromPoint(roiXCenter, l1, l2, l3, w, 'x')
|
|
|
|
|
roiY = rectsFromPoint(roiYCenter, l1, l2, l3, w, 'y')
|
|
|
|
|
dilationVal = 75
|
|
|
|
@ -233,13 +236,22 @@ cv2.namedWindow("Frame", cv2.WINDOW_NORMAL)
|
|
|
|
|
cv2.resizeWindow("Frame", 1350, 1350)
|
|
|
|
|
cv2.setMouseCallback("Frame", moveROI)
|
|
|
|
|
|
|
|
|
|
picam2.controls.ScalerCrop = (800, 0, 3040, 3040)
|
|
|
|
|
picam2.controls.Brightness = 0.05
|
|
|
|
|
picam2.controls.Contrast = 0.9
|
|
|
|
|
#picam2.controls.ScalerCrop = (800, 0, 3040, 3040)
|
|
|
|
|
picam2.controls.ScalerCrop = (1375, 550, 1800, 1800)
|
|
|
|
|
picam2.controls.ScalerCrop = (1100, 400, 2125, 2125)
|
|
|
|
|
#picam2.controls.Brightness = 0.2
|
|
|
|
|
picam2.controls.Contrast = 1.1
|
|
|
|
|
#picam2.set_controls({"ExposureValue": 2})
|
|
|
|
|
#picam2.set_controls({"ColourGains": (0, 0)})
|
|
|
|
|
#picam2.set_controls({"Sharpness": 10})
|
|
|
|
|
#picam2.set_controls({"AeEnable": False})
|
|
|
|
|
#picam2.set_controls({"ExposureTime": 1700})
|
|
|
|
|
picam2.set_controls({"Saturation": 0})
|
|
|
|
|
|
|
|
|
|
(w0, h0) = picam2.stream_configuration("main")["size"]
|
|
|
|
|
(w1, h1) = picam2.stream_configuration("lores")["size"]
|
|
|
|
|
s1 = picam2.stream_configuration("lores")["stride"]
|
|
|
|
|
print(h1)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
picam2.start()
|
|
|
|
|