Ejemplo n.º 1
0
/*static*/ void Fitting::fitRect(VectorOfListOfPoint &vecListPoint,
                                 float               &fSlope1,
                                 float               &fSlope2,
                                 std::vector<float>  &vecIntercept,
                                 bool                 bLineOneReversedFit,
                                 bool                 bLineTwoReversedFit)
{
    assert ( vecListPoint.size() == 4 );  //The input should has 4 lines
    vecIntercept.clear();
    auto totalRows = 0;
    for ( const auto &vectorPoint : vecListPoint)
        totalRows += ToInt32(vectorPoint.size());
    cv::Mat A = cv::Mat::zeros ( totalRows, 5, CV_32FC1);
    cv::Mat B = cv::Mat::zeros ( totalRows, 1, CV_32FC1);
 
    int index = 0;
    for (int i = 0; i < ToInt32 ( vecListPoint.size() ); ++ i )
    {
        ListOfPoint listPoint = vecListPoint[i];
        for (const auto &point : listPoint )
        {
            A.at<float>(index, i + 1 ) = 1.f;
            if ( i < 2 )   {
                if (bLineOneReversedFit)   {
                    A.at<float>(index, 0) = point.y;
                    B.at<float>(index, 0) = point.x;
                }
                else
                {
                    A.at<float>(index, 0) = point.x;
                    B.at<float>(index, 0) = point.y;
                }
            }else {
                if ( bLineOneReversedFit )   {
                    A.at<float>(index, 0) = -point.x;
                    B.at<float>(index, 0) =  point.y;
                }else {
                    A.at<float>(index, 0) = -point.y;
                    B.at<float>(index, 0) =  point.x;
                }
            }
            ++ index;
        }
    }

    cv::Mat matResult;
    bool bResult = cv::solve(A, B, matResult, cv::DECOMP_QR);

    fSlope1 = matResult.at<float>(0, 0);
    fSlope2 = - fSlope1;
    for ( int i = 0; i < 4; ++ i )
        vecIntercept.push_back ( matResult.at < float >( i + 1, 0 ) );
}
Ejemplo n.º 2
0
    v8::Handle<v8::Value> getPosition(const v8::Arguments& args) {

        int offsetX = 0;
        int offsetY = 0;
        if (args.Length() > 1) {
            offsetX = ToInt32(args[0]);
            offsetY = ToInt32(args[1]);
        }

        v8::Handle<v8::Object> pos = Game::templates.position->NewInstance();
        setNumberProp(pos, "x", Game::mouse.x - Game::graphics.offsetX + offsetX);
        setNumberProp(pos, "y", Game::mouse.y - Game::graphics.offsetY + offsetY);

        return pos;
        
    }
