FPoint
.h
#ifndef FPOINT_H
#define FPOINT_H
class FPoint
{
public:
FPoint(float x, float y);
float x, y;
FPoint operator+(const FPoint& b) {
return FPoint(x + b.x, y + b.y);
}
FPoint operator-(const FPoint& b) {
return FPoint(x - b.x, y - b.y);
}
};
#endif // FPOINT_H
.cpp
#include "fpoint.h"
FPoint::FPoint(float x, float y) {
this.x = x;
this.y = y;
}
PLabel
.h
#include <QLabel>
#include <QPoint>
#include <QMouseEvent>
#include <QPainter>
#include <QWidget>
#include <iostream>
#include <opencv2/core.hpp>
#include <vector>
#include "fpoint.h"
class RectLabel : public QLabel {
Q_OBJECT
public:
RectLabel(QWidget *parent = nullptr);
protected:
void paintEvent(QPaintEvent *event);
void mouseMoveEvent(QMouseEvent *event);
void mousePressEvent(QMouseEvent *event);
void mouseReleaseEvent(QMouseEvent *event);
int doubleCompare(double x);
bool between2Points(FPoint &a1, FPoint &a2, FPoint &p);
double cross(FPoint a, FPoint b);
double distance2Points(FPoint p1, FPoint p2);
void drawLine(QPainter &paint, FPoint &po1, FPoint&po2);
signals:
void sendRect(cv::Rect2f rt);
private:
std::vector<FPoint> points;
int selectIdx = 0;
bool stateSelect = false;
float startX = 0, startY = 0;
float endX = 0, endY = 0;
};
.CPP
#pragma execution_character_set("utf-8")
#include "rect