Passing Messages from the shoulders of Apache:
A demonstration of distributed image processing
By Matthew Stevenson - miamg@dnikatt.h.reutroboknoshanind@obor.ttagmaiycrehpl.com (July 25, 2011)
This component will:
- Fetch an image
- Fetch face locations
- Display the image with locations
We can reuse a lot of what we have already done to make a Video Display process in C++.
Connect to the broker, VideoTopic, and FaceQueue:
Connection myConnection("localhost:5672", "{username:admin, password:admin}");
myConnection.open();
Session mySession = myConnection.createSession();
Receiver myImageReceiver = mySession.createReceiver("example.VideoTopic; {create: always, node: {type: topic}}");
Receiver myRegionsReceiver = mySession.createReceiver("example.FaceQueue; {create: always, node: {type: queue}}");
Pull an image from the VideoTopic, and ImageRegions from the FaceQueue:
Message message = myImageReceiver.fetch();
PortableImage* pimg = unpackMessage<PortableImage>(message);
IplImage* img = unpackImage(pimg);
Message rgnsMsg = myRegionsReceiver.fetch();
ImageRegions* regions = unpackMessage<ImageRegions>(rgnsMsg);
Draw a circle on the image at each face location:
std::vector<ImageRegion> faces = faceRegions->regions;
for(std::vector<ImageRegion>::const_iterator r = faces.begin(); r != faces.end(); r++){
int x = cvRound((r->x + r->width*0.5));
int y = cvRound((r->y + r->height*0.5));
int radius = cvRound((r->width + r->height)*0.25);
cvDrawCircle(img,cvPoint(x,y),radius,CV_RGB(255,255,255),1);
}
Display the image:
cvShowImage("Window Title", img);
cvWaitKey(5);