国产 无码 综合区,色欲AV无码国产永久播放,无码天堂亚洲国产AV,国产日韩欧美女同一区二区

OpenCV下載、安裝以及使用

這篇具有很好參考價(jià)值的文章主要介紹了OpenCV下載、安裝以及使用。希望對(duì)大家有所幫助。如果存在錯(cuò)誤或未考慮完全的地方,請(qǐng)大家不吝賜教,您也可以點(diǎn)擊"舉報(bào)違法"按鈕提交疑問(wèn)。

一、安裝Visual Studio

OpenCV是一種開(kāi)源的計(jì)算機(jī)視覺(jué)開(kāi)發(fā)庫(kù)。既然是開(kāi)發(fā)庫(kù),那么必須依托某種語(yǔ)言程序來(lái)加載。以C++為例,在安裝OpenCV之前,必須安裝C++的程序開(kāi)發(fā)環(huán)境(IDE),在此我們選擇Visual Studio Community——VS社區(qū)版,這個(gè)版本是免費(fèi)的。

中文版下載安裝地址:
https://visualstudio.microsoft.com/zh-hans/downloads/

注意這是一個(gè)在線安裝的版本,請(qǐng)確保在安裝過(guò)程中網(wǎng)絡(luò)暢通。

二、創(chuàng)建C++程序

我們需要在VS中建立應(yīng)用程序。在此我們建立最簡(jiǎn)單的基于控制臺(tái)的應(yīng)用程序,項(xiàng)目名為face1。
OpenCV下載、安裝以及使用

三、下載OpenCV

所謂OpenCV的安裝,其實(shí)就是把OpenCV的庫(kù)路徑加入我們已有的項(xiàng)目路徑集合當(dāng)中?,F(xiàn)在有兩種方法,一種是自己下載OpencCV源碼,在源碼的基礎(chǔ)上編譯成庫(kù)(lib/dll)文件,一種是下載直接編譯好的庫(kù)文件, 我們選擇直接下載已經(jīng)編譯好的庫(kù)文件

最新版OpenCV Lib 下載鏈接
https://sourceforge.net/projects/opencvlibrary/files/latest/download
一共266MB,外網(wǎng)有的時(shí)候挺慢的。

四、安裝/配置OpenCV

下載后OpenCV后,運(yùn)行,解壓到一個(gè)固定目錄。比如我的:“D:\試驗(yàn)\軟件\opencv”——這個(gè)路徑稍后要作為庫(kù)和頭文件的路徑,加入以后C++程序項(xiàng)目中
在VS中,因?yàn)槊總€(gè)項(xiàng)目都是獨(dú)立編譯的,所以,每個(gè)項(xiàng)目具有自己的“規(guī)則包“。也就是說(shuō),對(duì)著項(xiàng)目名稱右鍵,選擇”屬性“,可以配置該項(xiàng)目的編譯規(guī)則。
現(xiàn)在我們?cè)趯傩源翱谥校渲肙penCV路徑,步驟如下

1、在屬性窗口中,我們選擇輸出目標(biāo)”配置”為“Debug“,”平臺(tái)“為”x64“。也就是編譯輸出在64位windows系統(tǒng)中運(yùn)行的調(diào)試版(debug)應(yīng)用程序
OpenCV下載、安裝以及使用

2、左邊選擇VC++目錄,右邊選中“包含目錄“項(xiàng)進(jìn)行編輯。把剛在OpenCV解壓目錄下的“include”目錄包含進(jìn)來(lái)。然后確定

3、重復(fù)上述步驟2。右邊選中“庫(kù)目錄“項(xiàng)進(jìn)行編輯。把剛在OpenCV解壓目錄下的“庫(kù)目錄”包含進(jìn)來(lái)。然后確定
OpenCV下載、安裝以及使用

4、在屬性窗口中,左邊選中“鏈接器->輸入“。右邊選中“附加依賴項(xiàng)”。把剛在OpenCV解壓后產(chǎn)生的靜態(tài)引用庫(kù)名字“opencv_world3416.lib”加進(jìn)來(lái)(注意名字后面的數(shù)字部分視各個(gè)版本不同而不同)。然后確定。

OpenCV下載、安裝以及使用

5、最后將OpenCV解壓目錄下的dll文件拷貝到程序運(yùn)行所在的目錄

OpenCV下載、安裝以及使用

五、運(yùn)行OpenCV程序

在已經(jīng)建立好的項(xiàng)目“face1”的源代碼中,加入opencv頭文件
OpenCV下載、安裝以及使用

