Ejemplo n.º 1
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());
    }
  }
Ejemplo n.º 2
0
  void PipelineStabTransform::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());
      }

      Q_ASSERT(image.baseColumns() == width && image.baseRows() == height);
      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);


      Q_ASSERT(blob.length() == image.baseColumns() * image.baseRows() * 3);

      // inframe
      VSFrame inframe;
      size_t dataLen = blob.length();
      inframe.data[0] = (uint8_t*) blob.data();
      inframe.linesize[0] = image.baseColumns() * 3; // TODO: it is correct?

      // outframe
      uint8_t* data = new uint8_t[dataLen];
      //memcpy(data, blob.data(), dataLen);
      VSFrame outframe;
      outframe.data[0] = data;
      outframe.linesize[0] = image.baseColumns() * 3; // TODO: it is correct?

      if (vsTransformPrepare(&td, &inframe, &outframe) != VS_OK) {
        throw runtime_error("Failed to prepare transform");
      }
      Q_ASSERT(vsTransformGetSrcFrameInfo(&td)->planes == 1);

      vsDoTransform(&td, vsGetNextTransform(&td, &trans));

      vsTransformFinish(&td);

      Magick::Geometry g(width, height);
      Magick::Blob oblob(data, dataLen);

      Magick::Image oimage;
      oimage.size(g);
      oimage.depth(8);
      oimage.magick("RGB");
      oimage.read(oblob);

      delete[] data;

      info.luminance = -1;
      emit input(info, oimage);

    } catch (exception &e) {
      emit error(e.what());
    }
  }