Exemple #1
0
int test_store_restore(TestData* testdata){
  VSMotionDetectConfig mdconf = vsMotionDetectGetDefaulfConfig("test_motionDetect");
  VSMotionDetect md;
  test_bool(vsMotionDetectInit(&md, &mdconf, &testdata->fi) == VS_OK);

  LocalMotions lms;
  int i;
  for(i=0; i<2; i++){
    test_bool(vsMotionDetection(&md, &lms,&testdata->frames[i])== VS_OK);
    if (i==0) vs_vector_del(&lms);
  }

  FILE* f = fopen("lmtest","w");
  vsStoreLocalmotions(f,&lms);
  fclose(f);
  f = fopen("lmtest","r");
  LocalMotions test = vsRestoreLocalmotions(f);
  fclose(f);
  vsStoreLocalmotions(stderr,&test);
  compare_localmotions(&lms,&test);
  fprintf(stderr,"\n** LM and LMS OKAY\n");

  f = fopen("lmstest","w");
  md.frameNum=1;
  vsPrepareFile(&md,f);
  vsWriteToFile(&md,f,&lms);
  md.frameNum=2;
  vsWriteToFile(&md,f,&test);
  fclose(f);

  f = fopen("lmstest","r");
  test_bool(vsReadFileVersion(f)==1);
  LocalMotions read1;
  test_bool(vsReadFromFile(f,&read1)==1);
  compare_localmotions(&lms,&read1);
  LocalMotions read2;
  test_bool(vsReadFromFile(f,&read2)==2);
  compare_localmotions(&test,&read2);
  fclose(f);
  fprintf(stderr,"** Reading file stepwise OKAY\n");
  vs_vector_del(&read1);
  vs_vector_del(&read2);
  vs_vector_del(&test);
  vs_vector_del(&lms);

  f = fopen("lmstest","r");
  VSManyLocalMotions mlms;
  test_bool(vsReadLocalMotionsFile(f,&mlms)==VS_OK);
  test_bool(vs_vector_size(&mlms)==2);
  fprintf(stderr,"** Entire file routine OKAY\n\n");

  for(i=0; i< vs_vector_size(&mlms); i++){
    if(VSMLMGet(&mlms,i))
      vs_vector_del(VSMLMGet(&mlms,i));
  }
  vs_vector_del(&mlms);

  return 1;
}
Exemple #2
0
  void PipelineStabDetect::onInput(InputImageInfo info, Magick::Image image) {
    try {
      if (!initialized) {
        init(image);
      }
      if (image.rows() != height || image.columns() != width) {
        throw runtime_error(QString("Not uniform image size! %").arg(info.file.fileName()).toStdString());
      }


      Magick::Blob blob;
      // set raw RGBS output format & convert it into a Blob  
      if (image.depth() > 8)
        *err << "Warning: we lost some information by converting to 8bit depth (now " << image.depth() << ")" << endl;
      image.depth(8);
      image.magick("RGB");
      image.write(&blob);

      LocalMotions localmotions;
      VSFrame frame;
      size_t dataLen = blob.length();

      Q_ASSERT(fi.planes == 1);
      Q_ASSERT(dataLen == image.baseColumns() * image.baseRows() * 3);

      if (stabConf->mdConf.show > 0) { // create copy of blob
        frame.data[0] = new uint8_t[dataLen];
        memcpy(frame.data[0], blob.data(), dataLen);
      } else {
        frame.data[0] = (uint8_t*) blob.data();
      }
      frame.linesize[0] = image.baseColumns() * 3;

      if (vsMotionDetection(&md, &localmotions, &frame) != VS_OK) {
        throw runtime_error("motion detection failed");
      } else {
        if (vsWriteToFile(&md, f, &localmotions) != VS_OK) {
          throw runtime_error("cannot write to transform file");
        }
        vs_vector_del(&localmotions);
      }

      if (stabConf->mdConf.show > 0) {
        // if we want to store transformations, we have to create new image...
        Magick::Geometry g(width, height);
        Magick::Blob oblob(frame.data[0], dataLen);

        Magick::Image oimage;
        oimage.read(oblob, g, 8, "RGB");
        delete[] frame.data[0];
        emit input(info, oimage);
      } else {
        emit input(info, image);
      }

    } catch (exception &e) {
      emit error(e.what());
    }
  }
Exemple #3
0
static void analyze_image( mlt_filter filter, mlt_frame frame, uint8_t* vs_image, VSPixelFormat vs_format, int width, int height )
{
	mlt_properties properties = MLT_FILTER_PROPERTIES( filter );
	vs_data* data = (vs_data*)filter->child;
	mlt_position pos = mlt_filter_get_position( filter, frame );

	// If any frames are skipped, analysis data will be incomplete.
	if( data->analyze_data && pos != data->analyze_data->last_position + 1 )
	{
		mlt_log_error( MLT_FILTER_SERVICE(filter), "Bad frame sequence\n" );
		destory_analyze_data( data->analyze_data );
		data->analyze_data = NULL;
	}

	if ( !data->analyze_data && pos == 0 )
	{
		// Analysis must start on the first frame
		init_analyze_data( filter, frame, vs_format, width, height );
	}

	if( data->analyze_data )
	{
		// Initialize the VSFrame to be analyzed.
		VSMotionDetect* md = &data->analyze_data->md;
		LocalMotions localmotions;
		VSFrame vsFrame;
		vsFrameFillFromBuffer( &vsFrame, vs_image, &md->fi );

		// Detect and save motions.
		if( vsMotionDetection( md, &localmotions, &vsFrame ) == VS_OK )
		{
			vsWriteToFile( md, data->analyze_data->results, &localmotions);
			vs_vector_del( &localmotions );
		}
		else
		{
			mlt_log_error( MLT_FILTER_SERVICE(filter), "Motion detection failed\n" );
			destory_analyze_data( data->analyze_data );
			data->analyze_data = NULL;
		}

		// Publish the motions if this is the last frame.
		if ( pos + 1 == mlt_filter_get_length2( filter, frame ) )
		{
			mlt_log_info( MLT_FILTER_SERVICE(filter), "Analysis complete\n" );
			destory_analyze_data( data->analyze_data );
			data->analyze_data = NULL;
			mlt_properties_set( properties, "results", mlt_properties_get( properties, "filename" ) );
		}
		else
		{
			data->analyze_data->last_position = pos;
		}
	}
}