接著,在程序中就可以使用openCV所提供的庫(kù)函數(shù)了。
比如在這個(gè)例子中:
我們讀取事先準(zhǔn)備好的一張圖片,并輸出它的尺寸:

OpenCV下載、安裝以及使用

運(yùn)行結(jié)果:
OpenCV下載、安裝以及使用

六、利用OpenCV程序進(jìn)行人臉檢測(cè)。
這個(gè)實(shí)例在opencv安裝目錄下的“samples/c++”目錄下。該目錄有大量實(shí)例,可以一一嘗試運(yùn)行。

OpenCV下載、安裝以及使用

在此我們選擇facedetect.cpp。復(fù)制相應(yīng)代碼運(yùn)行
注意頭文件需要做參照以下(而非例程中所示):

OpenCV下載、安裝以及使用

接著我們把這個(gè)項(xiàng)目所需要的數(shù)據(jù)文件移動(dòng)到該項(xiàng)目應(yīng)用程序所在目錄

OpenCV下載、安裝以及使用
整個(gè)實(shí)驗(yàn)程序源碼如下:

#define _CRT_SECURE_NO_WARNINGS

#include <iostream>
#include <opencv2/opencv.hpp>
using namespace std;
using namespace cv;

static void help(const char** argv)
{
    cout << "\nThis program demonstrates the use of cv::CascadeClassifier class to detect objects (Face + eyes). You can use Haar or LBP features.\n"
            "This classifier can recognize many kinds of rigid objects, once the appropriate classifier is trained.\n"
            "It's most known use is for faces.\n"
            "Usage:\n"
        <<  argv[0]
        <<  "   [--cascade=<cascade_path> this is the primary trained classifier such as frontal face]\n"
            "   [--nested-cascade[=nested_cascade_path this an optional secondary classifier such as eyes]]\n"
            "   [--scale=<image scale greater or equal to 1, try 1.3 for example>]\n"
            "   [--try-flip]\n"
            "   [filename|camera_index]\n\n"
            "example:\n"
        <<  argv[0]
        <<  " --cascade=\"data/haarcascades/haarcascade_frontalface_alt.xml\" --nested-cascade=\"data/haarcascades/haarcascade_eye_tree_eyeglasses.xml\" --scale=1.3\n\n"
            "During execution:\n\tHit any key to quit.\n"
            "\tUsing OpenCV version " << CV_VERSION << "\n" << endl;
}

void detectAndDraw( Mat& img, CascadeClassifier& cascade,
                    CascadeClassifier& nestedCascade,
                    double scale, bool tryflip );

string cascadeName;
string nestedCascadeName;

int main( int argc, const char** argv )
{
    VideoCapture capture;
    Mat frame, image;
    string inputName;
    bool tryflip;
    CascadeClassifier cascade, nestedCascade;
    double scale;

    cv::CommandLineParser parser(argc, argv,
        "{help h"
        "{cascade|data/haarcascades/haarcascade_frontalface_alt.xml|}"
        "{nested-cascade|data/haarcascades/haarcascade_eye_tree_eyeglasses.xml|}"
        "{scale|1|}{try-flip||}{@filename||}"
    );
    if (parser.has("help"))
    {
        help(argv);
        return 0;
    }
    cascadeName = parser.get<string>("cascade");
    nestedCascadeName = parser.get<string>("nested-cascade");
    scale = parser.get<double>("scale");
    if (scale < 1)
        scale = 1;
    tryflip = parser.has("try-flip");
    inputName = parser.get<string>("@filename");
    if (!parser.check())
    {
        parser.printErrors();
        return 0;
    }
    if (!nestedCascade.load(samples::findFileOrKeep(nestedCascadeName)))
        cerr << "WARNING: Could not load classifier cascade for nested objects" << endl;
    if (!cascade.load(samples::findFile(cascadeName)))
    {
        cerr << "ERROR: Could not load classifier cascade" << endl;
        help(argv);
        return -1;
    }
    if( inputName.empty() || (isdigit(inputName[0]) && inputName.size() == 1) )
    {
        int camera = inputName.empty() ? 0 : inputName[0] - '0';
        if(!capture.open(camera))
        {
            cout << "Capture from camera #" <<  camera << " didn't work" << endl;
            return 1;
        }
    }
    else if (!inputName.empty())
    {
        image = imread(samples::findFileOrKeep(inputName), IMREAD_COLOR);
        if (image.empty())
        {
            if (!capture.open(samples::findFileOrKeep(inputName)))
            {
                cout << "Could not read " << inputName << endl;
                return 1;
            }
        }
    }
    else
    {
        image = imread(samples::findFile("lena.jpg"), IMREAD_COLOR);
        if (image.empty())
        {
            cout << "Couldn't read lena.jpg" << endl;
            return 1;
        }
    }

    if( capture.isOpened() )
    {
        cout << "Video capturing has been started ..." << endl;

        for(;;)
        {
            capture >> frame;
            if( frame.empty() )
                break;

            Mat frame1 = frame.clone();
            detectAndDraw( frame1, cascade, nestedCascade, scale, tryflip );

            char c = (char)waitKey(10);
            if( c == 27 || c == 'q' || c == 'Q' )
                break;
        }
    }
    else
    {
        cout << "Detecting face(s) in " << inputName << endl;
        if( !image.empty() )
        {
            detectAndDraw( image, cascade, nestedCascade, scale, tryflip );
            waitKey(0);
        }
        else if( !inputName.empty() )
        {
            /* assume it is a text file containing the
            list of the image filenames to be processed - one per line */
            FILE* f = fopen( inputName.c_str(), "rt" );
            if( f )
            {
                char buf[1000+1];
                while( fgets( buf, 1000, f ) )
                {
                    int len = (int)strlen(buf);
                    while( len > 0 && isspace(buf[len-1]) )
                        len--;
                    buf[len] = '\0';
                    cout << "file " << buf << endl;
                    image = imread( buf, 1 );
                    if( !image.empty() )
                    {
                        detectAndDraw( image, cascade, nestedCascade, scale, tryflip );
                        char c = (char)waitKey(0);
                        if( c == 27 || c == 'q' || c == 'Q' )
                            break;
                    }
                    else
                    {
                        cerr << "Aw snap, couldn't read image " << buf << endl;
                    }
                }
                fclose(f);
            }
        }
    }

    return 0;
}

