30 #include <opencv2/opencv.hpp> 31 #include <QtGui/QTransform> 32 #include <QtCore/QPointF> 33 #include <QtCore/QTime> 40 connect(
this, SIGNAL(error(QAbstractSocket::SocketError)),
this, SLOT(
displayError(QAbstractSocket::SocketError)));
41 connect(
this, SIGNAL(disconnected()),
this, SLOT(
connectionLost()));
47 in.setVersion(QDataStream::Qt_4_0);
51 if (this->bytesAvailable() < (
int)
sizeof(quint16))
70 if(info.objDetected_.size() == 0)
72 printf(
"(%s) No objects detected.\n",
73 QTime::currentTime().toString(
"HH:mm:ss.zzz").toStdString().c_str());
77 QMultiMap<int, QSize>::const_iterator iterSizes = info.objDetectedSizes_.constBegin();
78 for(QMultiMap<int, QTransform>::const_iterator iter=info.objDetected_.constBegin();
79 iter!=info.objDetected_.constEnd();
83 int id = (int)iter.key();
84 float objectWidth = iterSizes.value().width();
85 float objectHeight = iterSizes.value().height();
88 QTransform qtHomography = iter.value();
90 QPointF qtTopLeft = qtHomography.map(QPointF(0,0));
91 QPointF qtTopRight = qtHomography.map(QPointF(objectWidth,0));
92 QPointF qtBottomLeft = qtHomography.map(QPointF(0,objectHeight));
93 QPointF qtBottomRight = qtHomography.map(QPointF(objectWidth,objectHeight));
95 printf(
"(%s) Object %d detected, Qt corners at (%f,%f) (%f,%f) (%f,%f) (%f,%f)\n",
96 QTime::currentTime().toString(
"HH:mm:ss.zzz").toStdString().c_str(),
98 qtTopLeft.x(), qtTopLeft.y(),
99 qtTopRight.x(), qtTopRight.y(),
100 qtBottomLeft.x(), qtBottomLeft.y(),
101 qtBottomRight.x(), qtBottomRight.y());
107 cv::Mat cvHomography(3, 3, CV_32F);
108 cvHomography.at<
float>(0,0) = qtHomography.m11();
109 cvHomography.at<
float>(1,0) = qtHomography.m12();
110 cvHomography.at<
float>(2,0) = qtHomography.m13();
111 cvHomography.at<
float>(0,1) = qtHomography.m21();
112 cvHomography.at<
float>(1,1) = qtHomography.m22();
113 cvHomography.at<
float>(2,1) = qtHomography.m23();
114 cvHomography.at<
float>(0,2) = qtHomography.m31();
115 cvHomography.at<
float>(1,2) = qtHomography.m32();
116 cvHomography.at<
float>(2,2) = qtHomography.m33();
117 std::vector<cv::Point2f> inPts, outPts;
118 inPts.push_back(cv::Point2f(0,0));
119 inPts.push_back(cv::Point2f(objectWidth,0));
120 inPts.push_back(cv::Point2f(0,objectHeight));
121 inPts.push_back(cv::Point2f(objectWidth,objectHeight));
122 cv::perspectiveTransform(inPts, outPts, cvHomography);
124 printf(
"(%s) Object %d detected, CV corners at (%f,%f) (%f,%f) (%f,%f) (%f,%f)\n",
125 QTime::currentTime().toString(
"HH:mm:ss.zzz").toStdString().c_str(),
127 outPts.at(0).x, outPts.at(0).y,
128 outPts.at(1).x, outPts.at(1).y,
129 outPts.at(2).x, outPts.at(2).y,
130 outPts.at(3).x, outPts.at(3).y);
142 case QAbstractSocket::RemoteHostClosedError:
144 case QAbstractSocket::HostNotFoundError:
145 printf(
"Tcp error: The host was not found. Please " 146 "check the host name and port settings.\n");
148 case QAbstractSocket::ConnectionRefusedError:
149 printf(
"The connection was refused by the peer. " 150 "Make sure Find-Object is running, " 151 "and check that the host name and port " 152 "settings are correct.\n");
155 printf(
"The following error occurred: %s.\n", this->errorString().toStdString().c_str());
162 printf(
"Connection lost!\n");
void displayError(QAbstractSocket::SocketError socketError)
TcpClient(QObject *parent=0)
static bool in(Reader::Char c, Reader::Char c1, Reader::Char c2, Reader::Char c3, Reader::Char c4)