Example #1
0
static bool isDir(const cv::String& path, DIR* dir)
{
#if defined _WIN32 || defined WINCE
    DWORD attributes;
    BOOL status = TRUE;
    if (dir)
        attributes = dir->data.dwFileAttributes;
    else
    {
        WIN32_FILE_ATTRIBUTE_DATA all_attrs;
#ifdef WINRT
        wchar_t wpath[MAX_PATH];
        size_t copied = mbstowcs(wpath, path.c_str(), MAX_PATH);
        CV_Assert((copied != MAX_PATH) && (copied != (size_t)-1));
        status = ::GetFileAttributesExW(wpath, GetFileExInfoStandard, &all_attrs);
#else
        status = ::GetFileAttributesExA(path.c_str(), GetFileExInfoStandard, &all_attrs);
#endif
        attributes = all_attrs.dwFileAttributes;
    }

    return status && ((attributes & FILE_ATTRIBUTE_DIRECTORY) != 0);
#else
    (void)dir;
    struct stat stat_buf;
    if (0 != stat( path.c_str(), &stat_buf))
        return false;
    int is_dir = S_ISDIR( stat_buf.st_mode);
    return is_dir != 0;
#endif
}
Example #2
0
    void print_info(ID3D11Texture2D* pSurface, int mode, float fps, cv::String oclDevName)
    {
        HRESULT r;

        UINT subResource = ::D3D11CalcSubresource(0, 0, 1);

        D3D11_MAPPED_SUBRESOURCE mappedTex;
        r = m_pD3D11Ctx->Map(pSurface, subResource, D3D11_MAP_WRITE_DISCARD, 0, &mappedTex);
        if (FAILED(r))
        {
            return;
        }

        cv::Mat m(m_height, m_width, CV_8UC4, mappedTex.pData, (int)mappedTex.RowPitch);

        cv::String strMode    = cv::format("%s", m_modeStr[mode].c_str());
        cv::String strFPS     = cv::format("%2.1f", fps);
        cv::String strDevName = cv::format("%s", oclDevName.c_str());

        cv::putText(m, strMode, cv::Point(0, 16), 1, 0.8, cv::Scalar(0, 0, 0));
        cv::putText(m, strFPS, cv::Point(0, 32), 1, 0.8, cv::Scalar(0, 0, 0));
        cv::putText(m, strDevName, cv::Point(0, 48), 1, 0.8, cv::Scalar(0, 0, 0));

        m_pD3D11Ctx->Unmap(pSurface, subResource);

        return;
    } // printf_info()
Example #3
0
    void print_info(ID3D10Texture2D* pSurface, int mode, float fps, cv::String oclDevName)
    {
        HRESULT r;

        UINT subResource = ::D3D10CalcSubresource(0, 0, 1);

        D3D10_MAPPED_TEXTURE2D mappedTex;
        r = pSurface->Map(subResource, D3D10_MAP_WRITE_DISCARD, 0, &mappedTex);
        if (FAILED(r))
        {
            return;
        }

        cv::Mat m(m_height, m_width, CV_8UC4, mappedTex.pData, (int)mappedTex.RowPitch);

        cv::String strMode       = cv::format("%s", m_modeStr[mode].c_str());
        cv::String strProcessing = m_demo_processing ? "blur frame" : "copy frame";
        cv::String strFPS        = cv::format("%2.1f", fps);
        cv::String strDevName    = cv::format("%s", oclDevName.c_str());

        cv::putText(m, strMode, cv::Point(0, 16), 1, 0.8, cv::Scalar(0, 0, 0));
        cv::putText(m, strProcessing, cv::Point(0, 32), 1, 0.8, cv::Scalar(0, 0, 0));
        cv::putText(m, strFPS, cv::Point(0, 48), 1, 0.8, cv::Scalar(0, 0, 0));
        cv::putText(m, strDevName, cv::Point(0, 64), 1, 0.8, cv::Scalar(0, 0, 0));

        m_pSurface->Unmap(subResource);

        return;
    } // print_info()
Example #4
0
 void save(cv::String filename)
 {
     FILE* fout = fopen(filename.c_str(), "wb");
     /*if (fout == NULL) {
         throw FLANNException("Cannot open file");
     }*/
     save_header(fout, *nnIndex_);
     saveIndex(fout);
     fclose(fout);
 }
