Exemplo n.º 1
0
class TargetProcessor:
	def __init__(self):
		self.rectHeight = 0.02
		self.rectWidth = 0.05
		self.focalLen = 480
		self.horizCent = 240
		self.vertiCent = 320
		
	def loadTarget(self, approx):
		'''Does all the higher level calculations.

		Takes an input array of points and sends it to the Target object.
		Then takes the width and height from the target object and calculates Distance, Azimuth, and Altitude.
		'''

		self.dist = 0
		self.azimuth = 0
		self.altitude = 0
		self.targetType = -1

		self.target = Target(approx)
	
		imgWidth = self.target.getWidth()
		imgHeight = self.target.getHeight()
		imgCenter = self.target.getCenter()
		
		rectCentX = imgCenter[0]
		rectCentY = imgCenter[1]
		
		offsetX = float(rectCentX - self.horizCent)
		offsetY = float(rectCentY - self.vertiCent)
		
		self.targetType = self.target.getType()

		self.dist = self.rectWidth * self.focalLen / imgWidth
		self.azimuth = np.arctan(offsetX / self.focalLen) * 180 / math.pi
		self.altitude = np.arctan(offsetY / self.focalLen) * 180 / math.pi

	def getType(self):
		'''Returns the target type'''
	
		return self.targetType

	def getAzimuth(self):
		'''Returns the azimuth'''
		
		return self.azimuth
Exemplo n.º 2
0
from TargetProcessor import TargetProcessor
from Target import Target
import cv2

cameraID = 1

cam = cv2.VideoCapture(cameraID)
detector = TargetDetector()
target = Target()
processor = TargetProcessor()

while(True):
	ret,frame = cam.read()
	if not ret:
		continue
	detector.threshold(frame)
	detector.contour()
	maxX, minX, maxY, minY = detector.getExtrema()
	targetApprox = detector.getTargetApprox()
	width = target.getWidth(maxX, minX)
	height = target.getHeight(maxY, minY)
	centerX, centerY = target.getCenter()
	shape = target.getShape(targetApprox)
	processor.calculate(width, height, centerX, centerY, frame, shape)
	azi = processor.getAzi()
	cv2.imshow("Threshed Image", detector.getThreshed())
	cv2.imshow("Contoured Image", detector.getContour())
	
	print("Azimuth: " + str(azi))
	if (cv2.waitKey(10) == 27):
		break
Exemplo n.º 3
0
detector = TargetDetector()
target = Target()
processor = TargetProcessor()

plusCount = 0
rectCount = 0

while (True):
    ret, frame = cam.read()
    if not ret:
        continue
    detector.threshold(frame)
    detector.contour()
    targetApprox = detector.getTargetApprox()
    width = target.getWidth(targetApprox)
    height = target.getHeight(targetApprox)
    centerX, centerY = target.getCenter()
    shape = target.getShape(targetApprox)
    processor.calculate(width, height, centerX, centerY, detector.getHSV(),
                        shape)
    azi = processor.getAzi()
    alti = processor.getAlti()
    dist = processor.getDist()
    cv2.imshow("Threshed Image", detector.getThreshed())
    cv2.imshow("Contoured Image", detector.getContour())
    print(shape)
    print("Azimuth: " + str(azi))
    print("Altitude: " + str(alti))
    print("Distance: " + str(dist))
    if (cv2.waitKey(10) == 27):
        break
Exemplo n.º 4
0
target = Target()
processor = TargetProcessor()

while (True):
    ret, frame = cam.read(
    )  #Gets the image from the camera (frame) and whether or not it receives a proper image (ret: returns true or false)
    if not ret:
        continue
    detector.threshold(
        frame
    )  #threshold the originial image, the live camera frame in this case
    detector.contours(detector.getThreshed(),
                      frame)  #Contour the image using the threshed image
    HSV = detector.getHSV(
    )  #<--- Gets variables from different classes, mainly for parameters in the processor
    height = target.getHeight(detector.getApprox())  #<---
    width = target.getWidth(detector.getApprox())  #<---
    centerX = target.getCenterX()  #<---
    centerY = target.getCenterY()  #<---
    processor.calculate(
        width, height, centerX, centerY, HSV
    )  #Calculating azimuth, altitude, and distance using the width, height, centerX, centerY, and the HSV image
    dist = processor.getDistance(
    )  #Receive the distance calculated by processor.calculate()
    azi = processor.getAzimuth(
    )  #Receive the azimuth calculated by processor.calculate()
    alti = processor.getAltitude(
    )  #Receive the altitude calculated by processor.calculate()
    print("Distance: " + str(dist))  #Print distance
    print("Azimuth: " + str(azi))  #Print azimuth
    print("Altitude: " + str(alti))  #Print altitude