Beispiel #1
0
class Main(object):
    """description of class"""
    def __init__(self, img):
        self.img = cv2.resize(img, (0, 0), fx = 0.2, fy = 0.2)
        self.detect = TargetDetector(self.img)
        self.detect.threshold([0, 0, 200], [255, 100, 255])
        self.target = Target(self.img, self.detect.findRect())
        self.processor = TargetProcessor(self.img, self.detect.findRect())
    def display(self):
        cv2.imshow("dd", self.img)
        cv2.waitKey(0)
    def distance(self):
        return self.processor.distance(self.target.xmin, self.target.xmax)
    def azimuth(self):
        return self.processor.azimuth(self.target.center(), self.target.img_center())
    def altitude(self):
        return self.processor.altitude(self.target.center(), self.target.img_center())
Beispiel #2
0
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)

#-------------------- FOR LIVE VIDEO (comment above code) ---------------------#
# cam = cv2.VideoCapture(0)
#
# while(True):