/** * Extract the moving element of the @frame (colored picture) * by comparing it to the @background picture * @backgound picture of the background * @frame picture to analyse * @return a picture of the extracted foreground */ Mat extractForegroundColor(const Mat & background, const Mat & frame){ Mat res; int seuil = 14; int lignes = frame.rows; int colonnes = frame.cols; int pas = frame.step; /*Control of the similarity of the picture size*/ if (background.rows == lignes && background.cols == colonnes){ res = Mat(frame.size(), frame.type()); /*Comparaison of the @frame with the @background and creation of the extract object in a picture*/ for (int i = 0; i<lignes; i++){ for (int j = 0; j<colonnes; j++){ if(abs(frame.data[i*pas+j*3+0] - background.data[i*pas+j*3+0]) > seuil || abs(frame.data[i*pas+j*3+1] - background.data[i*pas+j*3+1]) > seuil || abs(frame.data[i*pas+j*3+2] - background.data[i*pas+j*3+2]) > seuil){ // if the difference between the value of the frame pixel and of the background pixel // (for each canal) is above a threshold, the frame pixel is part of the foreground // and have to be extracted res.data[i*pas+j*3+0] = frame.data[i*pas+j*3+0]; res.data[i*pas+j*3+1] = frame.data[i*pas+j*3+1]; res.data[i*pas+j*3+2] = frame.data[i*pas+j*3+2]; } else{ // if not, the pixel is colored in a certain color (depends on the values in constantes.h) res.data[i*pas+j*3+0] = BLUE; res.data[i*pas+j*3+1] = GREEN; res.data[i*pas+j*3+2] = RED; } } } } else{ wrongFormat(); } return res; }
/* * Strip an IL binary. */ static int stripFile(const char *progname, const char *input, const char *output, int preserveDates, int verbose) { FILE *infile; FILE *outfile; char buffer[4096]; ILUInt32 len; ILUInt32 offset; ILUInt32 optHeader; ILUInt32 numSectionsOffset; ILUInt32 numSections; ILUInt32 headerSize; ILUInt32 debugRVA; ILUInt32 debugStart; const char *tempFile; char *nameBuf; /* Attempt to open the specified file */ if((infile = openFile(progname, input, "rb", "r")) == 0) { return 1; } /* Read the first 4k of the file so that we can parse the headers */ len = (ILUInt32)fread(buffer, 1, sizeof(buffer), infile); /* Do we have an MS-DOS stub and PE signature? Note: other "strip" programs support object files and ".a" archives, but we don't yet */ if(len < 64) { wrongFormat(progname, input, infile); return 1; } if(buffer[0] != 'M' || buffer[1] != 'Z') { wrongFormat(progname, input, infile); return 1; } offset = IL_READ_UINT32(buffer + 60); if((offset + 4) >= len) { wrongFormat(progname, input, infile); return 1; } if(buffer[offset] != 'P' || buffer[offset + 1] != 'E' || buffer[offset + 2] != '\0' || buffer[offset + 3] != '\0') { wrongFormat(progname, input, infile); return 1; } offset += 4; /* Process the PE/COFF header and skip to the start of the section table */ if((offset + 20) > len) { wrongFormat(progname, input, infile); return 1; } numSectionsOffset = offset + 2; numSections = IL_READ_UINT16(buffer + offset + 2); headerSize = IL_READ_UINT16(buffer + offset + 16); if(headerSize < 216 || headerSize > 1024) { wrongFormat(progname, input, infile); return 1; } optHeader = offset + 20; offset += 20 + headerSize; if(offset >= len) { wrongFormat(progname, input, infile); return 1; } /* Determine if the last section is ".ildebug". If it isn't, then the binary has already been stripped of debug symbols */ if((offset + 40 * numSections) > len) { wrongFormat(progname, input, infile); return 1; } if(numSections == 0 || ILMemCmp(buffer + offset + (numSections - 1) * 40, ".ildebug", 8) != 0) { /* We exit successfully if the file is already stripped */ if(output) { /* Copy the entire contents to the output */ if((outfile = openFile(progname, output, "wb", "w")) == 0) { fclose(infile); return 1; } while(len > 0) { fwrite(buffer, 1, (int)len, outfile); if(len < sizeof(buffer)) { len = 0; } else { len = (ILUInt32)fread(buffer, 1, sizeof(buffer), infile); } } fclose(outfile); } fclose(infile); return 0; } /* Patch the header to remove the ".ildebug" section, and determine how many bytes will remain in the file once the section is gone */ debugRVA = IL_READ_UINT32(buffer + offset + (numSections - 1) * 40 + 12); debugStart = IL_READ_UINT32(buffer + offset + (numSections - 1) * 40 + 20); ILMemZero(buffer + offset + (numSections - 1) * 40, 40); IL_WRITE_UINT32(buffer + optHeader + 56, debugRVA); /* New image size */ IL_WRITE_UINT16(buffer + numSectionsOffset, numSections - 1); if(debugStart < len) { len = debugStart; } /* Create the temporary output filename */ if(output) { tempFile = output; nameBuf = 0; } else { if((nameBuf = (char *)ILMalloc(strlen(input) + 5)) == 0) { fputs("virtual memory exhausted\n", stderr); fclose(infile); return 1; } strcpy(nameBuf, input); strcat(nameBuf, ".tmp"); tempFile = nameBuf; } /* Print what we are doing if the verbose flag is set */ if(verbose) { printf("copy from %s(pecoff-cli) to %s(pecoff-cli)\n", input, tempFile); } /* Open the temporary file */ if((outfile = openFile(progname, tempFile, "wb", "w")) == 0) { fclose(infile); if(nameBuf) { ILFree(nameBuf); } return 1; } /* Copy the contents across, with the ".ildebug" section removed */ offset = 0; while(offset < debugStart && len > 0) { fwrite(buffer, 1, (int)len, outfile); offset += len; if(offset < debugStart && len >= sizeof(buffer)) { len = (debugStart - offset); if(len > sizeof(buffer)) { len = sizeof(buffer); } len = fread(buffer, 1, (int)len, infile); } else { len = 0; } } /* Close the streams */ fclose(infile); fclose(outfile); #if !defined(IL_WIN32_PLATFORM) && defined(HAVE_STAT) && defined(HAVE_UTIME) /* Copy the date information across if necessary */ if(preserveDates) { struct stat st; struct utimbuf ut; if(stat(input, &st) >= 0) { ut.actime = st.st_atime; ut.modtime = st.st_mtime; utime(tempFile, &ut); } } #endif /* Rename the temporary file, to replace the original input */ if(!output) { ILRenameDir(tempFile, input); } if(nameBuf) { ILFree(nameBuf); } /* Finished */ return 0; }