Esempio n. 1
0
 void Add::execute(runtime::DataProvider& provider)
 {
     runtime::Id2DataPair inputMapper(INPUT);
     provider.receiveInputData(inputMapper);
     
     runtime::ReadAccess input(inputMapper.data());
     unsigned int sum = (unsigned int)(input.get<runtime::UInt32>()) +
                        (unsigned int)(m_offset);
     runtime::Data* result = new runtime::UInt32(sum);
     
     runtime::DataContainer outContainer(result);
    
     runtime::Id2DataPair output(OUTPUT, outContainer);
     provider.sendOutputData(output);
 }
Esempio n. 2
0
 void Bitwise_and::execute(runtime::DataProvider & provider)
 {
     switch(int(m_dataFlow))
     {
     case(MANUAL):
         {
             runtime::Id2DataPair src1InMapper(SRC_1);
             runtime::Id2DataPair src2InMapper(SRC_2);
             runtime::Id2DataPair dstInMapper(DST);
             
             provider.receiveInputData(src1InMapper && src2InMapper && dstInMapper);
             
             const runtime::Data* src1Data = 0;
             const runtime::Data* src2Data = 0;
             runtime::Data* dstData = 0;
             
             runtime::ReadAccess src1ReadAccess;
             runtime::ReadAccess src2ReadAccess;
             runtime::DataContainer inContainer = dstInMapper.data();
             runtime::WriteAccess writeAccess(inContainer);
             dstData = &writeAccess.get();
             
             if(src1InMapper.data() == inContainer)
             {
                 throw runtime::InputError(SRC_1, *this, "Can not operate in place.");
             }
             else
             {
                 src1ReadAccess = runtime::ReadAccess(src1InMapper.data());
                 src1Data = &src1ReadAccess.get();
             }
             
             if(src2InMapper.data() == inContainer)
             {
                 throw runtime::InputError(SRC_2, *this, "Can not operate in place.");
             }
             else
             {
                 src2ReadAccess = runtime::ReadAccess(src2InMapper.data());
                 src2Data = &src2ReadAccess.get();
             }
             
             if(! src1Data->variant().isVariant(m_src1Description->variant()))
             {
                 throw runtime::InputError(SRC_1, *this, "Wrong input data variant.");
             }
             if(! src2Data->variant().isVariant(m_src2Description->variant()))
             {
                 throw runtime::InputError(SRC_2, *this, "Wrong input data variant.");
             }
             if(! dstData->variant().isVariant(m_dstDescription->variant()))
             {
                 throw runtime::InputError(DST, *this, "Wrong input data variant.");
             }
             
             const runtime::Image* src1CastedData = runtime::data_cast<runtime::Image>(src1Data);
             const runtime::Image* src2CastedData = runtime::data_cast<runtime::Image>(src2Data);
             runtime::Image * dstCastedData = runtime::data_cast<runtime::Image>(dstData);
             
             if((src1CastedData->rows() != src2CastedData->rows()) || (src1CastedData->cols() != src2CastedData->cols()))
                 throw runtime::InputError(SRC_1, *this, "Input images must have the same size.");
                 
             if(src1CastedData->numChannels() != src2CastedData->numChannels())
                 throw runtime::InputError(SRC_1, *this, "Input images must have the same number of channels.");
                 
             if(src1CastedData->depth() != src2CastedData->depth())
                 throw runtime::InputError(SRC_1, *this, "Input images must have the same depth if the destination depth is not explicitely given.");
             
             dstCastedData->initializeImage(src1CastedData->width(), src1CastedData->height(), src1CastedData->stride(), dstCastedData->data(), src1CastedData->pixelType());
             
             cv::Mat src1CvData = cvsupport::getOpenCvMat(*src1CastedData);
             cv::Mat src2CvData = cvsupport::getOpenCvMat(*src2CastedData);
             cv::Mat dstCvData = cvsupport::getOpenCvMat(*dstCastedData);
             
             cv::bitwise_and(src1CvData, src2CvData, dstCvData);
             
             runtime::DataContainer dstOutContainer = inContainer;
             runtime::Id2DataPair dstOutMapper(DST, dstOutContainer);
             
             provider.sendOutputData(dstOutMapper);
         }
         break;
     case(ALLOCATE):
         {
             runtime::Id2DataPair src1InMapper(SRC_1);
             runtime::Id2DataPair src2InMapper(SRC_2);
             
             provider.receiveInputData(src1InMapper && src2InMapper);
             
             const runtime::Data* src1Data = 0;
             const runtime::Data* src2Data = 0;
             
             runtime::ReadAccess src1ReadAccess;
             runtime::ReadAccess src2ReadAccess;
             
             src1ReadAccess = runtime::ReadAccess(src1InMapper.data());
             src1Data = &src1ReadAccess.get();
             src2ReadAccess = runtime::ReadAccess(src2InMapper.data());
             src2Data = &src2ReadAccess.get();
             
             if(! src1Data->variant().isVariant(m_src1Description->variant()))
             {
                 throw runtime::InputError(SRC_1, *this, "Wrong input data variant.");
             }
             if(! src2Data->variant().isVariant(m_src2Description->variant()))
             {
                 throw runtime::InputError(SRC_2, *this, "Wrong input data variant.");
             }
             
             const runtime::Image* src1CastedData = runtime::data_cast<runtime::Image>(src1Data);
             const runtime::Image* src2CastedData = runtime::data_cast<runtime::Image>(src2Data);
             
             if((src1CastedData->rows() != src2CastedData->rows()) || (src1CastedData->cols() != src2CastedData->cols()))
                 throw runtime::InputError(SRC_1, *this, "Input images must have the same size.");
                 
             if(src1CastedData->numChannels() != src2CastedData->numChannels())
                 throw runtime::InputError(SRC_1, *this, "Input images must have the same number of channels.");
                 
             if(src1CastedData->depth() != src2CastedData->depth())
                 throw runtime::InputError(SRC_1, *this, "Input images must have the same depth if the destination depth is not explicitely given.");
             
             cv::Mat src1CvData = cvsupport::getOpenCvMat(*src1CastedData);
             cv::Mat src2CvData = cvsupport::getOpenCvMat(*src2CastedData);
             cv::Mat dstCvData;
             
             cv::bitwise_and(src1CvData, src2CvData, dstCvData);
             
             runtime::Image* dstCastedData = new cvsupport::Image(dstCvData);
             runtime::DataContainer dstOutContainer = runtime::DataContainer(dstCastedData);
             runtime::Id2DataPair dstOutMapper(DST, dstOutContainer);
             
             dstCastedData->initializeImage(dstCastedData->width(), dstCastedData->height(), dstCastedData->stride(), dstCastedData->data(), src1CastedData->pixelType());
             provider.sendOutputData(dstOutMapper);
         }
         break;
     }
 }