void detectAndDraw( Mat& img, CascadeClassifier& cascade,
                    CascadeClassifier& nestedCascade,
                    double scale, bool tryflip )
{
    double t = 0;
    vector<Rect> faces, faces2;
    const static Scalar colors[] =
    {
        Scalar(255,0,0),
        Scalar(255,128,0),
        Scalar(255,255,0),
        Scalar(0,255,0),
        Scalar(0,128,255),
        Scalar(0,255,255),
        Scalar(0,0,255),
        Scalar(255,0,255)
    };
    Mat gray, smallImg;

    cvtColor( img, gray, COLOR_BGR2GRAY );
    double fx = 1 / scale;
    resize( gray, smallImg, Size(), fx, fx, INTER_LINEAR_EXACT );
    equalizeHist( smallImg, smallImg );

    t = (double)getTickCount();
    cascade.detectMultiScale( smallImg, faces,
        1.1, 2, 0
        //|CASCADE_FIND_BIGGEST_OBJECT
        //|CASCADE_DO_ROUGH_SEARCH
        |CASCADE_SCALE_IMAGE,
        Size(30, 30) );
    if( tryflip )
    {
        flip(smallImg, smallImg, 1);
        cascade.detectMultiScale( smallImg, faces2,
                                 1.1, 2, 0
                                 //|CASCADE_FIND_BIGGEST_OBJECT
                                 //|CASCADE_DO_ROUGH_SEARCH
                                 |CASCADE_SCALE_IMAGE,
                                 Size(30, 30) );
        for( vector<Rect>::const_iterator r = faces2.begin(); r != faces2.end(); ++r )
        {
            faces.push_back(Rect(smallImg.cols - r->x - r->width, r->y, r->width, r->height));
        }
    }
    t = (double)getTickCount() - t;
    printf( "detection time = %g ms\n", t*1000/getTickFrequency());
    for ( size_t i = 0; i < faces.size(); i++ )
    {
        Rect r = faces[i];
        Mat smallImgROI;
        vector<Rect> nestedObjects;
        Point center;
        Scalar color = colors[i%8];
        int radius;

        double aspect_ratio = (double)r.width/r.height;
        if( 0.75 < aspect_ratio && aspect_ratio < 1.3 )
        {
            center.x = cvRound((r.x + r.width*0.5)*scale);
            center.y = cvRound((r.y + r.height*0.5)*scale);
            radius = cvRound((r.width + r.height)*0.25*scale);
            circle( img, center, radius, color, 3, 8, 0 );
        }
        else
            rectangle( img, Point(cvRound(r.x*scale), cvRound(r.y*scale)),
                       Point(cvRound((r.x + r.width-1)*scale), cvRound((r.y + r.height-1)*scale)),
                       color, 3, 8, 0);
        if( nestedCascade.empty() )
            continue;
        smallImgROI = smallImg( r );
        nestedCascade.detectMultiScale( smallImgROI, nestedObjects,
            1.1, 2, 0
            //|CASCADE_FIND_BIGGEST_OBJECT
            //|CASCADE_DO_ROUGH_SEARCH
            //|CASCADE_DO_CANNY_PRUNING
            |CASCADE_SCALE_IMAGE,
            Size(30, 30) );
        for ( size_t j = 0; j < nestedObjects.size(); j++ )
        {
            Rect nr = nestedObjects[j];
            center.x = cvRound((r.x + nr.x + nr.width*0.5)*scale);
            center.y = cvRound((r.y + nr.y + nr.height*0.5)*scale);
            radius = cvRound((nr.width + nr.height)*0.25*scale);
            circle( img, center, radius, color, 3, 8, 0 );
        }
    }
    imshow( "result", img );
}

