// ###################################################################### void TaskRelevanceMapSocial::inputFrame(const InputFrame& f) { const Dims mapdims = f.getDims(); const int sml = itsLevelSpec.getVal().mapLevel(); const float EyeVal = 128.0F, MouthVal = 64.0F, FaceVal = 32.0F, BodyVal = 16.0F, PersonVal = 4.0F, BkgdVal = 1.0F; Image<float> BigMap; BigMap.resize(mapdims, true); BigMap.clear(1.0F); Scene sceneData = itsObjectsInfo->getSceneData(itsFrame); // loop through all the regions on a given frame and assign z-stack order std::vector<float> weights(itsNumObjects, 1.0F); for (std::vector<Object>::iterator itrObject = sceneData.objects.begin(); itrObject != sceneData.objects.end(); itrObject++) { uint idx = (*itrObject).id; std::string ObjName = toLowerCase(itsObjectsNames[idx]); if (ObjName.find("eye") != std::string::npos) {weights[idx] = EyeVal;} else if (ObjName.find("mouth") != std::string::npos) {weights[idx] = MouthVal;} else if (ObjName.find("head") != std::string::npos || ObjName.find("face") != std::string::npos) {weights[idx] = FaceVal;} else if (ObjName.find("body") != std::string::npos) {weights[idx] = BodyVal;} else if (ObjName.find("person") != std::string::npos || ObjName.find("people") != std::string::npos || ObjName.find("man") != std::string::npos || ObjName.find("woman") != std::string::npos) {weights[idx] = PersonVal;} else {weights[idx] = BkgdVal;} } uint i,j,tmp; // sort z-stack weights const uint numInScene = sceneData.objects.size(); std::vector<uint> zorder(numInScene); for (i = 0; i < numInScene; i++) zorder[i] = i; for (i = 0; i < numInScene; i++) for (j = 0; j < numInScene-i-1; j++) if(weights[sceneData.objects[zorder[j]].id] > weights[sceneData.objects[zorder[j+1]].id]) { tmp = zorder[j]; zorder[j] = zorder[j+1]; zorder[j+1] = tmp; } // fill BigMap from bottom of z-stack to top // todo: enforce C0/C1 continuity by some poisson problem? for (i = 0; i < numInScene; i++) { Object iObj = sceneData.objects[zorder[i]]; drawFilledPolygon(BigMap, iObj.polygon, weights[iObj.id]); } itsMap = rescale(BigMap, mapdims.w() >> sml, mapdims.h() >> sml); itsFrame++; }
int main (int argc,char *argv[]) { int videofd1 = open("/dev/video0",O_RDWR); int videofd2 = open("/dev/video0",O_RDWR); IDirectFBSurface *SurfaceHandle; IDirectFBSurface *SurfaceHandle2; void *ptr,*ptr2; int pitch,pitch2; int colour_palette[256]; int colour_palette2_real[256]; /* random... */ int *colour_palette2 = colour_palette2_real; int is_lut8; is_lut8 = (argc > 1 && !strcmp (argv[1], "both")); memset(&colour_palette,0x0,4*256); //memset(&colour_palette[1],0xff,255*4); colour_palette[0] = 0xff000000; // black colour_palette[1] = 0xffff0000; // red colour_palette[2] = 0xff00ff00; // green colour_palette[3] = 0xff0000ff; // blue colour_palette[4] = 0xffffffff; // white colour_palette[5] = 0x80808000; // half-transp yellow colour_palette[6] = 0x00000000; // transp black if (videofd1 < 0) perror("Couldn't open video device 1\n"); if (videofd2 < 0) perror("Couldn't open video device 2\n"); v4l2_list_outputs (videofd1); fb_make_transparent(); init_dfb(&SurfaceHandle,is_lut8); init_dfb(&SurfaceHandle2,1); v4l2_set_output_by_name (videofd1, "RGB1"); v4l2_set_output_by_name (videofd2, "RGB2"); init_v4l(videofd1,0,0,1280,720,is_lut8); init_v4l(videofd2,0,0,1280,720,1); printf("%s:%d\n",__FUNCTION__,__LINE__); // memcpy (colour_palette, colour_palette2, sizeof (colour_palette)); colour_palette2 = colour_palette; { int coords = 60; int size = 100; // clear if (!is_lut8) SurfaceHandle->Clear (SurfaceHandle, 0x00, 0x00, 0x00, 0x00); else { SurfaceHandle->SetColorIndex (SurfaceHandle, 0x6); SurfaceHandle->FillRectangle (SurfaceHandle, 0, 0, 600, 600); } // White if (is_lut8) SurfaceHandle->SetColorIndex (SurfaceHandle, 0x4); else SurfaceHandle->SetColor (SurfaceHandle, 0xff, 0xff, 0xff, 0xff); SurfaceHandle->FillRectangle (SurfaceHandle, coords, coords, size, size); coords += size; // Red if (is_lut8) SurfaceHandle->SetColorIndex (SurfaceHandle, 0x1); else SurfaceHandle->SetColor (SurfaceHandle, 0xff, 0x00, 0x00, 0xff); SurfaceHandle->FillRectangle (SurfaceHandle, coords, coords, size, size); coords += size; // Green if (is_lut8) SurfaceHandle->SetColorIndex (SurfaceHandle, 0x2); else SurfaceHandle->SetColor (SurfaceHandle, 0x00, 0xff, 0x00, 0xff); SurfaceHandle->FillRectangle (SurfaceHandle, coords, coords, size, size); coords += size; // Blue if (is_lut8) SurfaceHandle->SetColorIndex (SurfaceHandle, 0x3); else SurfaceHandle->SetColor (SurfaceHandle, 0x00, 0x00, 0xff, 0xff); SurfaceHandle->FillRectangle (SurfaceHandle, coords, coords, size, size); coords += size; // half transp yellow if (is_lut8) SurfaceHandle->SetColorIndex (SurfaceHandle, 0x5); else SurfaceHandle->SetColor (SurfaceHandle, 0x80, 0x80, 0x00, 0x80); SurfaceHandle->FillRectangle (SurfaceHandle, coords, coords, size, size); coords += size; // transp if (is_lut8) SurfaceHandle->SetColorIndex (SurfaceHandle, 0x6); else SurfaceHandle->SetColor (SurfaceHandle, 0x00, 0x00, 0x00, 0x00); SurfaceHandle->FillRectangle (SurfaceHandle, coords, coords, size, size); coords += size; } { int xcoords = 60 + (100 * 6), ycoords = 60; int size = 100; // clear SurfaceHandle2->SetColorIndex (SurfaceHandle2, 0x6); SurfaceHandle2->FillRectangle (SurfaceHandle2, 220, 220, 440, 440); // transp SurfaceHandle2->SetColorIndex (SurfaceHandle2, 0x6); SurfaceHandle2->FillRectangle (SurfaceHandle2, xcoords, ycoords, size, size); xcoords -= size; ycoords += size; // half transp yellow SurfaceHandle2->SetColorIndex (SurfaceHandle2, 0x5); SurfaceHandle2->FillRectangle (SurfaceHandle2, xcoords, ycoords, size, size); xcoords -= size; ycoords += size; // Blue SurfaceHandle2->SetColorIndex (SurfaceHandle2, 0x3); SurfaceHandle2->FillRectangle (SurfaceHandle2, xcoords, ycoords, size, size); xcoords -= size; ycoords += size; // Green SurfaceHandle2->SetColorIndex (SurfaceHandle2, 0x2); SurfaceHandle2->FillRectangle (SurfaceHandle2, xcoords, ycoords, size, size); xcoords -= size; ycoords += size; // Red SurfaceHandle2->SetColorIndex (SurfaceHandle2, 0x1); SurfaceHandle2->FillRectangle (SurfaceHandle2, xcoords, ycoords, size, size); xcoords -= size; ycoords += size; // White SurfaceHandle2->SetColorIndex (SurfaceHandle2, 0x4); SurfaceHandle2->FillRectangle (SurfaceHandle2, xcoords, ycoords, size, size); xcoords -= size; ycoords += size; } DFBCHECK (SurfaceHandle->Lock (SurfaceHandle, DSLF_READ, &ptr, &pitch)); DFBCHECK (SurfaceHandle2->Lock (SurfaceHandle2, DSLF_READ, &ptr2, &pitch2)); printf("%s:%d\n",__FUNCTION__,__LINE__); zorder(videofd2,V4L2_CID_STM_Z_ORDER_RGB2,1); zorder(videofd1,V4L2_CID_STM_Z_ORDER_RGB1,2); queue_buffer( videofd1, ptr, (is_lut8 ? colour_palette : 0), 0ULL); stream_on( videofd1 ); getchar(); queue_buffer( videofd2, ptr2, colour_palette2, 0ULL); printf("%s:%d\n",__FUNCTION__,__LINE__); stream_on( videofd2 ); printf("%s:%d\n",__FUNCTION__,__LINE__); getchar(); zorder(videofd2,V4L2_CID_STM_Z_ORDER_RGB2,2); zorder(videofd1,V4L2_CID_STM_Z_ORDER_RGB1,1); fprintf(stderr,"Press Return/Enter to quit\n"); getchar(); // This seems to dequeue all buffers too, but that's what the spec says // so this is ok. stream_off( videofd1 ); stream_off( videofd2 ); deinit_dfb(); close(videofd1); return 0; }