def drawLinesOnVideo(pt, idx, painter, surface, gt, drawLines): ''' Draw Lines on Video ''' if hasElevationModel(): pt = GetLine3DIntersectionWithPlane(GetSensor(), pt, GetFrameCenter()[2]) scr_x, scr_y = vut.GetInverseMatrix(pt[1], pt[0], gt, surface) center = QPoint(scr_x, scr_y) painter.setPen(LinePen) if len(drawLines) > 1: try: pt = drawLines[idx + 1] if hasElevationModel(): pt = GetLine3DIntersectionWithPlane( GetSensor(), pt, GetFrameCenter()[2]) scr_x, scr_y = vut.GetInverseMatrix(pt[1], pt[0], gt, surface) end = QPoint(scr_x, scr_y) painter.drawLine(center, end) # Draw Start/End Points painter.setPen(DrawToolBar.white_pen) painter.drawPoint(center) painter.drawPoint(end) except Exception: None return
def drawRulerOnVideo(pt, idx, painter, surface, gt, drawRuler): ''' Draw Ruler on Video ''' if hasElevationModel(): pt = GetLine3DIntersectionWithPlane( GetSensor(), pt, GetFrameCenter()[2]) scr_x, scr_y = vut.GetInverseMatrix( pt[1], pt[0], gt, surface) center_pt = pt radius_pt = 5 center = QPoint(scr_x, scr_y) if len(drawRuler) > 1: try: pen = QPen(Qt.red) pen.setWidth(3) painter.setPen(pen) end_pt = drawRuler[idx + 1] if hasElevationModel(): end_pt = GetLine3DIntersectionWithPlane( GetSensor(), end_pt, GetFrameCenter()[2]) scr_x, scr_y = vut.GetInverseMatrix( end_pt[1], end_pt[0], gt, surface) end = QPoint(scr_x, scr_y) painter.drawLine(center, end) font12 = QFont("Arial", 12, weight=QFont.Bold) painter.setFont(font12) distance = round(sphere.distance( (center_pt[0], center_pt[1]), (end_pt[0], end_pt[1])), 2) text = str(distance) + " m" global RulerTotalMeasure RulerTotalMeasure += distance # Draw Start/End Points pen = QPen(Qt.white) pen.setWidth(radius_pt) pen.setCapStyle(Qt.RoundCap) painter.setPen(pen) painter.drawPoint(center) painter.drawPoint(end) painter.drawText(end + QPoint(5, -5), text) pen = QPen(QColor(255, 51, 153)) painter.setPen(pen) painter.drawText(end + QPoint(5, 10), str(round(RulerTotalMeasure, 2)) + " m") except Exception: None return
def drawMeasureDistanceOnVideo(pt, idx, painter, surface, gt, drawMDistance): ''' Draw Measure Distance on Video ''' if hasElevationModel(): pt = GetLine3DIntersectionWithPlane(GetSensor(), pt, GetFrameCenter()[2]) scr_x, scr_y = vut.GetInverseMatrix(pt[1], pt[0], gt, surface) center = QPoint(scr_x, scr_y) if len(drawMDistance) > 1: try: painter.setPen(MeasurePen) end_pt = drawMDistance[idx + 1] if hasElevationModel(): end_pt = GetLine3DIntersectionWithPlane( GetSensor(), end_pt, GetFrameCenter()[2]) scr_x, scr_y = vut.GetInverseMatrix(end_pt[1], end_pt[0], gt, surface) end = QPoint(scr_x, scr_y) painter.drawLine(center, end) painter.setFont(DrawToolBar.bold_12) distance = round( sphere.distance((pt[0], pt[1]), (end_pt[0], end_pt[1])), 2) text = str(distance) + " m" global RulerTotalMeasure RulerTotalMeasure += distance # Line lenght painter.setPen(MeasurePen) painter.drawText(end + QPoint(5, -10), text) painter.setPen(DrawToolBar.white_pen) # Total lenght painter.drawText(end + QPoint(5, 10), str(round(RulerTotalMeasure, 2)) + " m") # Draw Start/End Points painter.drawPoint(center) painter.drawPoint(end) except Exception: None return
def drawPointOnVideo(number, pt, painter, surface, gt): ''' Draw Points on Video ''' if hasElevationModel(): pt = GetLine3DIntersectionWithPlane(GetSensor(), pt, GetFrameCenter()[2]) scr_x, scr_y = vut.GetInverseMatrix(pt[1], pt[0], gt, surface) # don't draw something outside the screen. if scr_x < vut.GetXBlackZone(surface) or scr_y < vut.GetYBlackZone( surface): return if scr_x > vut.GetXBlackZone(surface) + vut.GetNormalizedWidth( surface) or scr_y > vut.GetYBlackZone( surface) + vut.GetNormalizedHeight(surface): return center = QPoint(scr_x, scr_y) painter.setPen(PointPen) painter.drawPoint(center) painter.setFont(DrawToolBar.bold_12) painter.drawText(center + QPoint(5, -5), str(number)) return
def drawPointOnVideo(number, pt, painter, surface, gt): ''' Draw Points on Video ''' if hasElevationModel(): pt = GetLine3DIntersectionWithPlane( GetSensor(), pt, GetFrameCenter()[2]) scr_x, scr_y = vut.GetInverseMatrix( pt[1], pt[0], gt, surface) # don't draw something outside the screen. if scr_x < vut.GetXBlackZone(surface) or scr_y < vut.GetYBlackZone(surface): return if scr_x > vut.GetXBlackZone(surface) + vut.GetNormalizedWidth(surface) or scr_y > vut.GetYBlackZone(surface) + vut.GetNormalizedHeight(surface): return radius = 10 center = QPoint(scr_x, scr_y) pen = QPen(Qt.red) pen.setWidth(radius) pen.setCapStyle(Qt.RoundCap) painter.setPen(pen) painter.drawPoint(center) font12 = QFont("Arial", 12, weight=QFont.Bold) painter.setFont(font12) painter.drawText(center + QPoint(5, -5), str(number)) return
def drawPolygonOnVideo(values, painter, surface, gt): ''' Draw Polygons on Video ''' poly = [] for pt in values: if hasElevationModel(): pt = GetLine3DIntersectionWithPlane( GetSensor(), pt, GetFrameCenter()[2]) scr_x, scr_y = vut.GetInverseMatrix( pt[1], pt[0], gt, surface) center = QPoint(scr_x, scr_y) poly.append(center) poly.append(poly[0]) radius = 3 polygon = QPolygonF(poly) pen = QPen() pen.setColor(Qt.green) pen.setWidth(radius) pen.setCapStyle(Qt.RoundCap) pen.setJoinStyle(Qt.RoundJoin) brush = QBrush() brush.setColor(QColor(176, 255, 128, 28)) brush.setStyle(Qt.SolidPattern) path = QPainterPath() path.addPolygon(polygon) painter.setPen(pen) painter.drawPolygon(polygon) painter.fillPath(path, brush) return
def drawLinesOnVideo(pt, idx, painter, surface, gt, drawLines): ''' Draw Lines on Video ''' if hasElevationModel(): pt = GetLine3DIntersectionWithPlane( GetSensor(), pt, GetFrameCenter()[2]) scr_x, scr_y = vut.GetInverseMatrix( pt[1], pt[0], gt, surface) radius = 3 radius_pt = 5 center = QPoint(scr_x, scr_y) pen = QPen(Qt.yellow) pen.setWidth(radius) pen.setCapStyle(Qt.RoundCap) # pen.setDashPattern([1, 4, 5, 4]) painter.setPen(pen) if len(drawLines) > 1: try: pt = drawLines[idx + 1] if hasElevationModel(): pt = GetLine3DIntersectionWithPlane( GetSensor(), pt, GetFrameCenter()[2]) scr_x, scr_y = vut.GetInverseMatrix( pt[1], pt[0], gt, surface) end = QPoint(scr_x, scr_y) painter.drawLine(center, end) # Draw Start/End Points pen = QPen(Qt.white) pen.setWidth(radius_pt) pen.setCapStyle(Qt.RoundCap) painter.setPen(pen) painter.drawPoint(center) painter.drawPoint(end) except Exception: None return
def drawMeasureAreaOnVideo(values, painter, surface, gt): ''' Draw Measure Area on Video ''' a_value = sphere.polygon_area([values]) poly = [] lat = [] long = [] for pt in values: if hasElevationModel(): pt = GetLine3DIntersectionWithPlane( GetSensor(), pt, GetFrameCenter()[2]) scr_x, scr_y = vut.GetInverseMatrix( pt[1], pt[0], gt, surface) center = QPoint(scr_x, scr_y) poly.append(center) lat.append(pt[0]) long.append(pt[1]) # Fix: Temporary correction # mousePressEvent calls after mouseMoveEvent. # A problem occurs because the centroid is miscalculated. # We remove duplicates values lat = list(dict.fromkeys(lat)) long = list(dict.fromkeys(long)) # Calculate Centroid Position scr_x, scr_y = vut.GetInverseMatrix( sum(long)/len(long), sum(lat)/len(lat), gt, surface) centroid = QPoint(scr_x, scr_y) # Create Poligon polygon = QPolygonF(poly) path = QPainterPath() path.addPolygon(polygon) painter.setFont(DrawToolBar.bold_12) painter.setPen(MeasurePen) painter.drawPolygon(polygon) painter.fillPath(path, MeasureBrush) painter.setPen(DrawToolBar.white_pen) painter.drawPoints(polygon) # Area if a_value >= 10000: painter.drawText(centroid , str(round(a_value/1000000, 2)) + " km²") else: painter.drawText(centroid , str(round(a_value, 2)) + " m²") return
def drawPolygonOnVideo(values, painter, surface, gt): ''' Draw Polygons on Video ''' poly = [] for pt in values: if hasElevationModel(): pt = GetLine3DIntersectionWithPlane(GetSensor(), pt, GetFrameCenter()[2]) scr_x, scr_y = vut.GetInverseMatrix(pt[1], pt[0], gt, surface) center = QPoint(scr_x, scr_y) poly.append(center) polygon = QPolygonF(poly) path = QPainterPath() path.addPolygon(polygon) painter.setPen(PolyPen) painter.drawPolygon(polygon) painter.fillPath(path, PolyBrush) painter.setPen(DrawToolBar.white_pen) painter.drawPoints(polygon) return