Ejemplo n.º 3
0
void TestOCV_1()
{
    std::cout << std::endl << "---------------------------------------------";
    std::cout << std::endl << "OCV REGRESSION TEST #1 STARTING";
    std::cout << std::endl << "---------------------------------------------";
    std::cout << std::endl;

    PR_LRN_OCV_CMD stLrnCmd;
    PR_LRN_OCV_RPY stLrnRpy;
    stLrnCmd.matInputImg = cv::imread("./data/TestOCV.png");
    stLrnCmd.rectROI = cv::Rect(311, 818, 180, 61);
    stLrnCmd.nCharCount = 4;
    
    PR_LrnOcv(&stLrnCmd, &stLrnRpy);
    std::cout << "PR_LrnOcv status " << ToInt32(stLrnRpy.enStatus) << std::endl;
    if (stLrnRpy.enStatus != VisionStatus::OK)
        return;

    PR_OCV_CMD stOcvCmd;
    PR_OCV_RPY stOcvRpy;
    stOcvCmd.matInputImg = stLrnCmd.matInputImg;
    stOcvCmd.rectROI = cv::Rect(288, 1075, 217, 142);
    stOcvCmd.vecRecordId.push_back(stLrnRpy.nRecordId);

    PR_Ocv(&stOcvCmd, &stOcvRpy);
    PrintOcvRpy(stOcvRpy);
}
Ejemplo n.º 4
0
static EJS_NATIVE_FUNC(_ejs_Process_exit) {
    ejsval code = _ejs_undefined;
    if (argc > 0)
        code = args[0];

    exit(ToInt32(code));
}
Ejemplo n.º 5
0
void TestOCV_2()
{
    std::cout << std::endl << "---------------------------------------------";
    std::cout << std::endl << "OCV REGRESSION TEST #2 STARTING";
    std::cout << std::endl << "---------------------------------------------";
    std::cout << std::endl;

    PR_LRN_OCV_CMD stLrnCmd;
    PR_LRN_OCV_RPY stLrnRpy;
    stLrnCmd.matInputImg = cv::imread("./data/TestOCV_2.png");
    stLrnCmd.rectROI = cv::Rect(148, 206, 89, 152);
    stLrnCmd.enDirection = PR_DIRECTION::UP;
    stLrnCmd.nCharCount = 3;

    PR_LrnOcv(&stLrnCmd, &stLrnRpy);
    std::cout << "PR_LrnOcv status " << ToInt32(stLrnRpy.enStatus) << std::endl;
    if (stLrnRpy.enStatus != VisionStatus::OK)
        return;

    PR_OCV_CMD stOcvCmd;
    PR_OCV_RPY stOcvRpy;
    stOcvCmd.matInputImg = cv::imread("./data/TestOCV_2.png");
    stOcvCmd.rectROI = cv::Rect(141, 903, 120, 296);
    stOcvCmd.enDirection = PR_DIRECTION::UP;
    stOcvCmd.vecRecordId.push_back(stLrnRpy.nRecordId);
    PR_Ocv(&stOcvCmd, &stOcvRpy);
    PrintOcvRpy(stOcvRpy);
}
Ejemplo n.º 6
0
void TestInspDevice()
{
    std::cout << std::endl << "------------------------------------------";
    std::cout << std::endl << "INSPECT DEVICE REGRESSION TEST #1 STARTING";
    std::cout << std::endl << "------------------------------------------";
    std::cout << std::endl;

    PR_FreeAllRecord();

    VisionStatus enStatus;
    PR_LRN_DEVICE_CMD stLrnDeviceCmd;
    stLrnDeviceCmd.matInputImg = cv::imread("./data/TmplResistor.png");
    stLrnDeviceCmd.bAutoThreshold = false;
    stLrnDeviceCmd.nElectrodeThreshold = 150;
    stLrnDeviceCmd.rectDevice = cv::Rect2f( 39, 27, 104, 65 );
    PR_LRN_DEVICE_RPY stLrnDeviceRpy;
    
    PR_SetDebugMode(PR_DEBUG_MODE::DISABLED);
    enStatus = PR_LrnDevice ( &stLrnDeviceCmd, &stLrnDeviceRpy );
    if ( enStatus != VisionStatus::OK ) {
        std::cout << "Failed to learn device, status " << ToInt32( enStatus ) << std::endl;
        return;
    }
    
    std::cout << "Success to learn device" << std::endl;

    PR_INSP_DEVICE_CMD stInspDeviceCmd;
    stInspDeviceCmd.matInputImg = cv::imread("./data/RotatedDevice.png");
    stInspDeviceCmd.nElectrodeThreshold = stLrnDeviceRpy.nElectrodeThreshold;
    stInspDeviceCmd.nDeviceCount = 1;
    stInspDeviceCmd.astDeviceInfo[0].nCriteriaNo = 0;
    stInspDeviceCmd.astDeviceInfo[0].rectSrchWindow = cv::Rect ( 33, 18, 96, 76 );
    stInspDeviceCmd.astDeviceInfo[0].stCtrPos = cv::Point(72,44);
    stInspDeviceCmd.astDeviceInfo[0].stInspItem.bCheckMissed = true;
    stInspDeviceCmd.astDeviceInfo[0].stInspItem.bCheckRotation = true;
    stInspDeviceCmd.astDeviceInfo[0].stInspItem.bCheckScale = true;
    stInspDeviceCmd.astDeviceInfo[0].stInspItem.bCheckShift = true;
    stInspDeviceCmd.astDeviceInfo[0].stSize = stLrnDeviceRpy.sizeDevice;
    stInspDeviceCmd.astCriteria[0].fMaxOffsetX = 15;
    stInspDeviceCmd.astCriteria[0].fMaxOffsetY = 15;
    stInspDeviceCmd.astCriteria[0].fMaxRotate = 5;
    stInspDeviceCmd.astCriteria[0].fMaxScale = 1.3f;
    stInspDeviceCmd.astCriteria[0].fMinScale = 0.7f;

    PR_INSP_DEVICE_RPY stInspDeviceRpy;    
    PR_InspDevice( &stInspDeviceCmd, &stInspDeviceRpy );
    std::cout << "Device inspection status " << stInspDeviceRpy.astDeviceResult[0].nStatus << std::endl;

    stInspDeviceCmd.matInputImg = cv::imread("./data/ShiftedDevice.png");
    stInspDeviceCmd.astDeviceInfo[0].stCtrPos = cv::Point(85, 48);
    stInspDeviceCmd.astDeviceInfo[0].stSize = cv::Size2f(99, 52);
    stInspDeviceCmd.astDeviceInfo[0].rectSrchWindow = cv::Rect ( 42, 16, 130, 100 );
    
    PR_InspDevice( &stInspDeviceCmd, &stInspDeviceRpy );
    std::cout << "Device inspection status " << stInspDeviceRpy.astDeviceResult[0].nStatus << std::endl;
}
Ejemplo n.º 7
0
//The equation is from http://hotmath.com/hotmath_help/topics/line-of-best-fit.html
/*static*/ void Fitting::fitLine(const ListOfPoint &listPoint, float &fSlope, float &fIntercept, bool reverseFit)
{
    if ( listPoint.size() < 2 )
        return;

    //double Sx = 0., Sy = 0., Sx2 = 0., Sy2 = 0., Sxy = 0.;
    //for ( const auto &point : listPoint )   {
    //    Sx   += point.x;
    //    Sy   += point.y;
    //    Sx2  += point.x * point.x;
    //    Sy2  += point.y * point.y;
    //    Sxy  += point.x * point.y;
    //}
    //size_t n = listPoint.size();
    //if ( reverseFit )   {
    //    fSlope = static_cast<float>( ( n * Sxy - Sx * Sy ) / ( n * Sy2 - Sy * Sy ) );
    //    fIntercept = static_cast< float >( ( Sx * Sy2 - Sy * Sxy ) / ( n * Sy2 - Sy * Sy ) );
    //}else {
    //    fSlope = static_cast<float>( ( n * Sxy - Sx * Sy ) / ( n * Sx2 - Sx * Sx ) );
    //    fIntercept = static_cast< float >( ( Sy * Sx2 - Sx * Sxy ) / ( n * Sx2 - Sx * Sx ) );
    //}
    cv::Mat B(ToInt32(listPoint.size()), 1, CV_32FC1);
    cv::Mat A = cv::Mat::ones(ToInt32(listPoint.size()), 2, CV_32FC1);
    int i = 0;
    for (const auto &point : listPoint)  {
        if (reverseFit) {
            A.at<float>(i, 0) = point.y;
            B.at<float>(i, 0) = point.x;
        }
        else
        {
            A.at<float>(i, 0) = point.x;
            B.at<float>(i, 0) = point.y;
        }
        ++ i;
    }

    cv::Mat matResult;
    bool bResult = cv::solve(A, B, matResult, cv::DECOMP_SVD);

    fSlope = matResult.at<float>(0, 0);
    fIntercept = matResult.at<float>(1, 0);
}
Ejemplo n.º 8
0
void PrintOcvRpy(const PR_OCV_RPY &stRpy)
{
    std::cout << "PR_Ocv status " << ToInt32(stRpy.enStatus) << std::endl;
    std::cout << std::fixed << std::setprecision(1);
    std::cout << "Overall score: " << stRpy.fOverallScore << std::endl;
    std::cout << "Individual char score: ";
    for (auto score : stRpy.vecCharScore)
        std::cout << score << " ";
    std::cout << std::endl;
}
Ejemplo n.º 9
0
void FillHoleWidget::on_cbAlgorithm_currentIndexChanged(int index)
{
    bool bKernelSizeVisible = ( ToInt32 ( PR_FILL_HOLE_METHOD::MORPHOLOGY ) == index );
    ui.labelMorphShape->setVisible ( bKernelSizeVisible );
    ui.cbMorphShape->setVisible ( bKernelSizeVisible );
    ui.labelKernelSize->setVisible ( bKernelSizeVisible );
    ui.lineEditKernalSize->setVisible ( bKernelSizeVisible );
    ui.labelIteration->setVisible ( bKernelSizeVisible );
    ui.lineEditIteration->setVisible ( bKernelSizeVisible );
}
Ejemplo n.º 10
0
/*static*/ void Fitting::fitParallelLine(const ListOfPoint &listPoints1,
                                         const ListOfPoint &listPoints2,
                                         float             &fSlope,
                                         float             &fIntercept1,
                                         float             &fIntercept2,
                                         bool               reverseFit)
{
    if ( listPoints1.size() < 2 || listPoints2.size() < 2 )
        return;

    auto totalDataCount = static_cast<int>(listPoints1.size() + listPoints2.size());
    auto dataCount1 = listPoints1.size();
    cv::Mat B(totalDataCount, 1, CV_32FC1);
    cv::Mat A = cv::Mat::zeros(totalDataCount, 3, CV_32FC1);
    ListOfPoint::const_iterator it1 = listPoints1.begin();
    ListOfPoint::const_iterator it2 = listPoints2.begin();
    for ( int i = 0; i < totalDataCount; ++ i )  {
        if ( i < ToInt32 ( listPoints1.size() ) )    {
            if ( reverseFit )
                A.at<float>(i, 0) = (*it1).y;
            else
                A.at<float>(i, 0) = (*it1).x;

            A.at<float>(i, 1) = 1.f;
            if ( reverseFit )
                B.at<float>(i, 0) = (*it1).x;
            else
                B.at<float>(i, 0) = (*it1).y;

            ++ it1;
        }
        else
        {
            if ( reverseFit )
                A.at<float>(i, 0) = (*it2).y;
            else
                A.at<float>(i, 0) = (*it2).x;
            A.at<float>(i, 2) = 1.f;
            if ( reverseFit )
                B.at<float>(i, 0) = (*it2).x;
            else
                B.at<float>(i, 0) = (*it2).y;

            ++ it2;
        }   
    }

    cv::Mat matResult;
    bool bResult = cv::solve(A, B, matResult, cv::DECOMP_SVD);

    fSlope = matResult.at<float>(0, 0);
    fIntercept1 = matResult.at<float>(1, 0);
    fIntercept2 = matResult.at<float>(2, 0);
}
Ejemplo n.º 11
0
    v8::Handle<v8::Value> wasReleased(const v8::Arguments& args) {

        bool ok = false;
        if (args.Length() > 0) {
            int id = ToInt32(args[0]);
            if (id > 0 && id < 3) {
                ok = Game::mouse.state[id] == 0 && Game::mouse.stateOld[id] > 0;
            }
        }

        return ok? v8::True() : v8::False();

    }
