//    폴더목록 출력(하위 디렉토리 포함)

#include <iostream>
#include <cstdio>
#include <stdio.h>
#include <map>
#include <iterator>
#include <string>
#include <fstream>
#include <dirent.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <strings.h>
#include <memory.h>
#include <stdlib.h>

using namespace std;

typedef map<string, bool> FILE_LIST;

class CFileList
{
public:
    CFileList();
    ~CFileList();

public:
    bool GetFileList(FILE_LIST& list, string strDir); //디렉토리 및 파일목록을 구한다
    void ShowFileList(FILE_LIST& list);//리스트를 출력한다
};

CFileList::CFileList()
{
}

CFileList::~CFileList()
{
}

bool CFileList::GetFileList(FILE_LIST& list, string strDir)
{
    struct stat statinfo;
    memset(&statinfo, 0, sizeof(statinfo));
    lstat(strDir.c_str(), &statinfo);
    if(!S_ISDIR(statinfo.st_mode))
    {
        cout<<strDir + " is not directory"<<endl;
        return false;
    }

    DIR *dir;
    struct dirent *entry;

     if ((dir = opendir(strDir.c_str())) == NULL)
     {
         cout<<strDir + " open error"<<endl;
        return false;
     }

    while ((entry = readdir(dir)) != NULL)
    {
        memset(&statinfo, 0, sizeof(statinfo));
        string strFilePath = strDir + "/" + entry->d_name;
        while(strFilePath.find("//") != string::npos)
                strFilePath.replace(strFilePath.find("//"), 2, "/");

        lstat(strFilePath.c_str(), &statinfo);

        if(S_ISDIR(statinfo.st_mode)) // 디렉토리 이면
        {
            if(strcmp(entry->d_name, ".") == 0 || strcmp(entry->d_name, "..") == 0)
                continue;


            list.insert(pair<string, bool>(strFilePath, true)); //디렉토리 경로를 넣음

            string strSubDir = strDir + "/" + entry->d_name;
            GetFileList(list, strSubDir); //디렉토리 안으로 들어감
        }
        else
        {
            //파일이면
            list.insert(pair<string, bool>(strFilePath, false)); //파일경로를 넣음
        }
    }

    //읽은 디렉토리 닫기
     closedir(dir);

    return true;
}

void CFileList::ShowFileList(FILE_LIST& list)
{
    FILE_LIST::iterator itr;
    for(itr = list.begin(); itr != list.end(); itr++)
    {
        if ( itr->second == true )
            cout<<"[DIRECTORY] " + itr->first<<endl;
        else
            cout<<"[FILE] " + itr->first<<endl;
    }
}

int main(int argc, char* argv[])
{
    if(argc != 2)
    {
        cout<<"usage: filelist [directory path]"<<endl;
        return 1;
    }

    CFileList FileList;

    string strSrcDir = argv[1];

    FILE_LIST file_list;

    FileList.GetFileList(file_list, strSrcDir);
    FileList.ShowFileList(file_list);

    return 0;
}

//    현재폴더 목록만 출력하는 소스

#include <stdio.h>
#include <unistd.h>
#include <dirent.h>


int main()
{
     DIR            *dir_info;
    struct dirent  *dir_entry;

    dir_info = opendir( ".");              // 현재 디렉토리를 열기
    if ( NULL != dir_info)
    {
        while( dir_entry   = readdir( dir_info))  // 디렉토리 안에 있는 모든 파일과 디렉토리 출력
        {
            printf( "%s\n", dir_entry->d_name);
        }
        closedir( dir_info);
    }
}



