bool RestoreScale::Cleanup() { for(int f=0;f<getImg()->getNumFrames();f++){ SegmentationResult *saved=getImg()->readLastFrameResultFromXML ("ScaleDown:originalImageId"); if(!saved){ if(Verbose()>1) cout << "ScaleDown::Cleanup : saved image sequence not found." << endl; } else{ int id; if(sscanf(saved->value.c_str(),"%d",&id)!=1){ throw string("RestoreScale::Cleanup(): couldn't parse original id."); } delete saved; if(Verbose()>1) cout << "Removing stored image " << id << endl; getImg()->removeImage(id); } } return CleanupPreviousMethod(); }
bool TestInterface::Process() { // preProcess int i; featureInterface.createMethods(getImg()); // doProcess if(Verbose() > 1){ // dump info about the parametres from the command line cout << "number of feature classes: " << featureInterface.featureClass.size() << endl; for(i=0;(unsigned)i<featureInterface.featureClass.size();i++){ cout << "feature class " << i << endl; cout << "name: " << featureInterface.featureClass[i].name << endl; cout << "options: " ; list<string>::const_iterator it; for(it=featureInterface.featureClass[i].options.begin(); it!=featureInterface.featureClass[i].options.end(); it++) cout << *it << " "; cout << endl; } cout << "number of feature specifications: " << featureInterface.featureSpec.size() << endl; for(i=0;(unsigned)i<featureInterface.featureSpec.size();i++){ cout << "feature specification " << i << endl; cout << "class: " << featureInterface.featureSpec[i].c << endl; cout << "index: " << featureInterface.featureSpec[i].index << endl; cout << "weight: " << featureInterface.featureSpec[i].weight << endl; } } Feature::featureVector fV; coordList l; int x,y; for(x=tileX1;x<=tileX2;x++) for(y=tileY1;y<=tileY2;y++) l.push_back(coord(x,y)); vector<coordList *> vc; vc.push_back(&l); featureInterface.calculateFeatures(vc,fV); Feature::printFeatureVector(cout,fV); cout << endl; featureInterface.freeClasses(); return ProcessNextMethod(); }
int *AlignmentMarks::GetVerticalSlice(int begin, int width,int margin) { segmentfile *seg=getImg(); int h=seg->getHeight()+2*margin,s; int *slice=new int[h]; int x,y; for(y=0;y<h;y++) slice[y]=-width; for(y=0;y<seg->getHeight();y++) for(x=0;x<width;x++){ seg->get_pixel_segment(x+begin,y,s); if(s) slice[y+margin] += 2; } if(printIntermediate){ cout << "Vertical slice from x=" << begin << " to x=" << begin+width-1 << endl; for(y=0;y<seg->getHeight();y++) cout << y << " " << slice[y+margin] << endl; } return slice; }
int *AlignmentMarks::GetSlice(int begin, int height,int margin) { segmentfile *seg=getImg(); int w=seg->getWidth()+2*margin,s; int *slice=new int[w]; int x,y; for(x=0;x<w;x++) slice[x]=-height; for(y=0;y<height;y++) for(x=0;x<seg->getWidth();x++){ seg->get_pixel_segment(x,y+begin,s); if(s) slice[x+margin] += 2; } if(printIntermediate){ cout << "Horisontal slice from y=" << begin << " to y=" << begin+height-1 << endl; for(x=0;x<seg->getWidth();x++) cout << x << " " << slice[x+margin] << endl; } return slice; }
ImgSequence::ImgSequence(string inDirName) : dirName(inDirName) { //cout << "Image directory: " << dirName << endl; countImages(); loadAllPoses(); // loadAllCovArrays(); // Load the first image to get its width and height. getImg(0); imageWidth = imgs[0]->getWidth(); imageHeight = imgs[0]->getHeight(); minX = truePoses[0].x; minY = truePoses[0].y; maxX = truePoses[0].x; maxY = truePoses[0].y; for (int i=1; i<getLength(); i++) { if (truePoses[i].x < minX) minX = truePoses[i].x; if (truePoses[i].y < minY) minY = truePoses[i].y; if (truePoses[i].x > maxX) maxX = truePoses[i].x; if (truePoses[i].y > maxY) maxY = truePoses[i].y; } }
int main(void) { addUrl(); GetHtml(url); getImg(); curl_easy_cleanup(curl); return 0; }
bool ListAdjacent::Process() { vector<set<int> > adj=getImg()->getAdjacentCombinations(); if(Verbose()>1) cout << "Got "<<adj.size() << " combinations." << endl; int l=adj.size(); SegmentationResult res; res.type="virtualsegment"; res.value=""; for(int i=0;i<l;i++){ res.name=formVirtualSegmentLabel(adj[i]); getImg()->writeFrameResultToXML(this,res); if(Verbose()>1) cout << " "<<res.name<<endl; } return ProcessNextMethod(); }
bool SampleRandom::Process() { int xSz,ySz; if(xFrac>0 && yFrac>0 && xFrac <= 1 && yFrac <=1){ xSz=(int)(xFrac*Width()); ySz=(int)(yFrac*Height()); } else{ xSz=(xSize>Width())?Width():xSize; ySz=(ySize>Height())?Height():ySize; } char valstr[80],lblstr[80]; clock_t c=clock(); struct tm *t=gmtime(&c); srand(t->tm_sec+60*t->tm_min+3600*t->tm_hour); for(int i=0;i<numberOfRegions;i++){ double r=rand(); r /= RAND_MAX+1.0; // scale r to interval [0,1) r *= (Width()-xSz); int xStart= (int)r; r=rand(); r /= RAND_MAX+1.0; // scale r to interval [0,1) r *= (Height()-ySz); int yStart= (int)r; sprintf(lblstr,"SampleRandom%d",i); sprintf(valstr,"rect:%d,%d,%d%d",xStart,yStart, xStart+xSz-1,yStart+ySz-1); SegmentationResult segresult; segresult.name=lblstr; segresult.type="region"; segresult.value=valstr; getImg()->writeFrameResultToXML(this,segresult); } return ProcessNextMethod(); }
int AlignmentMarks::FindTop() { int x,y,s; segmentfile *seg=getImg(); int w=seg->getWidth(); int h=seg->getHeight(); for(y=0;y<h;y++) for(x=0;x<w;x++){ seg->get_pixel_segment(x,y,s); if(s) return y; } return -1; }
void LocateFaceBox::ShowFaceBox(LBBox& fa) { imagedata img = *getImg()->accessFrame(); int m = WIDTH_BOX_FACIALPARTS; int n = HEIGHT_BOX_FACIALPARTS; int l = fa.l; int t = fa.t; int r = fa.l + m - 1; int b = fa.t + n - 1; int w0 = img.width(); int h0 = img.height(); int w = fa.w; int h = round(1.0 * h0 * w / w0); scalinginfo scale_si(w0, h0, w, h); img.rescale(scale_si); float xc=0.5*(w-1), yc=0.5*(h-1); scalinginfo rotate_si(fa.degree*PI/180, xc, yc); float xlt, ylt, xlb, ylb, xrt, yrt, xrb, yrb; rotate_si.rotate_dst_xy(l-xc,t-yc,xlt,ylt); rotate_si.rotate_dst_xy(l-xc,b-yc,xlb,ylb); rotate_si.rotate_dst_xy(r-xc,t-yc,xrt,yrt); rotate_si.rotate_dst_xy(r-xc,b-yc,xrb,yrb); int nxlt = max(0,round(xlt+xc)); int nylt = max(0,round(ylt+yc)); int nxlb = max(0,round(xlb+xc)); int nylb = min(h-1,round(ylb+yc)); int nxrt = min(w-1,round(xrt+xc)); int nyrt = max(0,round(yrt+yc)); int nxrb = min(w-1,round(xrb+xc)); int nyrb = min(h-1,round(yrb+yc)); img.force_three_channel(); DrawLine(img, nxlt, nylt, nxlb, nylb); DrawLine(img, nxlb, nylb, nxrb, nyrb); DrawLine(img, nxrb, nyrb, nxrt, nyrt); DrawLine(img, nxrt, nyrt, nxlt, nylt); imagefile::displaysettings stgs; stgs.title = "FaceBox"; imagefile::display(img, stgs); }
bool RemoveHoles::Process() { // find the largest continuous region that has label 0 in segmented image int x,y,v; int *unique = getImg()->GetSeparateLabelingInt(); map<int,int> counts; int w=getImg()->getWidth(); int h=getImg()->getHeight(); for(y=0;y<h;y++) for (x=0;x<w;x++){ getImg()->get_pixel_segment(x, y, v); if(v==0) counts[unique[x+y*w]]++; } if(counts.size()>1){ int maxlabel=counts.begin()->first; map<int,int>::const_iterator it; for(it=counts.begin();it!=counts.end();it++) if(it->second > counts[maxlabel]) maxlabel=it->first; int i=0; for(y=0;y<h;y++) for(x=0;x<w;x++){ getImg()->get_pixel_segment(x, y, v); if(v==0 && unique[i] != maxlabel) getImg()->set_pixel_segment(x,y,1); i++; } } return ProcessNextMethod(); }
ComputerView::ComputerView(Wt::WApplication *app, const Wt::WString &computerName, bool writeAccess, Wt::WContainerWidget *parent) : Wt::WContainerWidget(parent), app(app), _computerName(computerName), _img_led(NULL) { Wt::WBoxLayout *layout = new Wt::WBoxLayout(Wt::WBoxLayout::TopToBottom, this); Wt::WText *_title = new Wt::WText(computerName); _title->setStyleClass("ComputerName"); app->styleSheet().addRule(".ComputerName", "font-size: 36px; text-transform: capitalize;"); layout->addWidget(_title, 0, Wt::AlignCenter); /* create the buttons and connect them to their slots */ _btn_atx_force_off = new Wt::WPushButton("Force off"); _btn_atx_force_on = new Wt::WPushButton("Force on"); _btn_atx_reset = new Wt::WPushButton("Reset"); _btn_pw_switch_press = new Wt::WPushButton("Press"); _btn_pw_switch_force_off = new Wt::WPushButton("Force off"); _btn_atx_force_off->setEnabled(writeAccess); _btn_atx_force_on->setEnabled(writeAccess); _btn_atx_reset->setEnabled(writeAccess); _btn_pw_switch_press->setEnabled(writeAccess); _btn_pw_switch_force_off->setEnabled(writeAccess); _btn_atx_force_off->clicked().connect(this, &ComputerView::btn_atx_force_off_clicked); _btn_atx_force_on->clicked().connect(this, &ComputerView::btn_atx_force_on_clicked); _btn_atx_reset->clicked().connect(this, &ComputerView::btn_atx_reset_clicked); _btn_pw_switch_press->clicked().connect(this, &ComputerView::btn_pw_switch_press_clicked); _btn_pw_switch_force_off->clicked().connect(this, &ComputerView::btn_pw_switch_force_off_clicked); /* preload all the images */ _ico_led_on_file.reset(getImg("green_light.png")); _ico_led_off_file.reset(getImg("off_light.png")); _ico_ping_file.reset(getImg("ping.png")); _ico_atx_pwr_file.reset(getImg("atx_power.png")); _ico_pwr_switch_file.reset(getImg("power-button.png")); /* create the LED */ _img_led = new Wt::WImage(); _img_led->setHeight(Wt::WLength(16)); setPowerLedStatus(false); Wt::WGridLayout *grid = new Wt::WGridLayout(); grid->addWidget(_img_led, 0, 0, Wt::AlignCenter); grid->addWidget(new Wt::WText("Power Led state"), 0, 1); grid->addWidget(new Wt::WLabel(""), 0, 5); grid->addWidget(new Wt::WImage(_ico_ping_file.get()), 1, 0, Wt::AlignCenter); grid->addWidget(new Wt::WText("Ping"), 1, 1); _ping_txt = new Wt::WText("N/A"); grid->addWidget(_ping_txt, 1, 2, 0, 0, Wt::AlignCenter); grid->addWidget(new Wt::WImage(_ico_atx_pwr_file.get()), 2, 0, Wt::AlignCenter); grid->addWidget(new Wt::WText("ATX power"), 2, 1); grid->addWidget(_btn_atx_force_off, 2, 2); grid->addWidget(_btn_atx_force_on, 2, 3); grid->addWidget(_btn_atx_reset, 2, 4); grid->addWidget(new Wt::WImage(_ico_pwr_switch_file.get()), 3, 0, Wt::AlignCenter); grid->addWidget(new Wt::WText("Power switch"), 3, 1); grid->addWidget(_btn_pw_switch_press, 3, 2); grid->addWidget(_btn_pw_switch_force_off, 3, 3); grid->setColumnStretch(5, 1); layout->addLayout(grid); layout->addSpacing(10); Wt::WLabel *label = new Wt::WLabel("Logs:"); layout->addWidget(label); _logs_edit = new Wt::WTextArea(""); _logs_edit->setHeight(150); _logs_edit->setMaximumSize(Wt::WLength::Auto, 150); label->setBuddy(_logs_edit); layout->addWidget(_logs_edit); layout->addSpacing(10); }
bool AlignmentMarks::Process() { int maskwidth=10; int top,bottom; int x1,x2,x3,x4,y1,y2; top=FindTop(); if(top==-1) return false; bottom=FindBottom(); if(bottom==-1) return false; if(printIntermediate){ cout << "top=" << top<<" bottom="<< bottom << endl; } int *slice=GetVerticalSlice(0,Width(),maskwidth); EdgeDetect(slice,Height()+1,maskwidth,y1,y2); y2--; if(y1 <= y2){ top=y1;bottom=y2;} if(printIntermediate){ cout << "y1=" << y1<<" y2="<< y2 << endl; } int limit=top + (int)(0.1*(bottom-top)); int h=limit-top+1; slice=GetSlice(top,h,maskwidth); //if(Verbose()>1){ // cout << "Top slice:" << endl; // for(int i=0;i<Width()+2*maskwidth;i++) cout <<i<<": " << (int)slice[i] << endl; //} EdgeDetect(slice,Width()+1,maskwidth,x1,x2); x2--; delete[] slice; limit=bottom-(int)(0.1*(bottom-top)); h=bottom-limit+1; slice=GetSlice(limit,h,maskwidth); //if(Verbose()>1){ // cout << "Bottom slice:" << endl; // for(int i=0;i<Width()+2*maskwidth;i++) cout <<i<<": " << (int)slice[i] << endl; //} EdgeDetect(slice,Width()+1,maskwidth,x3,x4); x4--; delete[] slice; if(printIntermediate){ cout <<"x1=" << x1<<" x2="<< x2 << endl; cout << "x3=" << x3<<" x4="<< x4 << endl; } // scale the bottom alignment line double top_factor = 0.87; double center=(x3+x4)/2.0; double half_len = (x4-x3)*top_factor/2.0; x3 = (int)(center-half_len); x4 = (int)(center+half_len); if(printIntermediate){ cout << "After scaling x3=" << x3<<" x4="<< x4 << endl; } // now write the result SegmentationResult result; ostringstream *str=new ostringstream; (*str) << x1 << " " << top << " " << x2 << " " << top; result.name = "alignment_marks_top"; result.type = "line"; result.value = str->str(); getImg()->writeFrameResultToXML(this,result); delete str; str=new ostringstream; (*str) << x3 << " " << bottom << " " << x4 << " " << bottom; result.name = "alignment_marks_bottom"; result.value = str->str(); getImg()->writeFrameResultToXML(this,result); delete str; return true; }
bool Complex::operator==(const Complex & right) const { return (getReal() == right.getReal() && getImg() == right.getImg()); }
Complex Complex::operator*(const Complex & right) const { return Complex(getReal()*right.getReal()-getImg()*right.getImg(), getReal()*right.getImg()+getImg()*right.getReal()); }
Complex Complex::dotInvert() const { if(getReal() == 0 && getImg() == 0) throw HasNotInverse(); return Complex(getReal()/(getReal()*getReal()+getImg()*getImg()), (-1)*getImg()/(getReal()*getReal()+getImg()*getImg())); }
Complex Complex::addInvert() const { return Complex((-1)*getReal(), (-1)*getImg()); }
bool LocateFaceBox::Process() { _pFace_model = LBModel::ReadModel(_ffacemodel); _pNonface_model = LBModel::ReadModel(_fnonfacemodel); list<LBBox> candidates; DetectFaces(candidates); if (candidates.empty()) { cout << "!!! No qualified face found !!!" << endl; return false; } LBBox fa; float dmax=0.0; int i=0; for (list<LBBox>::iterator ci=candidates.begin();ci!=candidates.end();ci++) { float d = ci->deltan - ci->deltaf; if (i==0 || d>dmax) { dmax = d; fa = *ci; } i++; } if (Verbose()>2) cout << "fa.l=" << fa.l << " " << "fa.t=" << fa.t << " " << "fa.w=" << fa.w << " " << "fa.degree=" << fa.degree << " " << "fa.deltaf=" << fa.deltaf << " " << "fa.deltan=" << fa.deltan << endl; imagedata* pImg = getImg()->accessFrame(); int w0 = pImg->width(); int h0 = pImg->height(); float xc0 = 0.5*(w0-1); float yc0 = 0.5*(h0-1); float scale = (float)w0/fa.w; float xc = 0.5*(fa.w-1); float yc = 0.5*(h0/scale-1); float theta = PI * fa.degree / 180; scalinginfo si(theta, xc, yc); float ls,ts; si.rotate_dst_xy_c(fa.l, fa.t, ls, ts); int l = round(scale*ls); int t = round(scale*ts); int w = round(scale*WIDTH_BOX_FACIALPARTS); int h = round(scale*HEIGHT_BOX_FACIALPARTS); float irxc, iryc; si.rotate_dst_xy_c((fa.l+0.5*WIDTH_BOX_FACIALPARTS), (fa.t+0.5*HEIGHT_BOX_FACIALPARTS), irxc, iryc); irxc = scale * irxc; iryc = scale * iryc; stringstream faceinnerbox; faceinnerbox << l << " " << t << " " << w << " " << h << " " << theta << " " << irxc << " " << iryc; SegmentationResult faceinnerboxres; faceinnerboxres.name="faceinnerbox"; faceinnerboxres.type="rotated-box"; faceinnerboxres.value=faceinnerbox.str(); AddResultToXML(faceinnerboxres); float W = 30.0; // standard width of face inner box float HFORHEAD = 15.0; // standard forhead height float WF = 46.0; float HF = 56.0; float s = w / W; // scale between real face inner box and standard // face inner box float wf = WF * s; float hf = HF * s; float lr, tr; scalinginfo si0(theta, xc0, yc0); si0.rotate_src_xy_c(lr, tr, l, t); float flfr = lr - 0.5*(WF-W)*s; float ftfr = tr - HFORHEAD*s; float flf, ftf; si0.rotate_dst_xy_c(flfr, ftfr, flf, ftf); float frxc, fryc; si0.rotate_dst_xy_c(flfr+0.5*wf, ftfr+0.5*hf, frxc, fryc); stringstream facebox; facebox << round(flf) << " " << round(ftf) << " " << round(wf) << " " << round(hf) << " " << theta << " " << frxc << " " << fryc; SegmentationResult faceboxres; faceboxres.name="face"; faceboxres.type="rotated-box"; faceboxres.value=facebox.str(); AddResultToXML(faceboxres); float wh = hf; float WH = HF; float hlfr = lr - 0.5*(WH-W)*s; float htfr = ftfr; float hlf, htf; si0.rotate_dst_xy_c(hlfr, htfr, hlf, htf); float hrxc, hryc; si0.rotate_dst_xy_c(hlfr+0.5*wh, htfr+0.5*wh, hrxc, hryc); stringstream headbox; headbox << round(hlf) << " " << round(htf) << " " << round(wh) << " " << round(wh) << " " << theta << " " << hrxc << " " << hryc; SegmentationResult headboxres; headboxres.name="head"; headboxres.type="rotated-box"; headboxres.value=headbox.str(); AddResultToXML(headboxres); if (Verbose()>2) ShowFaceBox(fa); return ProcessNextMethod(); }
int main(int argc, char **argv) { int optindex = 0; char ch; struct option longopts[] = { {"dimension", required_argument, 0, 'd'}, //dimensions of src img {"components", required_argument, 0, 'c'}, //numger of components of src img {"depth", required_argument, 0, 'b'}, //bit depth of src img {"level", required_argument, 0, 'l'}, //level of dwt {"device", required_argument, 0, 'D'}, //cuda device {"forward", no_argument, 0, 'f'}, //forward transform {"reverse", no_argument, 0, 'r'}, //forward transform {"97", no_argument, 0, '9'}, //9/7 transform {"53", no_argument, 0, '5' }, //5/3transform {"write-visual",no_argument, 0, 'w' }, //write output (subbands) in visual (tiled) order instead of linear {"help", no_argument, 0, 'h'} }; int pixWidth = 0; //<real pixWidth int pixHeight = 0; //<real pixHeight int compCount = 3; //number of components; 3 for RGB or YUV, 4 for RGBA int bitDepth = 8; int dwtLvls = 3; //default numuber of DWT levels int device = 0; int forward = 1; //forward transform int dwt97 = 0; //1=dwt9/7, 0=dwt5/3 transform int writeVisual = 0; //write output (subbands) in visual (tiled) order instead of linear char * pos; while ((ch = getopt_long(argc, argv, "d:c:b:l:D:fr95wh", longopts, &optindex)) != -1) { switch (ch) { case 'd': pixWidth = atoi(optarg); pos = strstr(optarg, "x"); if (pos == NULL || pixWidth == 0 || (strlen(pos) >= strlen(optarg))) { usage(); return -1; } pixHeight = atoi(pos+1); break; case 'c': compCount = atoi(optarg); break; case 'b': bitDepth = atoi(optarg); break; case 'l': dwtLvls = atoi(optarg); break; case 'D': device = atoi(optarg); break; case 'f': forward = 1; break; case 'r': forward = 0; break; case '9': dwt97 = 1; break; case '5': dwt97 = 0; break; case 'w': writeVisual = 1; break; case 'h': usage(); return 0; case '?': return -1; default : usage(); return -1; } } argc -= optind; argv += optind; if (argc == 0) { // at least one filename is expected printf("Please supply src file name\n"); usage(); return -1; } if (pixWidth <= 0 || pixHeight <=0) { printf("Wrong or missing dimensions\n"); usage(); return -1; } if (forward == 0) { writeVisual = 0; //do not write visual when RDWT } // // device init // Create an OpenCL context on first available platform context = CreateContext(); if (context == NULL) { std::cerr << "Failed to create OpenCL context." << std::endl; return 1; } // Create a command-queue on the first device available // on the created context commandQueue = CreateCommandQueue(context, &cldevice); if (commandQueue == NULL) { Cleanup(context, commandQueue, program, kernel); return 1; } // Create OpenCL program from com_dwt.cl kernel source program = CreateProgram(context, cldevice, "com_dwt.cl"); if (program == NULL) { printf("fail to create program!!\n"); } // Create OpenCL kernel c_CopySrcToComponents = clCreateKernel(program, "c_CopySrcToComponents", NULL); if (c_CopySrcToComponents == NULL) { std::cerr << "Failed to create kernel" << std::endl; } c_CopySrcToComponent = clCreateKernel(program, "c_CopySrcToComponent", NULL); if (c_CopySrcToComponent == NULL) { std::cerr << "Failed to create kernel" << std::endl; } kl_fdwt53Kernel = clCreateKernel(program, "cl_fdwt53Kernel", NULL); if (kl_fdwt53Kernel == NULL) { std::cerr<<"Failed to create kernel\n"; } //initialize struct dwt struct dwt *d; d = (struct dwt *)malloc(sizeof(struct dwt)); d->srcImg = NULL; d->pixWidth = pixWidth; d->pixHeight = pixHeight; d->components = compCount; d->dwtLvls = dwtLvls; // file names d->srcFilename = (char *)malloc(strlen(argv[0])); strcpy(d->srcFilename, argv[0]); if (argc == 1) { // only one filename supplyed d->outFilename = (char *)malloc(strlen(d->srcFilename)+4); strcpy(d->outFilename, d->srcFilename); strcpy(d->outFilename+strlen(d->srcFilename), ".dwt"); } else { d->outFilename = strdup(argv[1]); } //Input review printf("\nSource file:\t\t%s\n", d->srcFilename); printf(" Dimensions:\t\t%dx%d\n", pixWidth, pixHeight); printf(" Components count:\t%d\n", compCount); printf(" Bit depth:\t\t%d\n", bitDepth); printf(" DWT levels:\t\t%d\n", dwtLvls); printf(" Forward transform:\t%d\n", forward); printf(" 9/7 transform:\t\t%d\n", dwt97); //data sizes int inputSize = pixWidth*pixHeight*compCount; //<amount of data (in bytes) to proccess //load img source image d->srcImg = (unsigned char *) malloc (inputSize); if (getImg(d->srcFilename, d->srcImg, inputSize) == -1) return -1; // DWT // Create memory objects, Set arguments for kernel functions, Queue the kernel up for execution across the array, Read the output buffer back to the Host, Output the result buffer if (forward == 1) { if(dwt97 == 1 ) processDWT<float>(d, forward, writeVisual); else // 5/3 processDWT<int>(d, forward, writeVisual); } else { // reverse if(dwt97 == 1 ) processDWT<float>(d, forward, writeVisual); else // 5/3 processDWT<int>(d, forward, writeVisual); } Cleanup(context, commandQueue, program, kernel); clReleaseKernel(c_CopySrcToComponents); clReleaseKernel(c_CopySrcToComponent); return 0; }
bool RestoreScale::Process() { int ow,oh; const imagedata *oi = NULL; SegmentationResult *saved=getImg()->readLastFrameResultFromXML ("ScaleDown:originalImageId"); if(!saved){ if(Verbose()>1){ cout << "RestoreScale::Process : saved image not found." << endl; cout << "Trying to find size info" << endl; } SegmentationResult *owRes=getImg()->readLastFrameResultFromXML ("ScaleDown:originalWidth"); if(!owRes) throw string("RestoreScale::Process: ScaleDown:originalWidth not found"); SegmentationResult *ohRes=getImg()->readLastFrameResultFromXML ("ScaleDown:originalHeight"); if(!ohRes){ delete owRes; throw string("RestoreScale::Process: ScaleDown:originalHeight not found"); } if(sscanf(owRes->value.c_str(),"%d",&ow)!=1){ delete owRes; delete ohRes; throw string("RestoreScale::Process: couldn't parse original width."); } if(sscanf(ohRes->value.c_str(),"%d",&oh)!=1){ delete owRes; delete ohRes; throw string("RestoreScale::Process: couldn't parse original height."); } delete owRes; delete ohRes; } else{ int id; if(sscanf(saved->value.c_str(),"%d",&id)!=1){ throw string("RestoreScale::Process: couldn't parse original id."); } if(Verbose()>1) cout << "original image w/ id " << id << " found." << endl; oi=getImg()->storedImage(id); if(!oi) throw string ("RestoreScale::Process :storedImage(") + saved->value +") failed"; else if(Verbose()>1) cout << "accessed parsed result frame" << endl; ow = oi->width(); oh = oi->height(); } getImg()->rescaleFrame(scalinginfo(Width(),Height(),ow,oh),oi,NULL,discardImage); delete saved; return ProcessNextMethod(); }
void LocateFaceBox::DetectFaces(list<LBBox>& faces) { imagedata img0 = *getImg()->accessFrame(); /* imagefile::displaysettings stgs; stgs.title = "img0"; imagefile::display(img0, stgs); */ img0.force_one_channel(); int m = WIDTH_BOX_FACIALPARTS; int n = HEIGHT_BOX_FACIALPARTS; int w0 = img0.width(); int h0 = img0.height(); int w = round(_scale_min); int h = round(1.0 * h0 * w / w0); int fi=0; while(w<=_scale_max) { imagedata img = img0; scalinginfo scale_si(w0, h0, w, h); img.rescale(scale_si); if (Verbose()>2) cout << "w=" << w << endl; for (float degree=_rotate_min;degree<=_rotate_max;degree+=_rotate_step) { imagedata rotated = img; scalinginfo rotate_si(degree*PI/180, 0.5*(w-1), 0.5*(h-1)); rotated.rotate(rotate_si); if (Verbose()>2) cout << "degree=" << degree << endl; for (int x=0;x<w-m+1;x++) for (int y=0;y<h-n+1;y++) { imagedata block = rotated.subimage(x,y,x+m-1,y+n-1); vector<float> Y = LBModel::PrepareVector(block); float deltaf = _pFace_model->Score(Y); float deltan = _pNonface_model->Score(Y); if (Verbose()>3) cout << "w=" << w << " " << "x=" << x << " " << "y=" << y << " " << "deltaf=" << deltaf << " " << "deltan=" << deltan << endl; if (deltaf<_theta && deltaf+_tau<deltan) { LBBox fa; fa.l = x; fa.t = y; fa.w = w; fa.degree = -degree; fa.deltaf = deltaf; fa.deltan = deltan; if (Verbose()>2) cout << "fa.l=" << fa.l << " " << "fa.t=" << fa.t << " " << "fa.w=" << fa.w << " " << "fa.degree=" << fa.degree << " " << "fa.deltaf=" << fa.deltaf << " " << "fa.deltan=" << fa.deltan << endl; faces.push_back(fa); if (Verbose()>2) cout << "face no. " << ++fi << " found" << endl; } } } w = round(w*_scale_augment); h = round(1.0 * h0 * w / w0); } }
gboolean isTennisFree() { gboolean res = FALSE; ExceptionInfo *exception; Image *image; ImageInfo *image_info; unsigned long colors; ColorPacket *histogram; unsigned long i = 0; char* img_path = "video.jpg"; getImg(); exception = AcquireExceptionInfo(); image_info = CloneImageInfo((ImageInfo *) NULL); strcpy(image_info->filename, img_path); image = ReadImage(image_info,exception); if (exception->severity != UndefinedException) { CatchException(exception); } if (image == (Image *) NULL) { return FALSE; //exit(1); } histogram = GetImageHistogram(image, &colors, exception); qsort((void *) histogram, (size_t) colors, sizeof(*histogram), myHistogramCompare); if (histogram == (ColorPacket*) NULL) { MagickError(exception->severity, exception->reason, exception->description); } if(colors > 0) { if(histogram[i].count > 5000 && ScaleQuantumToChar(RoundToQuantum(histogram[i].pixel.red)) < 35 && ScaleQuantumToChar(RoundToQuantum(histogram[i].pixel.green)) < 35 && ScaleQuantumToChar(RoundToQuantum(histogram[i].pixel.blue)) < 35) { res = TRUE; printf("Empty\n"); } else { res = FALSE; printf("Busy\n"); } // printf("%d %d %d %d\n", (int)histogram[i].count, ScaleQuantumToChar(RoundToQuantum(histogram[i].pixel.red)), ScaleQuantumToChar(RoundToQuantum(histogram[i].pixel.green)), ScaleQuantumToChar(RoundToQuantum(histogram[i].pixel.blue))); } // remove(img_path); histogram = (ColorPacket *) RelinquishMagickMemory(histogram); DestroyImage(image); image_info=DestroyImageInfo(image_info); exception=DestroyExceptionInfo(exception); return res; }
int main(int argc,char **argv) { ExceptionInfo *exception; Image *image; ImageInfo *image_info; unsigned long colors; ColorPacket *histogram; unsigned long i = 0; char* img_path = "video.jpg"; getImg(); MagickCoreGenesis(*argv,MagickTrue); exception = AcquireExceptionInfo(); image_info = CloneImageInfo((ImageInfo *) NULL); strcpy(image_info->filename, img_path); image = ReadImage(image_info,exception); if (exception->severity != UndefinedException) { CatchException(exception); } if (image == (Image *) NULL) { exit(1); } histogram = GetImageHistogram(image, &colors, exception); qsort((void *) histogram, (size_t) colors, sizeof(*histogram), myHistogramCompare); if (histogram == (ColorPacket*) NULL) { MagickError(exception->severity, exception->reason, exception->description); } if(colors > 0) { if(histogram[i].count > 10000 && ScaleQuantumToChar(RoundToQuantum(histogram[i].pixel.red)) < 35 && ScaleQuantumToChar(RoundToQuantum(histogram[i].pixel.green)) < 35 && ScaleQuantumToChar(RoundToQuantum(histogram[i].pixel.blue)) < 35) { printf("Empty\n"); } else { printf("Busy\n"); } // printf("%u %d %d %d\n", histogram[i].count, ScaleQuantumToChar(RoundToQuantum(histogram[i].pixel.red)), ScaleQuantumToChar(RoundToQuantum(histogram[i].pixel.green)), ScaleQuantumToChar(RoundToQuantum(histogram[i].pixel.blue))); } remove(img_path); histogram = (ColorPacket *) RelinquishMagickMemory(histogram); DestroyImage(image); image_info=DestroyImageInfo(image_info); exception=DestroyExceptionInfo(exception); MagickCoreTerminus(); return(0); }