運(yùn)行程序。該程序會(huì)自動(dòng)打開(kāi)攝像頭,識(shí)別并定位攝像頭前的人臉以及眼睛部位。
輸入q或者Q,退出程序。

下一篇------參數(shù)解析文章來(lái)源地址http://www.zghlxwxcb.cn/news/detail-474894.html

到了這里,關(guān)于OpenCV下載、安裝以及使用的文章就介紹完了。如果您還想了解更多內(nèi)容,請(qǐng)?jiān)谟疑辖撬阉鱐OY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章,希望大家以后多多支持TOY模板網(wǎng)!

本文來(lái)自互聯(lián)網(wǎng)用戶投稿,該文觀點(diǎn)僅代表作者本人,不代表本站立場(chǎng)。本站僅提供信息存儲(chǔ)空間服務(wù),不擁有所有權(quán),不承擔(dān)相關(guān)法律責(zé)任。如若轉(zhuǎn)載,請(qǐng)注明出處: 如若內(nèi)容造成侵權(quán)/違法違規(guī)/事實(shí)不符,請(qǐng)點(diǎn)擊違法舉報(bào)進(jìn)行投訴反饋,一經(jīng)查實(shí),立即刪除!

領(lǐng)支付寶紅包贊助服務(wù)器費(fèi)用

