Programming/openCV2015. 9. 25. 10:09

예전에 받아둔걸로 다시 해보는데..

음.. 비디오가 몇개 있는진 알 수 없다 인가?!

새로운 API가 나오기 전까지는 일일이 open 해보고 리턴값으로 체크해야 할 듯..


[링크 : http://docs.opencv.org/.../reading_and_writing_images_and_video.html?highlight=videocapture]

[링크 : http://stackoverflow.com/questions/24630158/how-to-get-video-capture-devices-information]

'Programming > openCV' 카테고리의 다른 글

opencv highgui trackbar  (0) 2015.09.27
opencv2 마우스 이벤트 / 클릭 위치  (0) 2015.09.25
openCV Mat Class  (0) 2014.07.04
openCV2 관련 꿍시렁 꿍시렁  (0) 2014.07.04
opencv2 highgui  (0) 2014.07.03
Posted by 구차니
Programming/openCV2014. 7. 4. 18:13
도서관에서 빌려와서 보는 책 정리중
OpenCV2를활용한컴퓨터비전프로그래밍
카테고리 컴퓨터/IT > 프로그래밍/언어
지은이 로버트 라가니에 (에이콘출판, 2012년)
상세보기

가장 많이 쓰일 클래스는 Mat인데 Matrix 답게 이미지를 행렬로 처리하는 클래스이다.

변수
rows , cols, step 은 이미지의 수직, 수평 해상도와 step은 실제 폭(색상이나 바이트 얼라인 포함한 data width)을 나타내며
data는 순수 이미지에 대한 포인터를 돌려준다.

메소드
row() col()은 해당 행/열에 대한 새로운 Matrix를 생성하고
channels()는 몇 채널인지를 알려준다. 만약 RGB라면 3개 채널(R,G,B) 흑백이라면 1채널을 돌려준다.
ptr()은 해당 데이터에 대한 포인터를
at()은 해당 데이터를 돌려준다.

class CV_EXPORTS Mat
{
public:
    //! returns a new matrix header for the specified row
    Mat row(int y) const;
    //! returns a new matrix header for the specified column
    Mat col(int x) const;

    /*! includes several bit-fields:
         - the magic signature
         - continuity flag
         - depth
         - number of channels
     */
    int flags;
    //! the matrix dimensionality, >= 2
    int dims;
    //! the number of rows and columns or (-1, -1) when the matrix has more than 2 dimensions
    int rows, cols;
    //! pointer to the data
    uchar* data;

    //! returns element type, similar to CV_MAT_TYPE(cvmat->type)
    int type() const;
    //! returns element type, similar to CV_MAT_DEPTH(cvmat->type)
    int depth() const;
    //! returns element type, similar to CV_MAT_CN(cvmat->type)
    int channels() const;

    //! returns pointer to (i0,i1) submatrix along the dimensions #0 and #1
    uchar* ptr(int i0, int i1);
    const uchar* ptr(int i0, int i1) const;

    //! template version of the above method
    template<typename _Tp> _Tp* ptr(int i0=0);

    //! the same as above, with the pointer dereferencing
    template<typename _Tp> _Tp& at(int i0=0);

    MSize size;
    MStep step;

}; 

Posted by 구차니
Programming/openCV2014. 7. 4. 13:23
openCV 2.3.1
디버그 모드로 하면 tbb_debug.dll 을 요구함
-> intel TBB 설치 하등가..
[링크 : http://stackoverflow.com/questions/7293160/c-tbb-debug-dll-missing]

크아아아앙 45MB에 2분이나 걸려 받았더니 여기에 두구둥!!!



openCV 2.4.7 / 2.4.9
라이브러리가 깨졌는지 메모리 침범하는 듯한 현상 발생
[링크 : http://stackoverflow.com/.../why-do-the-characters-iiii-get-stuck-onto-the-begining-of-my-strings]


걍 짜증나서 2.3.1에 릴리즈 모드 사용중 ㅠㅠ
일단 tbb 정도는 설치해 볼까나..

'Programming > openCV' 카테고리의 다른 글

opencv2.. VideoCapture 클래스..  (0) 2015.09.25
openCV Mat Class  (0) 2014.07.04
opencv2 highgui  (0) 2014.07.03
opencv2 VideoCapture::get() / set() - 웹캠 설정 읽어오기  (2) 2014.07.03
opencv2 채널분리하기(split)  (0) 2014.07.03
Posted by 구차니
Programming/openCV2014. 7. 3. 15:02
highgui는 이미지를 불러오거나 GUI를 꾸미기 위한 기능을 지원한다.

크게는 윈도우 생성/조절/파괴 및 키 입력대기
CV_EXPORTS_W void namedWindow(const string& winname, int flags = WINDOW_AUTOSIZE);
CV_EXPORTS_W void destroyWindow(const string& winname);
CV_EXPORTS_W void destroyAllWindows();

CV_EXPORTS_W void resizeWindow(const string& winname, int width, int height);
CV_EXPORTS_W void moveWindow(const string& winname, int x, int y);

CV_EXPORTS_W int waitKey(int delay = 0);

이미지 불러오기/저장/출력
CV_EXPORTS_W void imshow(const string& winname, InputArray mat);
 
CV_EXPORTS_W Mat imread( const string& filename, int flags=1 );
CV_EXPORTS_W bool imwrite( const string& filename, InputArray img, const vector<int>& params=vector<int>());
CV_EXPORTS_W Mat imdecode( InputArray buf, int flags );
CV_EXPORTS Mat imdecode( InputArray buf, int flags, Mat* dst );
CV_EXPORTS_W bool imencode( const string& ext, InputArray img,
                            CV_OUT vector<uchar>& buf,
                            const vector<int>& params=vector<int>()); 

비디오 캡쳐(파일 및 웹캠 지원)
class CV_EXPORTS_W VideoCapture
{
public:
    CV_WRAP VideoCapture();
    CV_WRAP VideoCapture(const string& filename);
    CV_WRAP VideoCapture(int device);

    virtual ~VideoCapture();
    CV_WRAP virtual bool open(const string& filename);
    CV_WRAP virtual bool open(int device);
    CV_WRAP virtual bool isOpened() const;
    CV_WRAP virtual void release();

    CV_WRAP virtual bool grab();
    CV_WRAP virtual bool retrieve(CV_OUT Mat& image, int channel=0);
    virtual VideoCapture& operator >> (CV_OUT Mat& image);
    CV_WRAP virtual bool read(CV_OUT Mat& image);

    CV_WRAP virtual bool set(int propId, double value);
    CV_WRAP virtual double get(int propId);

protected:
    Ptr<CvCapture> cap;
};


class CV_EXPORTS_W VideoWriter
{
public:
    CV_WRAP VideoWriter();
    CV_WRAP VideoWriter(const string& filename, int fourcc, double fps,
                Size frameSize, bool isColor=true);

    virtual ~VideoWriter();
    CV_WRAP virtual bool open(const string& filename, int fourcc, double fps,
                      Size frameSize, bool isColor=true);
    CV_WRAP virtual bool isOpened() const;
    CV_WRAP virtual void release();
    virtual VideoWriter& operator << (const Mat& image);
    CV_WRAP virtual void write(const Mat& image);

protected:
    Ptr<CvVideoWriter> writer;
};  




Posted by 구차니
Programming/openCV2014. 7. 3. 14:35

v4l2의 문제인지 설정은 잘안되고
못 불러 오는 설정사항도 많다 -_-a

VideoCapture::get
C++: double VideoCapture::get(int propId)
C: double cvGetCaptureProperty(CvCapture* capture, int property_id)

propId – Property identifier. It can be one of the following:
– CV_CAP_PROP_POS_MSEC Current position of the video file in milliseconds or video capture timestamp.
– CV_CAP_PROP_POS_FRAMES 0-based index of the frame to be decoded/captured next.
– CV_CAP_PROP_POS_AVI_RATIO Relative position of the video file: 0 - start of the film, 1 - end of the film.
CV_CAP_PROP_FRAME_WIDTH Width of the frames in the video stream.
CV_CAP_PROP_FRAME_HEIGHT Height of the frames in the video stream.
– CV_CAP_PROP_FPS Frame rate.
– CV_CAP_PROP_FOURCC 4-character code of codec.
– CV_CAP_PROP_FRAME_COUNT Number of frames in the video file.
– CV_CAP_PROP_FORMAT Format of the Mat objects returned by retrieve() .
– CV_CAP_PROP_MODE Backend-specific value indicating the current capture mode.
– CV_CAP_PROP_BRIGHTNESS Brightness of the image (only for cameras).
– CV_CAP_PROP_CONTRAST Contrast of the image (only for cameras).
– CV_CAP_PROP_SATURATION Saturation of the image (only for cameras).
– CV_CAP_PROP_HUE Hue of the image (only for cameras).
– CV_CAP_PROP_GAIN Gain of the image (only for cameras).
– CV_CAP_PROP_EXPOSURE Exposure (only for cameras).
– CV_CAP_PROP_CONVERT_RGB Boolean flags indicating whether images should be converted to RGB.
– CV_CAP_PROP_WHITE_BALANCE Currently not supported
– CV_CAP_PROP_RECTIFICATION Rectification flag for stereo cameras (note: only supported by DC1394 v 2.x backend currently) 

웹캠 설정 덤프
주석처리한 두개는 2.3.1에서는 지원하지 않고 2.4.9 에서 지원하는 항목이다.
                VideoCapture cap(0);
 
               cout << "POS_MSEC : "           << cap.get(CV_CAP_PROP_POS_MSEC) << endl;
                cout << "POS_FRAMES : "         << cap.get(CV_CAP_PROP_POS_FRAMES) << endl;
                cout << "POS_AVI_RATIO : "      << cap.get(CV_CAP_PROP_POS_AVI_RATIO) << endl;
                cout << "POS_FRAME_WIDTH : "    << cap.get(CV_CAP_PROP_FRAME_WIDTH) << endl;
                cout << "POS_FRAME_HEIGHT : "   << cap.get(CV_CAP_PROP_FRAME_HEIGHT) << endl;
                cout << "FPS : "                << cap.get(CV_CAP_PROP_FPS) << endl;
                cout << "FOURCC : "             << cap.get(CV_CAP_PROP_FOURCC) << endl;
//              cout << "FRAME_OUT : "          << cap.get(CV_CAP_PROP_FRAME_OUT) << endl;
                cout << "FORMAT : "             << cap.get(CV_CAP_PROP_FORMAT) << endl;
                cout << "MODE : "               << cap.get(CV_CAP_PROP_MODE) << endl;
                cout << "BRIHTNESS : "          << cap.get(CV_CAP_PROP_BRIGHTNESS) << endl;
                cout << "CONTRAST : "           << cap.get(CV_CAP_PROP_CONTRAST) << endl;
                cout << "SATURATION : "         << cap.get(CV_CAP_PROP_SATURATION) << endl;
                cout << "HUE : "                << cap.get(CV_CAP_PROP_HUE) << endl;
                cout << "GAIN : "               << cap.get(CV_CAP_PROP_GAIN) << endl;
                cout << "EXPOSURE : "           << cap.get(CV_CAP_PROP_EXPOSURE) << endl;
                cout << "CONVERT_RGB : "        << cap.get(CV_CAP_PROP_CONVERT_RGB) << endl;
//              cout << "WHITE_BALANCE : "      << cap.get(CV_CAP_PROP_WHITE_BALANCE) << endl;
                cout << "RECTIFICATION : "      << cap.get(CV_CAP_PROP_RECTIFICATION) << endl; 



'Programming > openCV' 카테고리의 다른 글

openCV2 관련 꿍시렁 꿍시렁  (0) 2014.07.04
opencv2 highgui  (0) 2014.07.03
opencv2 채널분리하기(split)  (0) 2014.07.03
opencv2 rgb2hsv color space 변환하기  (0) 2014.07.02
openCV2 2.3.1 ubuntu 컴파일하기  (0) 2014.07.01
Posted by 구차니
Programming/openCV2014. 7. 3. 14:02
core.hpp에 선언되어 있는 split을 사용하면 된다.
//! makes multi-channel array out of several single-channel arrays
CV_EXPORTS void merge(const Mat* mv, size_t count, OutputArray dst);
//! makes multi-channel array out of several single-channel arrays
CV_EXPORTS_W void merge(const vector<Mat>& mv, OutputArray dst);
    
//! copies each plane of a multi-channel array to a dedicated array
CV_EXPORTS void split(const Mat& src, Mat* mvbegin);
//! copies each plane of a multi-channel array to a dedicated array
CV_EXPORTS_W void split(const Mat& m, CV_OUT vector<Mat>& mv); 

vector<Mat> 형으로 변수를 선언하여
split(src, dst); 식으로 사용하면 되며
imshow에서 channel[0] 이런식으로 하면 채널별로 출력하면 된다.

[링크 : http://opencvexamples.blogspot.com/2013/10/split-and-merge-functions.html#.U7TjMPl_vKl]
[링크 : http://compvisionlab.wordpress.com/2013/03/07/opencv-basics-splitting-rgb-channels/]
[링크 : http://denislantsman.com/?p=103]
[링크 : http://baram4815.tistory.com/entry/OpenCV-2이미지에서-RGB-채널-분리
[링크 : http://baram4815.tistory.com/entry/OpenCVsplit-and-merge]
Posted by 구차니
Programming/openCV2014. 7. 2. 23:45
어렵거나 대단한 코드는 아니고 단순하게 RGB를 HSV로 변환하는 코드이다.

BGR 이니까.. 블루값에 Hue 성분이 들어갔으려나?
나중에 색상 조절해서 채널별로 출력을 해봐야겠다



#include <opencv2/core/core.hpp>
#include <opencv2/imgproc/imgproc.hpp>
#include <opencv2/highgui/highgui.hpp>
#include <iostream>

using namespace cv;
using namespace std;

int main(int argc, char* argv[])
{
        VideoCapture cap(0);
        if(!cap.isOpened())
        {
                cout << "No camera detected" << endl;
                return -1;
        }
        else
        {
                cout << "In capture ..." << endl;
        }

        namedWindow( "Display window", WINDOW_AUTOSIZE );

    for(;;)
    {
                Mat frame;
                Mat hsv;
                if(!cap.read(frame)) break;

                cvtColor(frame,hsv, CV_BGR2HSV);
                imshow("Display window", frame);
                imshow("HSV window", hsv);
                if(waitKey(30) >= 0) break;
    }

        return 0;
}

imgproc.hpp에 다음과 같이 정의 되어 있으며
cvtColor()는 독립된 함수로 되어있다.(클래스 랩핑이 안되어 있다)
enum
{
    COLOR_BGR2HSV     =40,
    COLOR_RGB2HSV     =41,
 
    COLOR_COLORCVT_MAX  = 135
};
 
//! converts image from one color space to another
CV_EXPORTS_W void cvtColor( InputArray src, OutputArray dst, int code, int dstCn=0 ); 
Posted by 구차니
Programming/openCV2014. 7. 1. 17:49
소스는 이전글 참조
2014/07/01 - [Programming/openCV] - openCV2 2.4.9 + VS2008 좌충우돌 프로젝트 생성하기 

$ g++ cv2cam.cpp `pkg-config --libs opencv` 

$ pkg-config --libs opencv
-lopencv_core -lopencv_imgproc -lopencv_highgui -lopencv_ml -lopencv_video -lopencv_features2d -lopencv_calib3d -lopencv_objdetect -lopencv_contrib -lopencv_legacy -lopencv_flann

[링크 : https://help.ubuntu.com/community/OpenCV ] 

일단.. #if 로 막은 아래소스를 사용한건데
2.3.1에서는 문제없이 되는 것을 봐서는 윈도우에서 라이브러리 버전이 꼬였거나 먼가 설정 문제인 듯 하다.




Posted by 구차니
Programming/openCV2014. 7. 1. 12:43
플랫폼
win7 64bit
VS2008
opencv 2.3.1 / opencv 2.4.7.2 / opencv 2.4.9

프로젝트 설정
include path 설정


library path 설정


library 목록 설정



왼쪽은 릴리즈용 오른쪽은 디버깅용(*d.lib)이다.
2.3.1
opencv_calib3d231.lib
opencv_contrib231.lib
opencv_core231.lib
opencv_features2d231.lib
opencv_flann231.lib
opencv_gpu231.lib
opencv_highgui231.lib
opencv_imgproc231.lib
opencv_legacy231.lib
opencv_ml231.lib
opencv_objdetect231.lib
opencv_ts231.lib
opencv_video231.lib 
opencv_calib3d231d.lib
opencv_contrib231d.lib
opencv_core231d.lib
opencv_features2d231d.lib
opencv_flann231d.lib
opencv_gpu231d.lib
opencv_highgui231d.lib
opencv_imgproc231d.lib
opencv_legacy231d.lib
opencv_ml231d.lib
opencv_objdetect231d.lib
opencv_ts231d.lib
opencv_video231d.lib


2.4.7

opencv_calib3d247.lib

opencv_contrib247.lib

opencv_core247.lib

opencv_features2d247.lib

opencv_flann247.lib

opencv_gpu247.lib

opencv_highgui247.lib

opencv_imgproc247.lib

opencv_legacy247.lib

opencv_ml247.lib

opencv_nonfree247.lib

opencv_objdetect247.lib

opencv_ocl247.lib

opencv_photo247.lib

opencv_stitching247.lib

opencv_superres247.lib

opencv_ts247.lib

opencv_video247.lib

opencv_videostab247.lib 

opencv_calib3d247d.lib

opencv_contrib247d.lib

opencv_core247d.lib

opencv_features2d247d.lib

opencv_flann247d.lib

opencv_gpu247d.lib

opencv_highgui247d.lib

opencv_imgproc247d.lib

opencv_legacy247d.lib

opencv_ml247d.lib

opencv_nonfree247d.lib

opencv_objdetect247d.lib

opencv_ocl247d.lib

opencv_photo247d.lib

opencv_stitching247d.lib

opencv_superres247d.lib

opencv_ts247d.lib

opencv_video247d.lib

opencv_videostab247d.lib 


2.4.9
opencv_calib3d249.lib
opencv_contrib249.lib
opencv_core249.lib
opencv_features2d249.lib
opencv_flann249.lib
opencv_gpu249.lib
opencv_highgui249.lib
opencv_imgproc249.lib
opencv_legacy249.lib
opencv_ml249.lib
opencv_nonfree249.lib
opencv_objdetect249.lib
opencv_ocl249.lib
opencv_photo249.lib
opencv_stitching249.lib
opencv_superres249.lib
opencv_ts249.lib
opencv_video249.lib
opencv_videostab249.lib  
opencv_calib3d249d.lib
opencv_contrib249d.lib
opencv_core249d.lib
opencv_features2d249d.lib
opencv_flann249d.lib
opencv_gpu249d.lib
opencv_highgui249d.lib
opencv_imgproc249d.lib
opencv_legacy249d.lib
opencv_ml249d.lib
opencv_nonfree249d.lib
opencv_objdetect249d.lib
opencv_ocl249d.lib
opencv_photo249d.lib
opencv_stitching249d.lib
opencv_superres249d.lib
opencv_ts249d.lib
opencv_video249d.lib
opencv_videostab249d.lib 


그 외에는 프로젝트의 exe 파일이 생성되는 릴리즈 / 디버깅 폴더에 dll 파일을 복사한다.


소스코드
#include <opencv2/core/core.hpp>
#include <opencv2/highgui/highgui.hpp>
#include <iostream>

using namespace cv;
using namespace std;

int _tmain(int argc, _TCHAR* argv[])
#if 1
{
// opencv 1 style 
CvCapture* capture = 0;
    Mat frame, frameCopy, image;

    capture = cvCaptureFromCAM( 0 ); //0=default, -1=any camera, 1..99=your camera
    if(!capture) cout << "No camera detected" << endl;

    cvNamedWindow( "result", 1 );

    if( capture )
    {
        cout << "In capture ..." << endl;
        for(;;)
        {
            IplImage* iplImg = cvQueryFrame( capture );
            frame = iplImg;
            if( frame.empty() )
                break;
            if( iplImg->origin == IPL_ORIGIN_TL )
                frame.copyTo( frameCopy );
            else
                flip( frame, frameCopy, 0 );

cvShowImage( "result", iplImg );

            if( waitKey( 10 ) >= 0 )
                cvReleaseCapture( &capture );
        }

        waitKey(0);

cvDestroyWindow("result");

return 0;
}

return 0;
}
#else
{
// opencv 2 style 
    VideoCapture cap(0);
if(!cap.isOpened())
{
cout << "No camera detected" << endl;
return -1;
}
else
{
cout << "In capture ..." << endl;
}

namedWindow( "Display window", WINDOW_AUTOSIZE );

    for(;;)
    {
Mat frame;
        if(!cap.read(frame)) break;
imshow("Display window", frame);
if(waitKey(30) >= 0) break;
    }

return 0;
}
#endif 

결론 : 설치했던 노트북에 무언가가 엉겨서 문제가 있었던 듯.. 다시 노트북을 밀어봐야 하나... ㅠㅠ

[링크: http://docs.opencv.org/.../windows_visual_studio_Opencv.html#windows-visual-studio-how-to]
[링크: http://thinkpiece.tistory.com/65]
[링크: http://hxr99.blogspot.kr/2011/12/opencv-examples-camera-capture.html] source
[링크: http://www.anlak.com/using-opencv-2-4-x-with-visual-studio-2010-tutorial/]
[링크: http://ko.dll-files.com/msvcp100d.dll.html]
[링크: http://stackoverflow.com/questions/16574959/installation-of-opencv-2-4-5-on-visual-studio-2008]
[링크: http://stackoverflow.com/questions/.../fatal-error-in-starting-up-opencv-2-4-6-on-vs-2008-file-not-found
[링크 : http://www.codeproject.com/Answers/468324/Problem-with-using-OpenCV-in-VS-2012#answer1]
Posted by 구차니
Programming/openCV2014. 6. 30. 16:30
Linker - general - Additional Library Directories
에서
D:\opencv\build\x64\vc10\lib
등을 추가해주면 된다.
x86 / Visual studio 버전별로 미리 컴파일 된 라이브러리가 존재한다.

dll을 사용하는 법은 좀 찾아 봐야할 듯.. 
[링크 : http://exportidea.blogspot.kr/2013/08/windows-dll.html]
[링크 : http://dhna.tistory.com/28]

To do this go to the Linker → Input and under the “Additional Dependencies” entry add the name of all modules which you want to use:
 
The names of the libraries are as follow:
(The Name of the module)(The version Number of the library you use)d.lib
A full list, for the latest version would contain:

opencv_calib3d249d.lib
opencv_contrib249d.lib
opencv_core249d.lib
opencv_features2d249d.lib
opencv_flann249d.lib
opencv_gpu249d.lib
opencv_highgui249d.lib
opencv_imgproc249d.lib
opencv_legacy249d.lib
opencv_ml249d.lib
opencv_nonfree249d.lib
opencv_objdetect249d.lib
opencv_ocl249d.lib
opencv_photo249d.lib
opencv_stitching249d.lib
opencv_superres249d.lib
opencv_ts249d.lib
opencv_video249d.lib
opencv_videostab249d.lib
 
The letter d at the end just indicates that these are the libraries required for the debug. Now click ok to save and do the
same with a new property inside the Release rule section. Make sure to omit the d letters from the library names and
to save the property sheets with the save icon above them.
 
opencv_tutorial.pdf 1.5. / How to build applications with OpenCV inside the Microsoft Visual Studio
[링크 : http://docs.opencv.org/.../windows_visual_studio_Opencv.html#windows-visual-studio-how-to]

'Programming > openCV' 카테고리의 다른 글

openCV2 2.3.1 ubuntu 컴파일하기  (0) 2014.07.01
openCV2 2.4.9 + VS2008 좌충우돌 프로젝트 생성하기  (0) 2014.07.01
OpenNI - Open Natural Interaction  (0) 2014.06.30
opencv2 웹캠 관련 문서  (0) 2014.06.28
opencv docs  (0) 2014.02.17
Posted by 구차니