/** * Re-cache the C<config-E<gt>identity_url> if needed. */ static int cache_ssh_identity (struct config *config) { int fd; /* If it doesn't need downloading, return. */ if (config->identity_url == NULL || !config->identity_file_needs_update) return 0; /* Generate a random filename. */ free (config->identity_file); config->identity_file = strdup ("/tmp/id.XXXXXX"); if (config->identity_file == NULL) error (EXIT_FAILURE, errno, "strdup"); fd = mkstemp (config->identity_file); if (fd == -1) error (EXIT_FAILURE, errno, "mkstemp"); close (fd); /* Curl download URL to file. */ if (curl_download (config->identity_url, config->identity_file) == -1) { free (config->identity_file); config->identity_file = NULL; config->identity_file_needs_update = 1; return -1; } return 0; }
int main(int argc, char** argv) { int store_width, store_height, store_autow, store_autoh; FILE *fout = stdout; #ifdef FEAT_CURL FILE *fr; int fd; #endif FILE *fp; int n; parse_options(argc, argv); store_width = width; store_height = height; store_autow = auto_width; store_autoh = auto_height; if ( strcmp(fileout, "-") ) { if ( (fout = fopen(fileout, "wb")) == NULL ) { fprintf(stderr, "Could not open '%s' for writing.\n", fileout); return 1; } } for ( n=1; n<argc; ++n ) { width = store_width; height = store_height; auto_width = store_autow; auto_height = store_autoh; // skip options if ( argv[n][0]=='-' && argv[n][1] ) continue; // read from stdin if ( argv[n][0]=='-' && !argv[n][1] ) { #ifdef _WIN32 // Good news, everyone! _setmode( _fileno( stdin ), _O_BINARY ); #endif decompress(stdin, fout); continue; } #ifdef FEAT_CURL if ( is_url(argv[n]) ) { if ( verbose ) fprintf(stderr, "URL: %s\n", argv[n]); fd = curl_download(argv[n], debug); if ( (fr = fdopen(fd, "rb")) == NULL ) { fputs("Could not fdopen read pipe\n", stderr); return 1; } decompress(fr, fout); fclose(fr); close(fd); continue; } #endif // read files if ( (fp = fopen(argv[n], "rb")) != NULL ) { if ( verbose ) fprintf(stderr, "File: %s\n", argv[n]); decompress(fp, fout); fclose(fp); continue; } else { fprintf(stderr, "Can't open %s\n", argv[n]); return 1; } } if ( fout != stdout ) fclose(fout); return 0; }
static gboolean gst_gcs_set_caps(GstBaseTransform * btrans, GstCaps * incaps, GstCaps * outcaps) { GstGcs *gcs = GST_GCS (btrans); gint in_width, in_height; gint out_width, out_height; GST_GCS_LOCK (gcs); gst_video_format_parse_caps(incaps, &gcs->in_format, &in_width, &in_height); gst_video_format_parse_caps(outcaps, &gcs->out_format, &out_width, &out_height); if (!(gcs->in_format == gcs->out_format) || !(in_width == out_width && in_height == out_height)) { GST_WARNING("Failed to parse caps %" GST_PTR_FORMAT " -> %" GST_PTR_FORMAT, incaps, outcaps); GST_GCS_UNLOCK (gcs); return FALSE; } gcs->width = in_width; gcs->height = in_height; GST_INFO("Initialising Gcs..."); gst_pad_set_event_function(GST_BASE_TRANSFORM_SINK_PAD(gcs), gst_gcs_sink_event); const CvSize size = cvSize(gcs->width, gcs->height); GST_WARNING (" width %d, height %d", gcs->width, gcs->height); ////////////////////////////////////////////////////////////////////////////// // allocate image structs in all spaces/////////////////////////////////////// gcs->pImageRGBA = cvCreateImageHeader(size, IPL_DEPTH_8U, 4); gcs->pImgRGB = cvCreateImage(size, IPL_DEPTH_8U, 3); gcs->pImgScratch = cvCreateImage(size, IPL_DEPTH_8U, 3); gcs->pImgGRAY = cvCreateImage(size, IPL_DEPTH_8U, 1); gcs->pImgGRAY_copy = cvCreateImage(size, IPL_DEPTH_8U, 1); gcs->pImgGRAY_diff = cvCreateImage(size, IPL_DEPTH_8U, 1); gcs->pImgGRAY_1 = cvCreateImage(size, IPL_DEPTH_8U, 1); gcs->pImgGRAY_1copy= cvCreateImage(size, IPL_DEPTH_8U, 1); cvZero( gcs->pImgGRAY_1 ); cvZero( gcs->pImgGRAY_1copy ); gcs->pImgChA = cvCreateImageHeader(size, IPL_DEPTH_8U, 1); gcs->pImgCh1 = cvCreateImage(size, IPL_DEPTH_8U, 1); gcs->pImgCh2 = cvCreateImage(size, IPL_DEPTH_8U, 1); gcs->pImgCh3 = cvCreateImage(size, IPL_DEPTH_8U, 1); gcs->pImgChX = cvCreateImage(size, IPL_DEPTH_8U, 1); gcs->pImg_skin = cvCreateImage(size, IPL_DEPTH_8U, 1); gcs->grabcut_mask = cvCreateMat( size.height, size.width, CV_8UC1); cvZero(gcs->grabcut_mask); initialise_grabcut( &(gcs->GC), gcs->pImgRGB, gcs->grabcut_mask ); gcs->bbox_prev = cvRect( 60,70, 210, 170 ); ////////////////////////////////////////////////////////////////////////////// #ifdef KMEANS // k-means allocation //////////////////////////////////////////////////////// gcs->pImgRGB_kmeans = cvCreateImage(size, IPL_DEPTH_8U, 3); gcs->num_samples = size.height * size.width; gcs->kmeans_points = cvCreateMat( gcs->num_samples, 5, CV_32FC1); gcs->kmeans_clusters = cvCreateMat( gcs->num_samples, 1, CV_32SC1); #endif //KMEANS ////////////////////////////////////////////////////////////////////////////// // Init ghost file /////////////////////////////////////////////////////////// curlMemoryStructGCS chunk; //gchar url[]="file:///home/mcasassa/imco2/mods/gstreamer/cyclops/shaders/mask8.png"; //gchar url[]="file:///apps/devnfs/mcasassa/mask_320x240.png"; char curlErrBuf[255]; if( gcs->ghostfilename){ if(FALSE == curl_download(gcs->ghostfilename, "", &chunk, curlErrBuf)) { GST_ERROR("download failed, err: %s", curlErrBuf); } char errBuf[255]; if( FALSE == read_png(&chunk, &(gcs->raw_image), &(gcs->info), errBuf)){ GST_ERROR("png load failed, err: %s", errBuf); } const CvSize sizegh = cvSize(gcs->info.width, gcs->info.height); gcs->cvGhost = cvCreateImageHeader(sizegh, IPL_DEPTH_8U, gcs->info.channels); gcs->cvGhost->imageData = (char*)gcs->raw_image; gcs->cvGhostBw = cvCreateImage(sizegh, IPL_DEPTH_8U, 1); if( gcs->info.channels > 1){ cvCvtColor( gcs->cvGhost, gcs->cvGhostBw, CV_RGB2GRAY ); } else{ cvCopy(gcs->cvGhost, gcs->cvGhostBw, NULL); } gcs->cvGhostBwResized = cvCreateImage(size, IPL_DEPTH_8U, 1); cvResize( gcs->cvGhostBw, gcs->cvGhostBwResized, CV_INTER_LINEAR); gcs->cvGhostBwAffined = cvCreateImage(size, IPL_DEPTH_8U, 1); } GST_INFO(" Collected caps, image in size (%dx%d), ghost size (%dx%d) %dch",gcs->width, gcs->height, gcs->info.width, gcs->info.height, gcs->info.channels ); // 3 points of the face bbox associated to the ghost. gcs->srcTri[0].x = 145; gcs->srcTri[0].y = 74; gcs->srcTri[1].x = 145; gcs->srcTri[1].y = 74+39; gcs->srcTri[2].x = 145+34; gcs->srcTri[2].y = 74+39; gcs->warp_mat = cvCreateMat(2,3,CV_32FC1); gcs->numframes = 0; GST_INFO("Gcs initialized."); GST_GCS_UNLOCK (gcs); return TRUE; }