相關(guān)文章

  • LaTex下載、安裝及配置并搭配使用Visual Studio Code教程(建議收藏)2022最新完整版

    LaTex下載、安裝及配置并搭配使用Visual Studio Code教程(建議收藏)2022最新完整版

    LaTex下載、安裝及配置并搭配使用Visual Studio Code教程(保姆級(jí)超詳細(xì))2022最新完整版 LaTeX (/?lɑ?t?x/,常被讀作/?lɑ?t?k/或/?le?t?k/,風(fēng)格化后寫(xiě)作“LATEX”),是一種基于TEX的排版系統(tǒng),由美國(guó)計(jì)算機(jī)科學(xué)家萊斯利·蘭伯特在20世紀(jì)80年代初期開(kāi)發(fā),利用這種格式系統(tǒng)的處

    2023年04月20日
    瀏覽(35)
  • OpenCV下載、安裝以及使用

    OpenCV下載、安裝以及使用

    一、安裝Visual Studio OpenCV是一種開(kāi)源的計(jì)算機(jī)視覺(jué)開(kāi)發(fā)庫(kù)。既然是開(kāi)發(fā)庫(kù),那么必須依托某種語(yǔ)言程序來(lái)加載。以C++為例,在安裝OpenCV之前,必須安裝C++的程序開(kāi)發(fā)環(huán)境(IDE),在此我們選擇Visual Studio Community——VS社區(qū)版,這個(gè)版本是免費(fèi)的。 中文版下載安裝地址: https:/

    2024年02月08日
    瀏覽(11)
  • Visual Studio更改并下載.Net Framework目標(biāo)框架以及Nuget包下載

    Visual Studio更改并下載.Net Framework目標(biāo)框架以及Nuget包下載

    ??當(dāng)使用.net進(jìn)行開(kāi)發(fā)時(shí),開(kāi)發(fā)的項(xiàng)目與.net framework目標(biāo)框架會(huì)非常密切相關(guān)的,所以當(dāng)vs本地使用的.net framework框架與該項(xiàng)目工程的框架不一致的時(shí)候,就可能打開(kāi)不了當(dāng)前項(xiàng)目,解決這個(gè)問(wèn)題的方法有: 第一種:要更改目標(biāo)框架以適應(yīng)當(dāng)前VS的; 第二種:或者根據(jù)目標(biāo)框架

    2024年02月05日
    瀏覽(55)
  • C/C++圖形庫(kù)EasyX保姆級(jí)使用教程(一) Microsoft Visual Studio 2022和EasyX的下載及安裝使用

    第一章 Microsoft Visual Studio 2022和EasyX的下載及安裝使用

    2024年02月11日
    瀏覽(20)
  • Visual Studio安裝及下載

    Visual Studio安裝及下載

    由于近期要將C語(yǔ)言作為學(xué)習(xí)工具,所以就翻看了很多文章以及了解了很多C語(yǔ)言開(kāi)發(fā)工具。經(jīng)過(guò)再三斟酌,決定將Visual Studio作為開(kāi)發(fā)工具,作為初學(xué)者,下面詳細(xì)介紹了該開(kāi)發(fā)工具的安裝與使用。希望后續(xù)的學(xué)習(xí)能夠得到順利的提升。 Microsoft Visual Studio (簡(jiǎn)稱VS)是微軟公司

    2024年02月03日
    瀏覽(18)
  • Visual Studio 2019 下載安裝

    Visual Studio 2019 下載安裝

    1、從官網(wǎng)下載最新版本 下載 Visual Studio Tools - 免費(fèi)安裝 Windows、Mac、Linux (microsoft.com) https://visualstudio.microsoft.com/zh-hans/downloads/ 2、Visual Studio 2019安裝包網(wǎng)盤(pán)鏈接: ??????https://pan.baidu.com/s/13H6TfDU-uyLxJssERvXgTw?? pwd=1234? ? ? ? ? ? 提取碼:1234 ?1、存儲(chǔ)路徑找到下載文件,雙擊

    2024年02月07日
    瀏覽(32)
  • 2.Visual Studio下載和安裝

    2.Visual Studio下載和安裝

    ????????Visual Studio 是微軟提供的一個(gè)集成開(kāi)發(fā)環(huán)境(IDE),主要用于為 Windows 系統(tǒng)開(kāi)發(fā)應(yīng)用程序。Visual Studio 提供了構(gòu)建 .Net 平臺(tái)應(yīng)用程序的一站式服務(wù),可以使用 Visual Studio 開(kāi)發(fā)、調(diào)試和運(yùn)行應(yīng)用程序。 1、Visual Studio下載 ????????首先從微軟官網(wǎng)(下載 Visual Studio

    2024年02月04日
    瀏覽(23)
  • Visual Studio2022下載安裝教程

    Visual Studio2022下載安裝教程

    首先去官網(wǎng)下載vs的安裝包https://visualstudio.microsoft.com 日常學(xué)習(xí)使用,選擇社區(qū)版就可以。 然后等待下載完成,雙擊安裝 Visual Studio安裝 根據(jù)官網(wǎng)的提示,要至少選擇【Desktop Development with C++】 然后更改一下下載的路徑,個(gè)人建議放在D盤(pán),不要放在C盤(pán),因?yàn)樵撥浖純?nèi)存比

    2024年02月11日
    瀏覽(23)
  • Visual Studio的下載與安裝

    Visual Studio的下載與安裝

    官網(wǎng)下載 網(wǎng)址:免費(fèi)的開(kāi)發(fā)人員軟件和服務(wù) - Visual Studio (microsoft.com) 直接下載社區(qū)版(Visual Studio Community) 安裝相關(guān)組件 運(yùn)行下載完成的Visual Studio Installer 勾選 .NET桌面開(kāi)發(fā) 、 使用C++的桌面開(kāi)發(fā) 以及 其他工具集 中的 Visual Studio 擴(kuò)展開(kāi)發(fā) 默認(rèn)安裝位置改到D盤(pán)(如果C盤(pán)空間

    2024年02月11日
    瀏覽(20)
  • Visual Studio Code的下載與安裝

    Visual Studio Code的下載與安裝

    Visual Studio Code(簡(jiǎn)稱 VS Code)是由 Microsoft 開(kāi)發(fā)的免費(fèi)、開(kāi)源的文本編輯器,適用于多種操作系統(tǒng),包括 Windows、macOS 和 Linux。它的設(shè)計(jì)目標(biāo)是成為一款輕量級(jí)、高效的代碼編輯工具,同時(shí)提供豐富的擴(kuò)展和功能,以滿足不同開(kāi)發(fā)者的需求。以下是關(guān)于 Visual Studio Code 的詳細(xì)介

    2024年02月07日
    瀏覽(30)

覺(jué)得文章有用就打賞一下文章作者

支付寶掃一掃打賞

博客贊助

微信掃一掃打賞

請(qǐng)作者喝杯咖啡吧~博客贊助

支付寶掃一掃領(lǐng)取紅包,優(yōu)惠每天領(lǐng)

二維碼1

領(lǐng)取紅包

二維碼2

領(lǐng)紅包