※※※※※※ 자세한 설명을 해드릴만큼 알지 못하며, Ubuntu에서 설치를 하고 작동하는것을 확인하는 단계입니다. 자세한 설명을 원하시면 OpenCV 공식 사이트에서 참조 하시기 바랍니다. ※※※※※※




  1. OpenCV install
    1. http://stackoverflow.com/questions/13904117/compiling-and-linking-opencv-in-ubuntu-12-04 에서 참조하였음.
    2.  sudo apt-get install libopencv-dev  
      1. sudo : Ubuntu에서 관리자 권한을 얻음. ( 암호를 알고 있어야 함.)
      2. apt-get install : 필요한 프로그램(libopencv-dev)을 설치하겠다.
      3. libopencv-dev : 설치할려고하는 파일 이름.
  2. 설치를 완료하였습니다.
  3. 이제 설치한 파일을 실행하겠습니다.
    1. g++이 설치가 안되어 있을 경우 설치한다.
      1.  sudo apt-get install g++  : 관리자 권한을 얻어서 g++을 설치한다.
    1. 필요한 예제 파일을 다운 받는다.
      1.  wget http://linux-projects.org/downloads/examples/opencv_test.cpp 
    2. 빌드 한다.
      1. http://elinux.org/Jetson/Installing_OpenCV 에서 참조하였음.
      2.  g++ opencv_test.cpp -lopencv_core -lopencv_imgproc -lopencv_highgui -o opencv_test  : 이 예제 프로그램에 한하여 빌드 옵션을 -lopencv_core -lopencv_imgproc -lopencv_highgui 를 사용하였으므로, 사용하는 프로그램에 따라 옵션을 달리 할경우가 많이 발생함.
    3. 프로그램을실행한다.
      1. 참고로 이 예제는 카메라를 필요로합니다 카메라를 연결하시고 사용하세요.
      2.  ./opencv_test 





"cvCreateFileCapture_FFMPEG"이라는 단어를 검색하고 싶으면, 

다음과 같이 검색을 한다.

grep -e cvCreateFileCapture_FFMPEG /home/OpenCV/ -R


여기서 "grep"를 이용하여 "cvCreateFileCapture_FFMPEG"단어를 "/home/OpenCV/"에서 검색한다. 그냥 "/home/"에서만 검색하고 싶은 경우에는 "-R"를 제외시킨다.


또한 검색 결과를 파일로 저장하고 싶으면 아래와 같이 한다.

grep -e cvCreateFileCapture_FFMPEG /home/OpenCV/ -R >> result.txt


"result.txt"파일명으로 저장된다.

프로젝트에서 확장자( .pro)를 클릭하고 아래 부분을 입력한다. ( 단 HEADERS, FORMS 보다 위에 입력한다. )

For example:

SOURCES += main.cpp
INCLUDEPATH += /usr/local/include/opencv
LIBS += `pkg-config opencv –cflags –libs`

or

INCLUDEPATH += /usr/local/include/opencv
LIBS += -L/usr/local/lib
LIBS += -lopencv_core
LIBS += -lopencv_imgproc
LIBS += -lopencv_highgui
LIBS += -lopencv_ml
LIBS += -lopencv_video
LIBS += -lopencv_features2d
LIBS += -lopencv_calib3d
LIBS += -lopencv_objdetect
LIBS += -lopencv_contrib
LIBS += -lopencv_legacy
LIBS += -lopencv_flann
LIBS += -lopencv_nonfree

# -L represents for Directory

# -l represents for file


* /usr/local/include/opencv 가 설치되어 있는 상태에서 위의 설정을 추가한다.

'STUDY > Qt' 카테고리의 다른 글

Qt install ( 설치 ) On Ubuntu  (0) 2014.07.16
Qt mode change  (0) 2014.07.16
Qt Library
$ sudo apt-get install libqt4-core
$ sudo apt-get install libqt4-dbg
$ sudo apt-get install libqt4-dev 
$ sudo apt-get install libqt4-gui

Qt Designer
$ sudo apt-get install qt4-designer
$ sudo apt-get install qt4-dev-tools 

Qt IDE
$ sudo apt-get install qtcreator

Compiler

$ sudo apt-get install g++ 


'STUDY > Qt' 카테고리의 다른 글

OpenCV 와 Qt 연결  (0) 2014.07.16
Qt mode change  (0) 2014.07.16

Projects -> Build Settings -> Edit build configuration : mode change ( Debug | Release )

'STUDY > Qt' 카테고리의 다른 글

OpenCV 와 Qt 연결  (0) 2014.07.16
Qt install ( 설치 ) On Ubuntu  (0) 2014.07.16

http://karytech.blogspot.kr/2012/05/opencv-24-on-ubuntu-1204.html


을 따라하자. 