Ejemplo n.º 12
0
    v8::Handle<v8::Value> setCursor(const v8::Arguments& args) {

        ALLEGRO_SYSTEM_MOUSE_CURSOR cursor = ALLEGRO_SYSTEM_MOUSE_CURSOR_DEFAULT;
        if (args.Length() > 0) {
            cursor = (ALLEGRO_SYSTEM_MOUSE_CURSOR)ToInt32(args[0]);
        }

        if (al_set_system_mouse_cursor(Game::allegro.display, cursor)) {
            return v8::True();
                
        } else {
            return v8::False();
        }

    }
Ejemplo n.º 13
0
//Using least square method to fit. Solve equation A * X = B.
/*static*/ void Fitting::fitParallelLine(const std::vector<cv::Point2f> &vecPoints1,
                                         const std::vector<cv::Point2f> &vecPoints2,
                                         float                          &fSlope,
                                         float                          &fIntercept1,
                                         float                          &fIntercept2,
                                         bool                            reverseFit)
{
    if ( vecPoints1.size() < 2 || vecPoints2.size() < 2 )
        return;

    auto totalDataCount = static_cast<int>(vecPoints1.size() + vecPoints2.size());
    auto dataCount1 = vecPoints1.size();
    cv::Mat B(totalDataCount, 1, CV_32FC1);
    cv::Mat A = cv::Mat::zeros(totalDataCount, 3, CV_32FC1);
    for ( int i = 0; i < totalDataCount; ++ i )  {
        if ( i < ToInt32 ( vecPoints1.size() ) )    {
            if ( reverseFit )
                A.at<float>(i, 0) = vecPoints1[i].y;
            else
                A.at<float>(i, 0) = vecPoints1[i].x;

            A.at<float>(i, 1) = 1.f;
            if ( reverseFit )
                B.at<float>(i, 0) = vecPoints1[i].x;
            else
                B.at<float>(i, 0) = vecPoints1[i].y;
        }
        else
        {
            if ( reverseFit )
                A.at<float>(i, 0) = vecPoints2[i - dataCount1].y;
            else
                A.at<float>(i, 0) = vecPoints2[i - dataCount1].x;
            A.at<float>(i, 2) = 1.f;
            if ( reverseFit )
                B.at<float>(i, 0) = vecPoints2[i - dataCount1].x;
            else
                B.at<float>(i, 0) = vecPoints2[i - dataCount1].y;
        }   
    }

    cv::Mat matResult;
    bool bResult = cv::solve(A, B, matResult, cv::DECOMP_SVD);

    fSlope = matResult.at<float>(0, 0);
    fIntercept1 = matResult.at<float>(1, 0);
    fIntercept2 = matResult.at<float>(2, 0);
}
Ejemplo n.º 14
0
SoundOpenAL::SoundOpenAL(const WaveData& wave_data)
{
    alGenSources(1u, &_source);
    ASSERT(_source != 0);

    alSourcef(_source, AL_PITCH, 1);
    alSourcef(_source, AL_GAIN, 1);
    alSource3f(_source, AL_POSITION, 0, 0, 0);
    alSource3f(_source, AL_VELOCITY, 0, 0, 0);
    alSourcei(_source, AL_LOOPING, AL_FALSE);

    alGenBuffers(1u, &_buffer);
    ASSERT(_buffer != 0);

    auto& wf = wave_data.Format();
    ALenum format =
        wf.channels == 1 ?
        (wf.bits_per_sample == 8 ? AL_FORMAT_MONO8 : AL_FORMAT_MONO16) :
        (wf.bits_per_sample == 8 ? AL_FORMAT_STEREO8 : AL_FORMAT_STEREO16);

    alBufferData(_buffer, format, wave_data.Data(), ToInt32(wave_data.DataByteSize()), wf.samples_per_seconds);
    ASSERT(alGetError() == 0);
}
Ejemplo n.º 15
0
osc_bundle_element_size_t ReceivedBundleElement::Size() const
{
    return ToInt32( sizePtr_ );
}
Ejemplo n.º 16
0
TSLKValue::operator bool()
{
	return ToInt32() > 0;
}
Ejemplo n.º 17
0
TSLKValue::operator unsigned short()
{
	return (unsigned short)ToInt32();
}
Ejemplo n.º 18
0
TSLKValue::operator unsigned long()
{
	return (unsigned long)ToInt32();
}
Ejemplo n.º 19
0
void TestInspBridge() {
    auto PrintRpy = [](const PR_INSP_BRIDGE_RPY &stRpy) {
        char chArrMsg[100];
        std::cout << "Inspect bridge status " << ToInt32(stRpy.enStatus) << std::endl;
        int nBridgeWindowIndex = 0;
        for (const auto &rectBridge : stRpy.vecBridgeWindow) {
            _snprintf(chArrMsg, sizeof(chArrMsg), "%d, %d, %d, %d", rectBridge.x, rectBridge.y, rectBridge.width, rectBridge.height);
            std::cout << "Bridge window " << nBridgeWindowIndex << " : " << chArrMsg << std::endl;
            ++ nBridgeWindowIndex;
        }
    };

    std::cout << std::endl << "---------------------------------------------";
    std::cout << std::endl << "INSPECT BRIDGE REGRESSION TEST #1 STARTING";
    std::cout << std::endl << "---------------------------------------------";
    std::cout << std::endl;

    {
        PR_INSP_BRIDGE_CMD stCmd;
        PR_INSP_BRIDGE_RPY stRpy;
        stCmd.matInputImg = cv::imread("./data/TestInspBridge.png", cv::IMREAD_GRAYSCALE);

        stCmd.enInspMode = PR_INSP_BRIDGE_MODE::OUTER;
        stCmd.rectROI = cv::Rect(221, 195, 28, 82);
        stCmd.rectOuterSrchWindow = cv::Rect(212, 187, 43, 102);
        for (int i = 0; i < 4; ++i)
            stCmd.vecOuterInspDirection.push_back(PR_DIRECTION(i));

        PR_InspBridge(&stCmd, &stRpy);
        PrintRpy(stRpy);
    }

    std::cout << std::endl << "---------------------------------------------";
    std::cout << std::endl << "INSPECT BRIDGE REGRESSION TEST #2 STARTING";
    std::cout << std::endl << "---------------------------------------------";
    std::cout << std::endl;

    {
        PR_INSP_BRIDGE_CMD stCmd;
        PR_INSP_BRIDGE_RPY stRpy;
        stCmd.matInputImg = cv::imread("./data/TestInspBridge.png", cv::IMREAD_GRAYSCALE);

        stCmd.enInspMode = PR_INSP_BRIDGE_MODE::OUTER;
        stCmd.rectROI = cv::Rect(169, 195, 28, 82);
        stCmd.rectOuterSrchWindow = cv::Rect(158, 187, 45, 108);
        for (int i = 0; i < 4; ++i)
            stCmd.vecOuterInspDirection.push_back(PR_DIRECTION(i));

        PR_InspBridge(&stCmd, &stRpy);
        PrintRpy(stRpy);
    }

    std::cout << std::endl << "---------------------------------------------";
    std::cout << std::endl << "INSPECT BRIDGE REGRESSION TEST #3 STARTING";
    std::cout << std::endl << "---------------------------------------------";
    std::cout << std::endl;

    {
        PR_INSP_BRIDGE_CMD stCmd;
        PR_INSP_BRIDGE_RPY stRpy;
        stCmd.matInputImg = cv::imread("./data/F1-7-4.png", cv::IMREAD_GRAYSCALE);
        stCmd.enInspMode = PR_INSP_BRIDGE_MODE::INNER;
        stCmd.rectROI = cv::Rect(1539, 1858, 24, 108);
        stCmd.stInnerInspCriteria.fMaxLengthX = 15;
        stCmd.stInnerInspCriteria.fMaxLengthY = 50;

        PR_InspBridge(&stCmd, &stRpy);
        PrintRpy(stRpy);
    }

    std::cout << std::endl << "---------------------------------------------";
    std::cout << std::endl << "INSPECT BRIDGE REGRESSION TEST #4 STARTING";
    std::cout << std::endl << "---------------------------------------------";
    std::cout << std::endl;

    {
        PR_INSP_BRIDGE_CMD stCmd;
        PR_INSP_BRIDGE_RPY stRpy;
        stCmd.matInputImg = cv::imread("./data/F1-7-4.png", cv::IMREAD_GRAYSCALE);
        stCmd.enInspMode = PR_INSP_BRIDGE_MODE::INNER;
        stCmd.rectROI = cv::Rect(1607, 1862, 24, 108);
        stCmd.stInnerInspCriteria.fMaxLengthX = 15;
        stCmd.stInnerInspCriteria.fMaxLengthY = 50;

        PR_InspBridge(&stCmd, &stRpy);
        PrintRpy(stRpy);
    }

    std::cout << std::endl << "---------------------------------------------";
    std::cout << std::endl << "INSPECT BRIDGE REGRESSION TEST #5 STARTING";
    std::cout << std::endl << "---------------------------------------------";
    std::cout << std::endl;

    {
        PR_INSP_BRIDGE_CMD stCmd;
        PR_INSP_BRIDGE_RPY stRpy;
        stCmd.matInputImg = cv::imread("./data/F1-7-4.png", cv::IMREAD_GRAYSCALE);
        stCmd.enInspMode = PR_INSP_BRIDGE_MODE::INNER;
        stCmd.rectROI = cv::Rect(1542, 2048, 24, 108);
        stCmd.stInnerInspCriteria.fMaxLengthX = 15;
        stCmd.stInnerInspCriteria.fMaxLengthY = 50;

        PR_InspBridge(&stCmd, &stRpy);
        PrintRpy(stRpy);
    }

    std::cout << std::endl << "---------------------------------------------";
    std::cout << std::endl << "INSPECT BRIDGE REGRESSION TEST #6 STARTING";
    std::cout << std::endl << "---------------------------------------------";
    std::cout << std::endl;

    {
        PR_INSP_BRIDGE_CMD stCmd;
        PR_INSP_BRIDGE_RPY stRpy;
        stCmd.matInputImg = cv::imread("./data/TestInspBridge_1.png", cv::IMREAD_GRAYSCALE);
        stCmd.enInspMode = PR_INSP_BRIDGE_MODE::OUTER;
        stCmd.rectROI = cv::Rect(184, 828, 208, 80);
        stCmd.rectOuterSrchWindow = cv::Rect(146, 776, 285, 185);
        stCmd.vecOuterInspDirection = {PR_DIRECTION::UP, PR_DIRECTION::DOWN, PR_DIRECTION::LEFT};

        PR_InspBridge(&stCmd, &stRpy);
        PrintRpy(stRpy);
    }

    std::cout << std::endl << "---------------------------------------------";
    std::cout << std::endl << "INSPECT BRIDGE REGRESSION TEST #7 STARTING";
    std::cout << std::endl << "---------------------------------------------";
    std::cout << std::endl;

    {
        PR_INSP_BRIDGE_CMD stCmd;
        PR_INSP_BRIDGE_RPY stRpy;
        stCmd.matInputImg = cv::imread("./data/TestInspBridge_2.png", cv::IMREAD_GRAYSCALE);
        stCmd.enInspMode = PR_INSP_BRIDGE_MODE::OUTER;
        stCmd.rectROI = cv::Rect(9, 14, 45, 173);
        stCmd.rectOuterSrchWindow = cv::Rect(0, 0, 64, 202);
        stCmd.vecOuterInspDirection = {PR_DIRECTION::LEFT, PR_DIRECTION::RIGHT};

        PR_InspBridge(&stCmd, &stRpy);
        PrintRpy(stRpy);
    }
}
Ejemplo n.º 20
0
  PrimitiveTypeMapCache() {
    // if we create the TypeMap as a static function member, the constructor
    // is guarantueed to be called by only one thread (see C++11 standard sec 6.7)
    // while all other threads wait for completion. Thus no manual synchronization
    // is needed for the initialization.

    // create all type mappers

    /* convert primitive types */

    #define CONVERT_NUMBER(NAME, TYPE, PRED, CONV)                              \
     {                                                                          \
      func_t f = [](const Local<Value>& val)                                    \
        -> std::tuple<size_t, void*, cl_int> {                                  \
        if (!val->PRED()){                                                      \
         return std::tuple<size_t, void*,cl_int>(0, NULL, CL_INVALID_ARG_VALUE);\
        }                                                                       \
        void* ptr_data = new TYPE;                                              \
        size_t ptr_size = sizeof(TYPE);                                         \
        *((TYPE *)ptr_data) = val->CONV();                                      \
        return std::tuple<size_t, void*,cl_int>(ptr_size, ptr_data, 0);         \
      };                                                                        \
      m_converters[NAME] = f;                                                   \
     }

    CONVERT_NUMBER("char", cl_char, IsInt32, ToInt32()->Value);
    CONVERT_NUMBER("uchar", cl_uchar, IsInt32, ToUint32()->Value);
    CONVERT_NUMBER("short", cl_short, IsInt32, ToInt32()->Value);
    CONVERT_NUMBER("ushort", cl_ushort, IsInt32, ToUint32()->Value);
    CONVERT_NUMBER("int", cl_int , IsInt32, ToInt32()->Value);
    CONVERT_NUMBER("uint", cl_uint, IsInt32, ToUint32()->Value);
    CONVERT_NUMBER("long", cl_long, IsNumber, ToInteger()->Value);
    CONVERT_NUMBER("ulong", cl_ulong, IsNumber, ToInteger()->Value);
    CONVERT_NUMBER("float", cl_float, IsNumber, NumberValue);
    CONVERT_NUMBER("double", cl_double, IsNumber, NumberValue);
    CONVERT_NUMBER("half", cl_half, IsNumber, NumberValue);

    #undef CONVERT_NUMBER


    /* convert vector types (e.g. float4, int16, etc) */

    #define CONVERT_VECT(NAME, TYPE, I, PRED, COND)                             \
      {                                                                         \
       func_t f = [](const Local<Value>& val)                                   \
          -> std::tuple<size_t, void*, cl_int> {                                \
        if (!val->IsArray()) {                                                  \
          /*THROW_ERR(CL_INVALID_ARG_VALUE);  */                                \
          return std::tuple<size_t,void*,cl_int>(0, NULL, CL_INVALID_ARG_VALUE);\
        }                                                                       \
        Local<Array> arr = Local<Array>::Cast(val);                             \
        if (arr->Length() != I) {                                               \
          /*THROW_ERR(CL_INVALID_ARG_SIZE);*/                                   \
          return std::tuple<size_t,void*,cl_int>(0, NULL, CL_INVALID_ARG_SIZE); \
        }                                                                       \
        TYPE * vvc = new TYPE[I];                                               \
        size_t ptr_size = sizeof(TYPE) * I;                                     \
        void* ptr_data = vvc;                                                   \
        for (unsigned int i = 0; i < I; ++ i) {                                 \
          if (!arr->Get(i)->PRED()) {                                           \
            /*THROW_ERR(CL_INVALID_ARG_VALUE);*/                                \
            /*THROW_ERR(CL_INVALID_ARG_VALUE);*/                                \
          return std::tuple<size_t,void*,cl_int>(0, NULL, CL_INVALID_ARG_VALUE);\
          }                                                                     \
          vvc[i] = arr->Get(i)->COND();                                         \
        }                                                                       \
        return std::tuple<size_t,void*,cl_int>(ptr_size, ptr_data, 0);          \
      };                                                                        \
      m_converters["NAME ## I"] = f;                                            \
      }

    #define CONVERT_VECTS(NAME, TYPE, PRED, COND) \
      CONVERT_VECT(NAME, TYPE, 2, PRED, COND);\
      CONVERT_VECT(NAME, TYPE, 3, PRED, COND);\
      CONVERT_VECT(NAME, TYPE, 4, PRED, COND);\
      CONVERT_VECT(NAME, TYPE, 8, PRED, COND);\
      CONVERT_VECT(MAME, TYPE, 16, PRED, COND);

    CONVERT_VECTS("char", cl_char, IsInt32, ToInt32()->Value);
    CONVERT_VECTS("uchar", cl_uchar, IsInt32, ToUint32()->Value);
    CONVERT_VECTS("short", cl_short, IsInt32, ToInt32()->Value);
    CONVERT_VECTS("ushort", cl_ushort, IsInt32, ToUint32()->Value);
    CONVERT_VECTS("int", cl_int, IsInt32, ToInt32()->Value);
    CONVERT_VECTS("uint", cl_uint, IsInt32, ToUint32()->Value);
    CONVERT_VECTS("long", cl_long, IsNumber, ToInteger()->Value);
    CONVERT_VECTS("ulong", cl_ulong, IsNumber, ToInteger()->Value);
    CONVERT_VECTS("float", cl_float, IsNumber, NumberValue);
    CONVERT_VECTS("double", cl_double, IsNumber, NumberValue);
    CONVERT_VECTS("half", cl_half, IsNumber, NumberValue);

    #undef CONVERT_VECT
    #undef CONVERT_VECTS

    // add boolean conversion
    m_converters["bool"] = [](const Local<Value>& val) {
        size_t ptr_size = sizeof(cl_bool);
        void* ptr_data = new cl_bool;
        *((cl_bool *)ptr_data) = val->BooleanValue() ? 1 : 0;
        return std::tuple<size_t,void*,cl_int>(ptr_size, ptr_data, 0);
    };
  }