static bool isDir(const cv::String& path, DIR* dir)
{
#if defined WIN32 || defined _WIN32 || defined WINCE
    DWORD attributes;
    if (dir)
        attributes = dir->data.dwFileAttributes;
    else
        attributes = ::GetFileAttributes(path.c_str());

    return (attributes != INVALID_FILE_ATTRIBUTES) && ((attributes & FILE_ATTRIBUTE_DIRECTORY) != 0);
#else
    (void)dir;
    struct stat stat_buf;
    if (0 != stat( path.c_str(), &stat_buf))
        return false;
    int is_dir = S_ISDIR( stat_buf.st_mode);
    return is_dir != 0;
#endif
}
Example #6
0
static void glob_rec(const cv::String& directory, const cv::String& wildchart, std::vector<cv::String>& result, bool recursive)
{
    DIR *dir;
    struct dirent *ent;

    if ((dir = opendir (directory.c_str())) != 0)
    {
        /* find all the files and directories within directory */
        try
        {
            while ((ent = readdir (dir)) != 0)
            {
                const char* name = ent->d_name;
                if((name[0] == 0) || (name[0] == '.' && name[1] == 0) || (name[0] == '.' && name[1] == '.' && name[2] == 0))
                    continue;

                cv::String path = directory + native_separator + name;

                if (isDir(path, dir))
                {
                    if (recursive)
                        glob_rec(path, wildchart, result, recursive);
                }
                else
                {
                    if (wildchart.empty() || wildcmp(name, wildchart.c_str()))
                        result.push_back(path);
                }
            }
        }
        catch (...)
        {
            closedir(dir);
            throw;
        }
        closedir(dir);
    }
    else CV_Error(CV_StsObjectNotFound, cv::format("could not open directory: %s", directory.c_str()));
}
Example #7
0
bool createDirectory(const cv::String& path)
{
    CV_INSTRUMENT_REGION();
#if defined WIN32 || defined _WIN32 || defined WINCE
#ifdef WINRT
    wchar_t wpath[MAX_PATH];
    size_t copied = mbstowcs(wpath, path.c_str(), MAX_PATH);
    CV_Assert((copied != MAX_PATH) && (copied != (size_t)-1));
    int result = CreateDirectoryA(wpath, NULL) ? 0 : -1;
#else
    int result = _mkdir(path.c_str());
#endif
#elif defined __linux__ || defined __APPLE__ || defined __HAIKU__ || defined __FreeBSD__
    int result = mkdir(path.c_str(), 0777);
#else
    int result = -1;
#endif

    if (result == -1)
    {
        return isDirectory(path);
    }
    return true;
}
Example #8
0
CV_EXPORTS void remove_all(const cv::String& path)
{
    if (!exists(path))
        return;
    if (isDirectory(path))
    {
        std::vector<String> entries;
        utils::fs::glob(path, cv::String(), entries, false, true);
        for (size_t i = 0; i < entries.size(); i++)
        {
            const String& e = entries[i];
            remove_all(e);
        }
#ifdef _MSC_VER
        bool result = _rmdir(path.c_str()) == 0;
#else
        bool result = rmdir(path.c_str()) == 0;
#endif
        if (!result)
        {
            CV_LOG_ERROR(NULL, "Can't remove directory: " << path);
        }
    }
    else
    {
#ifdef _MSC_VER
        bool result = _unlink(path.c_str()) == 0;
#else
        bool result = unlink(path.c_str()) == 0;
#endif
        if (!result)
        {
            CV_LOG_ERROR(NULL, "Can't remove file: " << path);
        }
    }
}
Example #9
0
    void print_info(LPDIRECT3DSURFACE9 pSurface, int mode, float time, cv::String oclDevName)
    {
        HDC hDC;

        HRESULT r = pSurface->GetDC(&hDC);
        if (FAILED(r))
        {
            return;
        }

        HFONT hFont = (HFONT)::GetStockObject(SYSTEM_FONT);

        HFONT hOldFont = (HFONT)::SelectObject(hDC, hFont);

        if (hOldFont)
        {
            TEXTMETRIC tm;
            ::GetTextMetrics(hDC, &tm);

            char buf[256];
            int  y = 0;

            buf[0] = 0;
            sprintf(buf, "mode: %s", m_modeStr[mode].c_str());
            ::TextOut(hDC, 0, y, buf, (int)strlen(buf));

            y += tm.tmHeight;
            buf[0] = 0;
            sprintf(buf, m_demo_processing ? "blur frame" : "copy frame");
            ::TextOut(hDC, 0, y, buf, (int)strlen(buf));

            y += tm.tmHeight;
            buf[0] = 0;
            sprintf(buf, "time: %4.1f msec", time);
            ::TextOut(hDC, 0, y, buf, (int)strlen(buf));

            y += tm.tmHeight;
            buf[0] = 0;
            sprintf(buf, "OpenCL device: %s", oclDevName.c_str());
            ::TextOut(hDC, 0, y, buf, (int)strlen(buf));

            ::SelectObject(hDC, hOldFont);
        }

        r = pSurface->ReleaseDC(hDC);

        return;
    } // print_info()
