updated tcpClient with new DetectionInfo messages

git-svn-id: http://find-object.googlecode.com/svn/trunk/find_object@370 620bd6b2-0a58-f614-fd9a-1bd335dccda9
This commit is contained in:
matlabbe 2014-08-04 01:35:11 +00:00
parent e6fcc961b8
commit 841eeb1989
2 changed files with 29 additions and 25 deletions

View File

@ -13,6 +13,7 @@ SET(SRC_FILES
) )
SET(INCLUDE_DIRS SET(INCLUDE_DIRS
${CMAKE_CURRENT_SOURCE_DIR}/../../include
${CMAKE_CURRENT_SOURCE_DIR} ${CMAKE_CURRENT_SOURCE_DIR}
${OpenCV_INCLUDE_DIRS} ${OpenCV_INCLUDE_DIRS}
) )
@ -29,12 +30,12 @@ INCLUDE_DIRECTORIES(${INCLUDE_DIRS})
# Add binary called "example" that is built from the source file "main.cpp". # Add binary called "example" that is built from the source file "main.cpp".
# The extension is automatically found. # The extension is automatically found.
ADD_EXECUTABLE(tcpObjectsClient ${SRC_FILES}) ADD_EXECUTABLE(tcpClient ${SRC_FILES})
TARGET_LINK_LIBRARIES(tcpObjectsClient ${LIBRARIES}) TARGET_LINK_LIBRARIES(tcpClient ${LIBRARIES})
SET_TARGET_PROPERTIES( tcpObjectsClient SET_TARGET_PROPERTIES( tcpClient
PROPERTIES OUTPUT_NAME ${PROJECT_PREFIX}-tcpObjectsClient) PROPERTIES OUTPUT_NAME ${PROJECT_PREFIX}-tcpClient)
INSTALL(TARGETS tcpObjectsClient INSTALL(TARGETS tcpClient
RUNTIME DESTINATION bin COMPONENT runtime RUNTIME DESTINATION bin COMPONENT runtime
BUNDLE DESTINATION "${CMAKE_BUNDLE_LOCATION}" COMPONENT runtime) BUNDLE DESTINATION "${CMAKE_BUNDLE_LOCATION}" COMPONENT runtime)

View File

@ -6,7 +6,7 @@
*/ */
#include "TcpClient.h" #include "TcpClient.h"
#include "find_object/DetectionInfo.h"
#include <opencv2/opencv.hpp> #include <opencv2/opencv.hpp>
#include <QtGui/QTransform> #include <QtGui/QTransform>
#include <QtCore/QPointF> #include <QtCore/QPointF>
@ -43,28 +43,29 @@ void TcpClient::readReceivedData()
blockSize_ = 0; blockSize_ = 0;
QVector<float> data; DetectionInfo info;
in >> data; in >> info;
printf("---\n"); printf("---\n");
if(data.size() == 0) if(info.objDetected_.size() == 0)
{ {
printf("(%s) No objects detected.\n", printf("(%s) No objects detected.\n",
QTime::currentTime().toString("HH:mm:ss.zzz").toStdString().c_str()); QTime::currentTime().toString("HH:mm:ss.zzz").toStdString().c_str());
} }
else else
{ {
for(int i=0; i<data.size(); i+=12) QMultiMap<int, QSize>::const_iterator iterSizes = info.objDetectedSizes_.constBegin();
for(QMultiMap<int, QTransform>::const_iterator iter=info.objDetected_.constBegin();
iter!=info.objDetected_.constEnd();
++iter)
{ {
// get data // get data
int id = (int)data[i]; int id = (int)iter.key();
float objectWidth = data[i+1]; float objectWidth = iterSizes.value().width();
float objectHeight = data[i+2]; float objectHeight = iterSizes.value().height();
// Find corners Qt // Find corners Qt
QTransform qtHomography(data[i+3], data[i+4], data[i+5], QTransform qtHomography = iter.value();
data[i+6], data[i+7], data[i+8],
data[i+9], data[i+10], data[i+11]);
QPointF qtTopLeft = qtHomography.map(QPointF(0,0)); QPointF qtTopLeft = qtHomography.map(QPointF(0,0));
QPointF qtTopRight = qtHomography.map(QPointF(objectWidth,0)); QPointF qtTopRight = qtHomography.map(QPointF(objectWidth,0));
@ -84,15 +85,15 @@ void TcpClient::readReceivedData()
{ {
// Find corners OpenCV // Find corners OpenCV
cv::Mat cvHomography(3, 3, CV_32F); cv::Mat cvHomography(3, 3, CV_32F);
cvHomography.at<float>(0,0) = data[i+3]; cvHomography.at<float>(0,0) = qtHomography.m11();
cvHomography.at<float>(1,0) = data[i+4]; cvHomography.at<float>(1,0) = qtHomography.m12();
cvHomography.at<float>(2,0) = data[i+5]; cvHomography.at<float>(2,0) = qtHomography.m13();
cvHomography.at<float>(0,1) = data[i+6]; cvHomography.at<float>(0,1) = qtHomography.m21();
cvHomography.at<float>(1,1) = data[i+7]; cvHomography.at<float>(1,1) = qtHomography.m22();
cvHomography.at<float>(2,1) = data[i+8]; cvHomography.at<float>(2,1) = qtHomography.m23();
cvHomography.at<float>(0,2) = data[i+9]; cvHomography.at<float>(0,2) = qtHomography.m31();
cvHomography.at<float>(1,2) = data[i+10]; cvHomography.at<float>(1,2) = qtHomography.m32();
cvHomography.at<float>(2,2) = data[i+11]; cvHomography.at<float>(2,2) = qtHomography.m33();
std::vector<cv::Point2f> inPts, outPts; std::vector<cv::Point2f> inPts, outPts;
inPts.push_back(cv::Point2f(0,0)); inPts.push_back(cv::Point2f(0,0));
inPts.push_back(cv::Point2f(objectWidth,0)); inPts.push_back(cv::Point2f(objectWidth,0));
@ -108,6 +109,8 @@ void TcpClient::readReceivedData()
outPts.at(2).x, outPts.at(2).y, outPts.at(2).x, outPts.at(2).y,
outPts.at(3).x, outPts.at(3).y); outPts.at(3).x, outPts.at(3).y);
} }
++iterSizes;
} }
} }
} }