Esempio n. 3
0
 void PyrUp::execute(runtime::DataProvider & provider)
 {
     switch(int(m_dataFlow))
     {
     case(MANUAL):
         {
             runtime::Id2DataPair srcInMapper(SRC);
             runtime::Id2DataPair dstInMapper(DST);
             
             provider.receiveInputData(srcInMapper && dstInMapper);
             
             const runtime::Data* srcData = 0;
             runtime::Data* dstData = 0;
             
             runtime::ReadAccess srcReadAccess;
             runtime::DataContainer inContainer = dstInMapper.data();
             runtime::WriteAccess writeAccess(inContainer);
             dstData = &writeAccess.get();
             
             if(srcInMapper.data() == inContainer)
             {
                 throw runtime::InputError(SRC, *this, "Can not operate in place.");
             }
             else
             {
                 srcReadAccess = runtime::ReadAccess(srcInMapper.data());
                 srcData = &srcReadAccess.get();
             }
             
             if(! srcData->variant().isVariant(m_srcDescription->variant()))
             {
                 throw runtime::InputError(SRC, *this, "Wrong input data variant.");
             }
             if(! dstData->variant().isVariant(m_dstDescription->variant()))
             {
                 throw runtime::InputError(DST, *this, "Wrong input data variant.");
             }
             
             const runtime::Image* srcCastedData = runtime::data_cast<runtime::Image>(srcData);
             runtime::Image * dstCastedData = runtime::data_cast<runtime::Image>(dstData);
             
             int width = 2  * srcCastedData->width();
             int height = 2 * srcCastedData->height();
             dstCastedData->initializeImage(width, height, width * srcCastedData->pixelSize(), dstCastedData->data(), srcCastedData->pixelType());
             
             cv::Mat srcCvData = cvsupport::getOpenCvMat(*srcCastedData);
             cv::Mat dstCvData = cvsupport::getOpenCvMat(*dstCastedData);
             
             cv::pyrUp(srcCvData, dstCvData);
             
             runtime::DataContainer dstOutContainer = inContainer;
             runtime::Id2DataPair dstOutMapper(DST, dstOutContainer);
             
             provider.sendOutputData(dstOutMapper);
         }
         break;
     case(ALLOCATE):
         {
             runtime::Id2DataPair srcInMapper(SRC);
             
             provider.receiveInputData(srcInMapper);
             
             const runtime::Data* srcData = 0;
             
             runtime::ReadAccess srcReadAccess;
             
             srcReadAccess = runtime::ReadAccess(srcInMapper.data());
             srcData = &srcReadAccess.get();
             
             if(! srcData->variant().isVariant(m_srcDescription->variant()))
             {
                 throw runtime::InputError(SRC, *this, "Wrong input data variant.");
             }
             
             const runtime::Image* srcCastedData = runtime::data_cast<runtime::Image>(srcData);
             
             cv::Mat srcCvData = cvsupport::getOpenCvMat(*srcCastedData);
             cv::Mat dstCvData;
             
             cv::pyrUp(srcCvData, dstCvData);
             
             runtime::Image* dstCastedData = new cvsupport::Image(dstCvData);
             runtime::DataContainer dstOutContainer = runtime::DataContainer(dstCastedData);
             runtime::Id2DataPair dstOutMapper(DST, dstOutContainer);
             
             dstCastedData->initializeImage(dstCastedData->width(), dstCastedData->height(), dstCastedData->stride(), dstCastedData->data(), srcCastedData->pixelType());
             provider.sendOutputData(dstOutMapper);
         }
         break;
     }
 }