Ejemplo n.º 21
0
static void PrintInspReply(const PR_INSP_CONTOUR_RPY &stRpy) {
    std::cout << "Inspect contour status: " << ToInt32(stRpy.enStatus) << std::endl;
    std::cout << "Number of defects: " << stRpy.vecDefectContour.size() << std::endl;
}
Ejemplo n.º 22
0
 static Elem toType(Elem a) {
     return ToInt32(a);
 }
Ejemplo n.º 23
0
char ReceivedMessageArgument::AsCharUnchecked() const
{
    return (char)ToInt32( argument_ );
}
Ejemplo n.º 24
0
TSLKValue::operator int()
{
	return ToInt32();
}
Ejemplo n.º 25
0
TSLKValue::operator unsigned int()
{
	return (unsigned int)ToInt32();
}
Ejemplo n.º 26
0
static void PrintLrnReply(const PR_LRN_CONTOUR_RPY &stRpy) {
    std::cout << "Learn contour status: " << ToInt32(stRpy.enStatus) << std::endl;
    std::cout << "Result threshold: " << stRpy.nThreshold << std::endl;
    std::cout << "Number of contour: " << stRpy.vecContours.size() << std::endl;
}
Ejemplo n.º 27
0
 static void toType2(JSContext *cx, JS::Handle<JS::Value> v, Elem *out) {
     ToInt32(cx,v,out);
 }