설치시 필요한 것들은 여기에 포함되어있다. ( 'here'을 유심히 보면 된다. )


  • 이 글은 쉽게 컴퓨터와 감시용 카메라(  웹캠, IP카메라, 캡쳐보드에 연결된 아날로그 카메라 등 )를 이용하여 감시 카메라 시스템을 설치한다.
  • 설치 시 필요한 것들은 다음과 같다.
    • Ubuntu
    • 카메라( Camera )  
  • 패키지를 설치하기 위해서 관리자 권한을 획득한다.
    • ~$ sudo -i
    • 비밀번호( Password )를 입력한다.
  • ssl-cert 패키지를 설치한다.
    • ~# apt-get install ssl-cert
  • 존마인더( zoneminder ) 패키지를 설치한다.
    • ~# apt-get install zoneminder
    • 아래와 같이 zoneminder에 설치에 필요한 필요한 패키지들이 추가로 필요하다고 알려준다. 따라서 y로 추가 패키지도 설치한다.
    • 데이터베이스( DB : Data Base )의 비밀번호(  Password )를 입력하라고 아래와 같이 나온다.
      • 설정하고 싶은 비밀번호를 입력한다. 
    • 재확인은 다음과 같다. ( 위에서 설정한 비밀번호와 똑같이 입력하면 된다. )
    • nullmailer을 설정하라고 아래와 같이 나온다. 하지만 난 이게 무슨 의미인지 몰라서 그냥 "ok"를 클릭했다. ( 이와 같이 해도 무슨 문제가 있는지 모르지만.... 일단은 상관없다 )
    • 두번째도 위와 같다
    • 추가로 H.264 패키지를 설치해도 된다.
      • ~# apt-get install x264
    • 존마인더 시작파일을 수정해서, MySQL을 수정하여 딜레이를 추가한다. ( 에디터( Editer )는 "vi"를 사용하였다. )
      • ~# vi /etc/init.d/zoneminder
      • 다음과 같이 24번째 줄의 "sleep 15"를 추가한다.
    • 아파치( apache ) 설정은 다음과 같다.
      • ~# ln -s /etc/zm/apache.conf /etc/apache2/conf.d/zoneminder.conf
      • ~# /etc/init.d/apache2 force-reload
      • ~# /adduser www-data video
      • ~# make-ssl-cert generate-default-snakeoil --force-overwrite
      • ~# a2enmod ssl
      • ~# a2ensite default-ssl
      • ~# service apache2 restart
      • 웹서버에 접속이 가능하다.
        • 웹주소를 "https://서버주소"로 들어가면 된다.
          • 예를 들면, 
            • "https://127.0.0.1"
            • "https://localhost"
            • 등이 있다.
        • 실행화면은 다음과 같다.
    • 캠보졸라( cambozola )를 설치한다.
      • ~# cd /usr/src
      • ~# wget https://www.andywilcock.com/code/cambozola/cambozola-latest.tar.gz
      • ~# tar -xzvf cambozola-latest.tar.gz
      • cp cambozola-0.935/dist/cambozola.jar /usr/share/zoneminder
        • 설치당시 현재 0.935 이다.
    • NTP 시간 동기화를 한다.
      • ~# vi /etc/cron.daily/ntpdate
        • 여기에 다음과 같이 입력한다.
          • #! /bin/sh
          • ntpdate 0.kr.pool.ntp.org
      •  실행가능한 권한을 준다.
        • ~# chmod 755 /etc/cron.daily/ntpdate
    • 재부팅 한다.
      • ~# Shutdown -r now
  • zoneminder 화면 확인
    • 익스플로러, 크롬, 및 파이어폭스 등 에서 다음과 같이 입력한다.
    • https://localhost/zm
    • https://127.0.0.1/zm
    • https://computerIP/zm
      • 파이어폭스에서 확인결과는 다음과 같다.


  1. 구성 속성 -> 링커 -> 디버깅 -> 디버그 정보 생성 : 예(/DEBUG) 로 체크
  2. 구성 속성 -> C/C++ -> 최적화 -> 최적화 : 사용 안함 (/Od)로 체크
  3. 도구 -> 옵션 -> 디버깅 -> 일반 -> 소스 파일이 원래 버전과 정확하게 일치해야 함 : 체크 해제


+ Recent posts