Exemplo n.º 1
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()
        Xmid, Ymid = target.getCenter()
Exemplo n.º 2
0
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)

#-------------------- FOR LIVE VIDEO (comment above code) ---------------------#
# cam = cv2.VideoCapture(0)
#
# while(True):
#     ret, frame = cam.read()
#     h,w = frame.shape[:2]