OpenCV学习_1和总结

       昨天晚上开始突然想学一下图像学什么的,于是去隔壁找了JJ牛——在此真的很感谢JJ对我的帮助和对我傻×的无限忍耐。。。

        先是codeblocks,准确说一直在配置它的一些设置,今天下午又试试了DEV,然后又是QT。。。均以失败告终——Process terminated with status -1073741510 。

        实在没办法的时候转机出现了。。。最后改了下设置,在QT下运行成功了!

        代码参考网上的:

#include 
#include 
int main(int argc, char* argv[])
{
    cvNamedWindow("in");
    IplImage* in = cvLoadImage(argv[1]);
    IplImage* r = cvCreateImage(cvGetSize(in), IPL_DEPTH_8U, 1);
    IplImage* g = cvCreateImage(cvGetSize(in), IPL_DEPTH_8U, 1);
    IplImage* b = cvCreateImage(cvGetSize(in), IPL_DEPTH_8U, 1);
    IplImage* out = cvCreateImage(cvGetSize(in), IPL_DEPTH_8U, 1);
    IplImage* dst = cvCreateImage(cvGetSize(in), IPL_DEPTH_8U, 1);
    cvSplit(in, r, g, b, NULL);
    cvAddWeighted(r, 1./3., g, 1./3., 0, out);
    cvAddWeighted(b, 1./3., out, 2./3., 0, out);
    cvNamedWindow("out");
    cvShowImage("out", out);
    cvThreshold(out, dst, 150, 255, CV_THRESH_BINARY);
    cvNamedWindow("dst");
    cvShowImage("dst", dst);
    cvShowImage("in", in);
    cvWaitKey(0);
    return 0;
}
pro文件:
#-------------------------------------------------
#
# Project created by QtCreator 2013-05-06T16:28:18
#
#-------------------------------------------------

QT       += core

QT       -= gui

TARGET = QtFirstCV
CONFIG   += console
CONFIG   -= app_bundle

TEMPLATE = app


SOURCES += main.cpp

INCLUDEPATH += D:\qt-opencv\include
INCLUDEPATH += D:\qt-opencv\include\opencv
INCLUDEPATH += D:\qt-opencv\include\opencv2
CONFIG(release,debug|release)
{
LIBS +=D:\qt-opencv\lib\libopencv_calib3d231.dll.a  \
       D:\qt-opencv\lib\libopencv_calib3d_pch_dephelp.a \
       D:\qt-opencv\lib\libopencv_contrib231.dll.a  \
       D:\qt-opencv\lib\libopencv_contrib_pch_dephelp.a \
       D:\qt-opencv\lib\libopencv_core231.dll.a \
       D:\qt-opencv\lib\libopencv_core_pch_dephelp.a    \
       D:\qt-opencv\lib\libopencv_features2d231.dll.a   \
       D:\qt-opencv\lib\libopencv_features2d_pch_dephelp.a  \
       D:\qt-opencv\lib\libopencv_flann231.dll.a    \
       D:\qt-opencv\lib\libopencv_flann_pch_dephelp.a   \
       D:\qt-opencv\lib\libopencv_gpu231.dll.a  \
       D:\qt-opencv\lib\libopencv_gpu_pch_dephelp.a \
       D:\qt-opencv\lib\libopencv_haartraining_engine.a \
       D:\qt-opencv\lib\libopencv_highgui231.dll.a  \
       D:\qt-opencv\lib\libopencv_highgui_pch_dephelp.a \
       D:\qt-opencv\lib\libopencv_imgproc231.dll.a  \
       D:\qt-opencv\lib\libopencv_imgproc_pch_dephelp.a \
       D:\qt-opencv\lib\libopencv_legacy231.dll.a   \
       D:\qt-opencv\lib\libopencv_legacy_pch_dephelp.a  \
       D:\qt-opencv\lib\libopencv_ml231.dll.a   \
       D:\qt-opencv\lib\libopencv_ml_pch_dephelp.a  \
       D:\qt-opencv\lib\libopencv_objdetect231.dll.a    \
       D:\qt-opencv\lib\libopencv_objdetect_pch_dephelp.a   \
       D:\qt-opencv\lib\libopencv_test_calib3d_pch_dephelp.a    \
       D:\qt-opencv\lib\libopencv_test_core_pch_dephelp.a   \
       D:\qt-opencv\lib\libopencv_test_features2d_pch_dephelp.a \
       D:\qt-opencv\lib\libopencv_test_gpu_pch_dephelp.a    \
       D:\qt-opencv\lib\libopencv_test_highgui_pch_dephelp.a    \
       D:\qt-opencv\lib\libopencv_test_imgproc_pch_dephelp.a    \
       D:\qt-opencv\lib\libopencv_test_ml_pch_dephelp.a \
       D:\qt-opencv\lib\libopencv_test_objdetect_pch_dephelp.a  \
       D:\qt-opencv\lib\libopencv_test_video_pch_dephelp.a  \
       D:\qt-opencv\lib\libopencv_ts231.a   \
       D:\qt-opencv\lib\libopencv_ts_pch_dephelp.a  \
       D:\qt-opencv\lib\libopencv_video231.dll.a    \
       D:\qt-opencv\lib\libopencv_video_pch_dephelp.a \
}

PS:我就是一笨蛋,笨的不行!



#include"highgui.h"
#include"cv.h"

int g_slider_position = 0;
CvCapture* g_capture   = NULL;
void onTrackbarSlide(int pos){
    cvSetCaptureProperty(
                g_capture,
                CV_CAP_PROP_POS_FRAMES,
                pos
                );
}

int main(int argc, char* argv[]){
   cvNamedWindow("Example2",CV_WINDOW_AUTOSIZE);
   g_capture = cvCreateFileCapture(argv[1]);
   //CvCapture* capture = cvCreateFileCapture(argv[1]);
   int frames = (int) cvGetCaptureProperty(
               g_capture,
               CV_CAP_PROP_FRAME_COUNT
               );
   if( frames != 0){
       cvCreateTrackbar(
                   "Position",
                   "Example2",
                   &g_slider_position,
                   frames,
                   onTrackbarSlide
                   );
   }

   IplImage* frame;
   while(1){
       frame = cvQueryFrame(g_capture);
       if(!frame)break;
       cvShowImage("Example2",frame);
       char c = cvWaitKey(100);

       if(c == 27) break;
   }
   cvReleaseCapture(&g_capture);
   cvDestroyWindow("Example2");

}

结束抄代码!开始自己写!加油!

你可能感兴趣的:(OpenCV)