Example #10
0
void CameraWrapperConnector::fillListWrapperLibs(const cv::String& folderPath, std::vector<cv::String>& listLibs)
{
    DIR *dp;
    struct dirent *ep;

    dp = opendir (folderPath.c_str());
    if (dp != NULL)
    {
        while ((ep = readdir (dp))) {
            const char* cur_name=ep->d_name;
            if (strstr(cur_name, PREFIX_CAMERA_WRAPPER_LIB)) {
                listLibs.push_back(cur_name);
                LOGE("||%s", cur_name);
            }
        }
        (void) closedir (dp);
    }
}
Example #11
0
    void print_info(MODE mode, float time, cv::String& oclDevName)
    {
#if defined(_WIN32)
        HDC hDC = m_hDC;

        HFONT hFont = (HFONT)::GetStockObject(SYSTEM_FONT);

        HFONT hOldFont = (HFONT)::SelectObject(hDC, hFont);

        if (hOldFont)
        {
            TEXTMETRIC tm;
            ::GetTextMetrics(hDC, &tm);

            char buf[256+1];
            int  y = 0;

            buf[0] = 0;
            sprintf_s(buf, sizeof(buf)-1, "Mode: %s OpenGL %s", m_modeStr[mode].c_str(), use_buffer() ? "buffer" : "texture");
            ::TextOut(hDC, 0, y, buf, (int)strlen(buf));

            y += tm.tmHeight;
            buf[0] = 0;
            sprintf_s(buf, sizeof(buf)-1, "Time, msec: %2.1f", time);
            ::TextOut(hDC, 0, y, buf, (int)strlen(buf));

            y += tm.tmHeight;
            buf[0] = 0;
            sprintf_s(buf, sizeof(buf)-1, "OpenCL device: %s", oclDevName.c_str());
            ::TextOut(hDC, 0, y, buf, (int)strlen(buf));

            ::SelectObject(hDC, hOldFont);
        }
#elif defined(__linux__)

        char buf[256+1];
        snprintf(buf, sizeof(buf)-1, "Time, msec: %2.1f, Mode: %s OpenGL %s, Device: %s", time, m_modeStr[mode].c_str(), use_buffer() ? "buffer" : "texture", oclDevName.c_str());
        XStoreName(m_display, m_window, buf);
#endif
    }
Example #12
0
    void print_info(int mode, float fps, cv::String oclDevName)
    {
#if defined(WIN32) || defined(_WIN32)
        HDC hDC = m_hDC;

        HFONT hFont = (HFONT)::GetStockObject(SYSTEM_FONT);

        HFONT hOldFont = (HFONT)::SelectObject(hDC, hFont);

        if (hOldFont)
        {
            TEXTMETRIC tm;
            ::GetTextMetrics(hDC, &tm);

            char buf[256+1];
            int  y = 0;

            buf[0] = 0;
            sprintf_s(buf, sizeof(buf)-1, "Mode: %s", m_modeStr[mode].c_str());
            ::TextOut(hDC, 0, y, buf, (int)strlen(buf));

            y += tm.tmHeight;
            buf[0] = 0;
            sprintf_s(buf, sizeof(buf)-1, "FPS: %2.1f", fps);
            ::TextOut(hDC, 0, y, buf, (int)strlen(buf));

            y += tm.tmHeight;
            buf[0] = 0;
            sprintf_s(buf, sizeof(buf)-1, "OpenCL device: %s", oclDevName.c_str());
            ::TextOut(hDC, 0, y, buf, (int)strlen(buf));

            ::SelectObject(hDC, hOldFont);
        }
#elif defined(__linux__)

        char buf[256+1];
        snprintf(buf, sizeof(buf)-1, "FPS: %2.1f Mode: %s Device: %s", fps, m_modeStr[mode].c_str(), oclDevName.c_str());
        XStoreName(m_display, m_window, buf);
#endif
    }
