Exemple #1
0
cam = cv2.VideoCapture(0)

network = Network()
network.userServer()

while (
        True
):  # while loop for continuous analyzation of frames through video capture
    network.waitForPing()

    ret, frame = cam.read()
    h, w = frame.shape[:
                       2]  # gets the height and width of the frame for analyzation purposes
    imgXcenter = w / 2
    imgYcenter = h / 2
    det = Detector()  # makes a new TargetDetector object
    proc = Processor()  # makes a new TargetProcessor object
    if not ret:  # checks if boolean value ret is false
        continue

    threshold = det.threshold(minThreshold, maxThreshold,
                              frame)  # getting thresholded frame
    det.Contours(threshold)  # finding contours based on thresholded frame
    det.filterContours()  # filtering the contours by size and number
    contours, index, corners, isCross, isRect = det.getContours(
    )  # getting the contours, specific index, and array of corners

    if (corners
            is not None):  # checking if the corners array returned is not null
        target = Target(corners)  # making a new Target object
        Imagewidth = target.getWidth()
Exemple #2
0
lightblue = (255, 221, 0)
# distance = 2.54*18
# actualWidth = 20.3
focalLength = 700
# actualHeight = 25
actualWidth = 50
minThreshold = np.array([0, 0, 236], np.uint8)
maxThreshold = np.array([255, 100, 255], np.uint8)

#----------------------------- FOR STILL FRAMES -------------------------------#
frame = cv2.imread("ReflectiveRectangle.JPG")
h, w = frame.shape[:2]
imgXcenter = w / 2
imgYcenter = h / 2

det = Detector()
threshold = det.getThreshold(minThreshold, maxThreshold, frame)
corners = det.getContours(threshold, frame)

target = Target(corners)
Xmid, Ymid = target.center()

processor = Processor()
d, az, al = processor.findDistanceAzimuth(focalLength, actualWidth,
                                          target.width(), Xmid - imgXcenter,
                                          imgYcenter - Ymid)
processor.displayValues(d, az, al)

cv2.imshow("drawContours", frame)

cv2.waitKey(0)