Esempio n. 4
0
 void CornerMinEigenVal::execute(runtime::DataProvider & provider)
 {
     switch(int(m_dataFlow))
     {
     case(MANUAL):
         {
             runtime::Id2DataPair srcInMapper(INPUT_SRC);
             runtime::Id2DataPair dstInMapper(INPUT_DST);
             
             provider.receiveInputData(srcInMapper && dstInMapper);
             
             const runtime::Data* srcData = 0;
             runtime::Data* dstData = 0;
             
             runtime::ReadAccess srcReadAccess;
             runtime::DataContainer inContainer = dstInMapper.data();
             runtime::WriteAccess writeAccess(inContainer);
             dstData = &writeAccess.get();
             
             if(srcInMapper.data() == inContainer)
             {
                 throw runtime::InputError(INPUT_SRC, *this, "Can not operate in place.");
             }
             else
             {
                 srcReadAccess = runtime::ReadAccess(srcInMapper.data());
                 srcData = &srcReadAccess.get();
             }
             
             if(! srcData->variant().isVariant(m_srcDescription->variant()))
             {
                 throw runtime::InputError(INPUT_SRC, *this, "Wrong input data variant.");
             }
             if(! dstData->variant().isVariant(m_dstDescription->variant()))
             {
                 throw runtime::InputError(INPUT_DST, *this, "Wrong input data variant.");
             }
             
             const runtime::Image* srcCastedData = runtime::data_cast<runtime::Image>(srcData);
             runtime::Matrix * dstCastedData = runtime::data_cast<runtime::Matrix>(dstData);
             
             unsigned int stride = srcCastedData->cols() * runtime::Matrix::valueSize(runtime::Matrix::FLOAT_32);
             dstCastedData->initializeMatrix(srcCastedData->rows(), srcCastedData->cols(), stride, dstCastedData->data(), runtime::Matrix::FLOAT_32);
             
             cv::Mat srcCvData = cvsupport::getOpenCvMat(*srcCastedData);
             cv::Mat dstCvData = cvsupport::getOpenCvMat(*dstCastedData);
             int blockSizeCvData = int(m_blockSize);
             int ksizeCvData = int(m_ksize);
             
             cv::cornerMinEigenVal(srcCvData, dstCvData, blockSizeCvData, ksizeCvData);
             
             runtime::DataContainer dstOutContainer = inContainer;
             runtime::Id2DataPair dstOutMapper(OUTPUT_DST, dstOutContainer);
             
             provider.sendOutputData(dstOutMapper);
         }
         break;
     case(ALLOCATE):
         {
             runtime::Id2DataPair srcInMapper(INPUT_SRC);
             
             provider.receiveInputData(srcInMapper);
             
             const runtime::Data* srcData = 0;
             
             runtime::ReadAccess srcReadAccess;
             
             srcReadAccess = runtime::ReadAccess(srcInMapper.data());
             srcData = &srcReadAccess.get();
             
             if(! srcData->variant().isVariant(m_srcDescription->variant()))
             {
                 throw runtime::InputError(INPUT_SRC, *this, "Wrong input data variant.");
             }
             
             const runtime::Image* srcCastedData = runtime::data_cast<runtime::Image>(srcData);
             
             cv::Mat srcCvData = cvsupport::getOpenCvMat(*srcCastedData);
             cv::Mat dstCvData;
             int blockSizeCvData = int(m_blockSize);
             int ksizeCvData = int(m_ksize);
             
             cv::cornerMinEigenVal(srcCvData, dstCvData, blockSizeCvData, ksizeCvData);
             
             runtime::Matrix* dstCastedData = new cvsupport::Matrix(dstCvData);
             runtime::DataContainer dstOutContainer = runtime::DataContainer(dstCastedData);
             runtime::Id2DataPair dstOutMapper(OUTPUT_DST, dstOutContainer);
             
             provider.sendOutputData(dstOutMapper);
         }
         break;
     }
 }