Example #13
0
 static inline void save(OutputArchive& ar, const cv::String& val)
 {
     ar = Nan::New<v8::String>(val.c_str());
 }
Example #14
0
void VideoCapture_create(CvCapture*& capture, Ptr<IVideoCapture>& icap, VideoCaptureAPIs api, const cv::String& filename)
{
    switch (api)
    {
    default:
        CV_LOG_WARNING(NULL, "VideoCapture(filename=" << filename << ") was built without support of requested backendID=" << (int)api);
        break;
#if defined HAVE_LIBV4L || defined HAVE_CAMV4L || defined HAVE_CAMV4L2 || defined HAVE_VIDEOIO
    case CAP_V4L:
        TRY_OPEN_LEGACY(cvCreateCameraCapture_V4L(filename.c_str()))
        break;
#endif

#ifdef HAVE_VFW
    case CAP_VFW:
        TRY_OPEN_LEGACY(cvCreateFileCapture_VFW(filename.c_str()))
        break;
#endif

#if defined(HAVE_QUICKTIME) || defined(HAVE_QTKIT)
    case CAP_QT:
        TRY_OPEN_LEGACY(cvCreateFileCapture_QT(filename.c_str()))
        break;
#endif

#ifdef HAVE_AVFOUNDATION
    case CAP_AVFOUNDATION:
        TRY_OPEN_LEGACY(cvCreateFileCapture_AVFoundation(filename.c_str()))
        break;
#endif

#ifdef HAVE_OPENNI
    case CAP_OPENNI:
        TRY_OPEN_LEGACY(cvCreateFileCapture_OpenNI(filename.c_str()))
        break;
#endif

#ifdef HAVE_OPENNI2
    case CAP_OPENNI2:
        TRY_OPEN_LEGACY(cvCreateFileCapture_OpenNI2(filename.c_str()))
        break;
#endif
#ifdef HAVE_XIMEA
    case CAP_XIAPI:
        TRY_OPEN_LEGACY(cvCreateCameraCapture_XIMEA(filename.c_str()))
        break;
#endif
    case CAP_IMAGES:
        TRY_OPEN_LEGACY(cvCreateFileCapture_Images(filename.c_str()))
        break;
#ifdef HAVE_FFMPEG
    case CAP_FFMPEG:
        TRY_OPEN(cvCreateFileCapture_FFMPEG_proxy(filename))
        break;
#endif
#ifdef HAVE_GSTREAMER
    case CAP_GSTREAMER:
        TRY_OPEN(createGStreamerCapture(filename))
        break;
#endif
#ifdef HAVE_XINE
    case CAP_XINE:
        TRY_OPEN(createXINECapture(filename.c_str()))
        break;
#endif
#ifdef HAVE_MSMF
    case CAP_MSMF:
        TRY_OPEN(cvCreateCapture_MSMF(filename))
        break;
#endif
#ifdef HAVE_GPHOTO2
    case CAP_GPHOTO2:
        TRY_OPEN(createGPhoto2Capture(filename))
        break;
#endif
#ifdef HAVE_MFX
    case CAP_INTEL_MFX:
        TRY_OPEN(makePtr<VideoCapture_IntelMFX>(filename))
        break;
#endif
    case CAP_OPENCV_MJPEG:
        TRY_OPEN(createMotionJpegCapture(filename))
        break;
    } // switch
}
Example #15
0
void imshow(cv::String name, cv::Mat im)
{
  GuiReceiver::getInstance()->showImage(QString(name.c_str()), im);
}