本文整理汇总了C++中Communicator::recv方法的典型用法代码示例。如果您正苦于以下问题:C++ Communicator::recv方法的具体用法?C++ Communicator::recv怎么用?C++ Communicator::recv使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Communicator
的用法示例。
在下文中一共展示了Communicator::recv方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: main
int main(){
thread t(waitForKeyPress);
list<CvPoint> opticalFlowVectors;
//set up communicator
Communicator* comm = new Communicator(512, "192.168.2.3", 9002, "*", 9000);
//receive size of one image
char frameWidthBuf[3];
char frameHeightBuf[3];
comm->recv(frameWidthBuf, 3, 0);
comm->recv(frameHeightBuf, 3, 0);
//extract data
int frameWidth = atoi(frameWidthBuf);
int frameHeight = atoi(frameHeightBuf);
int frameSize = frameWidth*frameHeight;
cout << frameSize << endl;
//declare frames
Mat frame1(frameWidth,frameHeight,CV_8UC1);
Mat frame2(frameWidth,frameHeight,CV_8UC1);
//second get the image
comm->recv(frame1.data, frameSize, 0);
//build pyramid for frame 1
buildOpticalFlowPyramid(frame1, pyramid1, cvSize(pyrWindowSize,pyrWindowSize), 3);
//start optical flow algorithm
cout << "Started optical flow algorithm." << endl;
high_resolution_clock::time_point t1 = high_resolution_clock::now();
int iter = 0;
mtx.lock();
while(loop)
{
mtx.unlock();
//recv frame 2
comm->recv(frame2.data, frameSize, 0);
FeatureDetector* detector = new FastFeatureDetector(FASTThreshold,true);
detector->detect(frame1, KeyPointVector);
delete detector;
if(KeyPointVector.size() > 30)
FASTThreshold++;
else
FASTThreshold--;
//build pyramid for frame 2
buildOpticalFlowPyramid(frame2, pyramid2, cvSize(pyrWindowSize,pyrWindowSize), 3);
KeyPoint::convert(KeyPointVector, pointVector1);
//run Lucas Kanade optical flow if features have been found
if(KeyPointVector.size() > 0)
{
calcOpticalFlowPyrLK(pyramid1, pyramid2, pointVector1,
pointVector2, featuresFound, featuresError,
cvSize(pyrWindowSize,pyrWindowSize), 0,
cvTermCriteria(TermCriteria::COUNT+TermCriteria::EPS, 10, 0.2),
0,0.0001);
}
Mat frame3;
cvtColor(frame2, frame3, CV_GRAY2RGB);
for(int i=0; i < pointVector1.size(); i++){
if(featuresFound[i]==0 || featuresError[i]>50)
{
//printf("Error is: %f\n",featuresError[i]);
} else {
CvPoint p0 = cvPoint(
cvRound(pointVector1[i].x),
cvRound(pointVector1[i].y));
CvPoint p1 = cvPoint(
cvRound(pointVector2[i].x),
cvRound(pointVector2[i].y));
line(frame3, p0, p1, CV_RGB(255,0,0), 1, 8, 0);
}
}
ostringstream fileName2;
fileName2 << "flightphoto/flow" << iter <<".jpg";
imwrite(fileName2.str(), frame3);
//store pyramid 2 in pyramid 1
frame1 = frame2.clone();
pyramid1.swap(pyramid2);
//find the average displacement
displacement = trajectoryCalc(pointVector1, pointVector2, featuresFound,
featuresError, KeyPointVector.size());
//Compensate angle: must be done on RPI
//.........这里部分代码省略.........
示例2: main
int main(){
thread t(waitForKeyPress);
list<CvPoint> opticalFlowVectors;
//set up communicator
Communicator* comm = new Communicator(512, "192.168.2.3", 9002, "*", 9000);
//receive size of one image
char frameWidthBuf[3];
char frameHeightBuf[3];
comm->recv(frameWidthBuf, 3, 0);
comm->recv(frameHeightBuf, 3, 0);
//extract data
int frameWidth = atoi(frameWidthBuf);
int frameHeight = atoi(frameHeightBuf);
int frameSize = frameWidth*frameHeight;
//declare frames
Mat frame1(frameWidth,frameHeight,CV_8UC1);
Mat frame2(frameWidth,frameHeight,CV_8UC1);
//second recv the first frame
//recv the size of the encoded frame
char encSizeBuf[6];
comm->recv(encSizeBuf, 6, 0);
int encSize = atoi(encSizeBuf);
vector<uchar> enc = vector<uchar>(encSize);
//recv the encoded frame
comm->recv(&enc[0], encSize, 0);
//decode the frame
qlz_state_decompress *state_decompress = (qlz_state_decompress *)malloc(sizeof(qlz_state_decompress));
qlz_decompress((const char*) &enc[0], (char*) frame1.data, state_decompress);
//build pyramid for frame 1
buildOpticalFlowPyramid(frame1, pyramid1, cvSize(pyrWindowSize,pyrWindowSize), 3);
//start optical flow algorithm
cout << "Started optical flow algorithm." << endl;
high_resolution_clock::time_point t1 = high_resolution_clock::now();
mtx.lock();
while(loop)
{
mtx.unlock();
//recv frame 2
//recv the size of the encoded frame
comm->recv(encSizeBuf, 6, 0);
encSize = atoi(encSizeBuf);
enc = vector<uchar>(encSize);
//recv the encoded frame
comm->recv(&enc[0], encSize, 0);
//uncompress recv data
qlz_decompress((const char*) &enc[0], (char*) frame2.data, state_decompress);
FeatureDetector* detector = new FastFeatureDetector(FASTThreshold,true);
detector->detect(frame1, KeyPointVector);
delete detector;
if(KeyPointVector.size() > 30)
FASTThreshold++;
else
FASTThreshold--;
//build pyramid for frame 2
buildOpticalFlowPyramid(frame2, pyramid2, cvSize(pyrWindowSize,pyrWindowSize), 3);
KeyPoint::convert(KeyPointVector, pointVector1);
//run Lucas Kanade optical flow if features have been found
if(KeyPointVector.size() > 0)
{
calcOpticalFlowPyrLK(pyramid1, pyramid2, pointVector1,
pointVector2, featuresFound, featuresError,
cvSize(pyrWindowSize,pyrWindowSize), 0,
cvTermCriteria(TermCriteria::COUNT+TermCriteria::EPS, 10, 0.2),
0,0.0001);
}
//store pyramid 2 in pyramid 1
frame1 = frame2.clone();
pyramid1.swap(pyramid2);
//find the average displacement
displacement = trajectoryCalc(pointVector1, pointVector2, featuresFound,
featuresError, KeyPointVector.size());
//Compensate angle: must be done on RPI
char xBuf[4]; char yBuf[4];
int xBufLen = sprintf(xBuf, "%d", displacement.x);
int yBufLen = sprintf(yBuf, "%d", displacement.y);
//.........这里部分代码省略.........