Esempio n. 5
0
 void Merge::execute(runtime::DataProvider & provider)
 {
     switch(int(m_dataFlow))
     {
     case(MANUAL):
         {
             runtime::Id2DataPair src1InMapper(INPUT_SRC_1);
             runtime::Id2DataPair src2InMapper(INPUT_SRC_2);
             runtime::Id2DataPair dstInMapper(INPUT_DST);
             
             provider.receiveInputData(src1InMapper && src2InMapper && dstInMapper);
             
             const runtime::Data* src1Data = 0;
             const runtime::Data* src2Data = 0;
             runtime::Data* dstData = 0;
             
             runtime::ReadAccess src1ReadAccess;
             runtime::ReadAccess src2ReadAccess;
             runtime::DataContainer inContainer = dstInMapper.data();
             runtime::WriteAccess writeAccess(inContainer);
             dstData = &writeAccess.get();
             
             if(src1InMapper.data() == inContainer)
             {
                 throw runtime::InputError(INPUT_SRC_1, *this, "Can not operate in place.");
             }
             else
             {
                 src1ReadAccess = runtime::ReadAccess(src1InMapper.data());
                 src1Data = &src1ReadAccess.get();
             }
             
             if(src2InMapper.data() == inContainer)
             {
                 throw runtime::InputError(INPUT_SRC_2, *this, "Can not operate in place.");
             }
             else
             {
                 src2ReadAccess = runtime::ReadAccess(src2InMapper.data());
                 src2Data = &src2ReadAccess.get();
             }
             
             if(! src1Data->variant().isVariant(m_src1Description->variant()))
             {
                 throw runtime::InputError(INPUT_SRC_1, *this, "Wrong input data variant.");
             }
             if(! src2Data->variant().isVariant(m_src2Description->variant()))
             {
                 throw runtime::InputError(INPUT_SRC_2, *this, "Wrong input data variant.");
             }
             if(! dstData->variant().isVariant(m_dstDescription->variant()))
             {
                 throw runtime::InputError(INPUT_DST, *this, "Wrong input data variant.");
             }
             
             const runtime::Matrix* src1CastedData = runtime::data_cast<runtime::Matrix>(src1Data);
             const runtime::Matrix* src2CastedData = runtime::data_cast<runtime::Matrix>(src2Data);
             runtime::Matrix * dstCastedData = runtime::data_cast<runtime::Matrix>(dstData);
             
             if((src1CastedData->rows() != src2CastedData->rows()) || (src1CastedData->cols() != src2CastedData->cols()))
                 throw runtime::InputError(INPUT_SRC_1, *this, "Input matrices must have the same size.");
                 
             if(src1CastedData->type() != src2CastedData->type())
                 throw runtime::InputError(INPUT_SRC_1, *this, "Input matrices must have the same types.");
             
             dstCastedData->initializeMatrix(src1CastedData->rows(), 2*src1CastedData->cols(), 2*src1CastedData->cols()*src1CastedData->valueSize(), dstCastedData->data(), src1CastedData->valueType());
             
             cv::Mat src1CvData = cvsupport::getOpenCvMat(*src1CastedData);
             cv::Mat src2CvData = cvsupport::getOpenCvMat(*src2CastedData);
             cv::Mat dstCvData = cvsupport::getOpenCvMat(*dstCastedData);
             
             merge(src1CvData, src2CvData, dstCvData);
             
             runtime::DataContainer dstOutContainer = inContainer;
             runtime::Id2DataPair dstOutMapper(OUTPUT_DST, dstOutContainer);
             
             provider.sendOutputData(dstOutMapper);
         }
         break;
     case(ALLOCATE):
         {
             runtime::Id2DataPair src1InMapper(INPUT_SRC_1);
             runtime::Id2DataPair src2InMapper(INPUT_SRC_2);
             
             provider.receiveInputData(src1InMapper && src2InMapper);
             
             const runtime::Data* src1Data = 0;
             const runtime::Data* src2Data = 0;
             
             runtime::ReadAccess src1ReadAccess;
             runtime::ReadAccess src2ReadAccess;
             
             src1ReadAccess = runtime::ReadAccess(src1InMapper.data());
             src1Data = &src1ReadAccess.get();
             src2ReadAccess = runtime::ReadAccess(src2InMapper.data());
             src2Data = &src2ReadAccess.get();
             
             if(! src1Data->variant().isVariant(m_src1Description->variant()))
             {
                 throw runtime::InputError(INPUT_SRC_1, *this, "Wrong input data variant.");
             }
             if(! src2Data->variant().isVariant(m_src2Description->variant()))
             {
                 throw runtime::InputError(INPUT_SRC_2, *this, "Wrong input data variant.");
             }
             
             const runtime::Matrix* src1CastedData = runtime::data_cast<runtime::Matrix>(src1Data);
             const runtime::Matrix* src2CastedData = runtime::data_cast<runtime::Matrix>(src2Data);
             
             if((src1CastedData->rows() != src2CastedData->rows()) || (src1CastedData->cols() != src2CastedData->cols()))
                 throw runtime::InputError(INPUT_SRC_1, *this, "Input matrices must have the same size.");
                 
             if(src1CastedData->type() != src2CastedData->type())
                 throw runtime::InputError(INPUT_SRC_1, *this, "Input matrices must have the same types.");
             
             cv::Mat src1CvData = cvsupport::getOpenCvMat(*src1CastedData);
             cv::Mat src2CvData = cvsupport::getOpenCvMat(*src2CastedData);
             cv::Mat dstCvData;
             
             merge(src1CvData, src2CvData, dstCvData);
             
             runtime::Matrix* dstCastedData = new cvsupport::Matrix(dstCvData);
             runtime::DataContainer dstOutContainer = runtime::DataContainer(dstCastedData);
             runtime::Id2DataPair dstOutMapper(OUTPUT_DST, dstOutContainer);
             
             dstCastedData->initializeMatrix(dstCastedData->rows(), dstCastedData->cols(), dstCastedData->stride(), dstCastedData->data(), src1CastedData->valueType());
             provider.sendOutputData(dstOutMapper);
         }
         break;
     }
 }