久久久久久久av_日韩在线中文_看一级毛片视频_日本精品二区_成人深夜福利视频_武道仙尊动漫在线观看

OpenCv 2.3 C - 如何隔離圖像內(nèi)的對(duì)象

OpenCv 2.3 C - How to isolate object inside image(OpenCv 2.3 C - 如何隔離圖像內(nèi)的對(duì)象)
本文介紹了OpenCv 2.3 C - 如何隔離圖像內(nèi)的對(duì)象的處理方法,對(duì)大家解決問題具有一定的參考價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)吧!

問題描述

我有一個(gè)像:

我想刪除數(shù)字周圍的黑色行和列.所以我希望結(jié)果是:

i want to remove the black rows and cols round the number. So i want that the result is:

我試試這個(gè):

void findX(IplImage* imgSrc,int* min, int* max){
    int i;
    int minFound=0;
    CvMat data;
    CvScalar maxVal=cvRealScalar(imgSrc->width * 255);
    CvScalar val=cvRealScalar(0);
    //For each col sum, if sum < width*255 then we find the min
    //then continue to end to search the max, if sum< width*255 then is new max
    for (i=0; i< imgSrc->width; i++){
        cvGetCol(imgSrc, &data, i);
        val= cvSum(&data);
        if(val.val[0] < maxVal.val[0]){
            *max= i;
            if(!minFound){
                *min= i;
                minFound= 1;
            }
        }
    }
}

void findY(IplImage* imgSrc,int* min, int* max){
    int i;
    int minFound=0;
    CvMat data;
    CvScalar maxVal=cvRealScalar(imgSrc->width * 255);
    CvScalar val=cvRealScalar(0);
    //For each col sum, if sum < width*255 then we find the min
    //then continue to end to search the max, if sum< width*255 then is new max
    for (i=0; i< imgSrc->height; i++){
        cvGetRow(imgSrc, &data, i);
        val= cvSum(&data);
        if(val.val[0] < maxVal.val[0]){
            *max=i;
            if(!minFound){
                *min= i;
                minFound= 1;
            }
        }
    }
}
CvRect findBB(IplImage* imgSrc){
    CvRect aux;
    int xmin, xmax, ymin, ymax;
    xmin=xmax=ymin=ymax=0;

    findX(imgSrc, &xmin, &xmax);
    findY(imgSrc, &ymin, &ymax);

    aux=cvRect(xmin, ymin, xmax-xmin, ymax-ymin);

    //printf("BB: %d,%d - %d,%d
", aux.x, aux.y, aux.width, aux.height);

    return aux;

}

所以我使用:

IplImage *my_image = cvLoad....
CvRect bb = findBB(my_image);
IplImage *new_image = cvCreateImage(cvSize(bb.width,bb.height), my_image->depth, 1);
cvShowImage("test",new_image);

效果不佳,因?yàn)槲覈L試檢查新圖像中是否存在黑色行或列.我能做什么?有人能幫我嗎?(對(duì)不起我的英語!)

it doesn't work good, cause i try to check if in new image there are black rows or cols and they are present. what can i do? can someone help me? (sorry for my english!)

推薦答案

一種方法是簡單地執(zhí)行 邊界框技術(shù)檢測數(shù)字,如下圖所示:

One way to do it is to simply execute the bounding box technique to detect the digit, as illustrated by the image below:

由于您的圖像已經(jīng)過處理,因此我使用的邊界框技術(shù)要簡單得多.

Since your image is already processed the bounding box technique I use is a lot simpler.

在該過程之后,您真正需要做的就是將原始圖像的 ROI(感興趣區(qū)域)設(shè)置為框定義的區(qū)域,以實(shí)現(xiàn) 裁剪 效果并隔離對(duì)象:

After that procedure, all you really need to do is set the ROI (Region of Interest) of the original image to the area defined by the box to achieve the crop effect and isolate the object:

請(qǐng)注意,在生成的圖像中,邊框中有一個(gè)額外的非白色行/列像素.好吧,他們也不是黑人.那是因?yàn)槲覜]有執(zhí)行任何閾值方法將圖像二值化為黑白.下面的代碼演示了在圖像的灰度版本上執(zhí)行的邊界框技術(shù).

Notice that in the resulting image there is one extra row/column of pixels in the border that are not white. Well, they are not black either. That's because I didn't performed any threshold method to binarize the image to black and white. The code below demonstrates the bounding box technique being executed on a grayscale version of the image.

這幾乎是實(shí)現(xiàn)您想要的目標(biāo)的路線圖.出于教育目的,我將分享我使用 OpenCV 的 C++ 接口編寫的代碼.我相信你有能力將它轉(zhuǎn)換成 C 接口.

This is pretty much the roadmap to achieve what you want. For educational purposes I'm sharing the code I wrote using the C++ interface of OpenCV. I'm sure you are capable of converting it to the C interface.

#include <cv.h>
#include <highgui.h>

#include <vector>


int main(int argc, char* argv[])
{
    cv::Mat img = cv::imread(argv[1]);

    // Convert RGB Mat to GRAY
    cv::Mat gray;
    cv::cvtColor(img, gray, CV_BGR2GRAY);

    // Store the set of points in the image before assembling the bounding box
    std::vector<cv::Point> points;
    cv::Mat_<uchar>::iterator it = gray.begin<uchar>();
    cv::Mat_<uchar>::iterator end = gray.end<uchar>();
    for (; it != end; ++it)
    {
        if (*it) points.push_back(it.pos());
    }

    // Compute minimal bounding box
    cv::RotatedRect box = cv::minAreaRect(cv::Mat(points));

// Draw bounding box in the original image (debug purposes)
//cv::Point2f vertices[4];
//box.points(vertices);
//for (int i = 0; i < 4; ++i)
//{
        //cv::line(img, vertices[i], vertices[(i + 1) % 4], cv::Scalar(0, 255, 0), 1, CV_AA);
/
                【網(wǎng)站聲明】本站部分內(nèi)容來源于互聯(lián)網(wǎng),旨在幫助大家更快的解決問題,如果有圖片或者內(nèi)容侵犯了您的權(quán)益,請(qǐng)聯(lián)系我們刪除處理,感謝您的支持!
                
上一篇:使用 CMake 編譯靜態(tài)可執(zhí)行文件 下一篇:正方形檢測沒有找到正方形
相關(guān)文檔推薦 斷言失敗(size.width>0 &amp;&amp; size.height&g Assertion failed (size.widthgt;0 amp;amp; size.heightgt;0)(斷言失敗(size.width0 amp;amp; size.height0)) 在 C++ 中旋轉(zhuǎn)圖像而不使用 OpenCV 函數(shù) Rotate an image in C++ without using OpenCV functions(在 C++ 中旋轉(zhuǎn)圖像而不使用 OpenCV 函數(shù)) OpenCV:處理每一幀 OpenCV: process every frame(OpenCV:處理每一幀) 為什么我不能在 openCV 中打開 avi 視頻? Why can#39;t I open avi video in openCV?(為什么我不能在 openCV 中打開 avi 視頻?) OpenCV 無法設(shè)置 SVM 參數(shù) OpenCV unable to set up SVM Parameters(OpenCV 無法設(shè)置 SVM 參數(shù)) 使用 cvtColor 轉(zhuǎn)換單一顏色 Convert a single color with cvtColor(使用 cvtColor 轉(zhuǎn)換單一顏色)
欄目導(dǎo)航 前端問題解決Java問題php問題Python問題C#/.NET問題C/C++問題移動(dòng)開發(fā)問題數(shù)據(jù)庫問題 最新文章 • 模塊化算法和 NTT(有限域 DF... • cout&lt;&lt;調(diào)用它打印的... • QPSQL 驅(qū)動(dòng)未加載 Qt... • Qt如何刪除對(duì)象?存儲(chǔ) QObject... • c++ 從.csv文件中讀取... • Qt GUI 應(yīng)用程序中的控制臺(tái)輸... • 什么時(shí)候應(yīng)該在 C++ 中使用“... • 使用 GCC 在可執(zhí)行文件中嵌入... • Qt5 靜態(tài)構(gòu)建產(chǎn)生無法加載平... • 如何在 C++11 中終止線程?... • 當(dāng) main() 退出時(shí),分離的線程... • 為什么從`std::async` 阻塞返回... 熱門文章 • 模塊化算法和 NTT(有限域 DF... • cout&lt;&lt;調(diào)用它打印的... • QPSQL 驅(qū)動(dòng)未加載 Qt... • Qt如何刪除對(duì)象?存儲(chǔ) QObject... • c++ 從.csv文件中讀取... • Qt GUI 應(yīng)用程序中的控制臺(tái)輸... • 什么時(shí)候應(yīng)該在 C++ 中使用“... • 使用 GCC 在可執(zhí)行文件中嵌入... • Qt5 靜態(tài)構(gòu)建產(chǎn)生無法加載平... • 如何在 C++11 中終止線程?... • 當(dāng) main() 退出時(shí),分離的線程... • 為什么從`std::async` 阻塞返回... 熱門標(biāo)簽 掃碼點(diǎn)餐 門戶 驗(yàn)證碼 廣告設(shè)計(jì) 商務(wù)合作 商城模板 bootstrap 進(jìn)銷存系統(tǒng) 零售系統(tǒng) ar 商城 視頻教程 微擎 o2o 分發(fā)系統(tǒng) 音樂 淘寶客 discuz模板 微小區(qū) 留學(xué)服務(wù) ai 資源 小米 刷單 3d 小游戲 交友 蜘蛛池 卡券 你畫我猜 虛擬幣 區(qū)塊鏈 視頻 全景 漫畫網(wǎng) OElove 按鈕切換 博客 物流網(wǎng)站 游戲模板 svg jquery angular 360 動(dòng)畫模板 攝影 動(dòng)畫特效 在線客服 扁平 地板 域名停放 域名頁 canvas html5 小程序 thinkphp 視頻打賞 java視頻 挖礦網(wǎng) 養(yǎng)生網(wǎng) 帝國cms 微信程序 電影源碼 css3 訂單系統(tǒng) 微商 微擎微贊 蘋果cms 郵件群發(fā) 小說源碼
網(wǎng)站首頁 - 聯(lián)系我們- 免責(zé)聲明- 網(wǎng)站公告 - 標(biāo)簽分類- 網(wǎng)站地圖 Copyright © 2022-2023 HTML5模板網(wǎng) 版權(quán)所有并保留所有權(quán) 粵ICP備14083021號(hào) 感谢您访问我们的网站,您可能还对以下资源感兴趣: 久久久久久久av|日韩在线中文|看一级毛片视频|日本精品二区|成人深夜福利视频|武道仙尊动漫在线观看 主站蜘蛛池模板: 激情做爰呻吟视频舌吻 | 涩涩97| 一区二区三区精品 | 亚洲国产精 | 久久视频一区二区 | 四虎影视大全 | 国产精品区二区三区日本 | 成人片免费看 | 国产日韩欧美视频 | 福利视频1000 | 久久精品福利视频 | 国产精品三级在线 | 日韩视频在线观看免费 | 欧美午夜视频 | 精品日韩一区二区三区 | 久久综合久色欧美综合狠狠 | 欧美黑人一区二区三区 | 久久久综合视频 | 青青草伊人网 | 欧美伦理一区二区 | 国产肉体xxxx裸体784大胆 | 国产日韩在线视频 | 欧美伦理一区二区 | 六月激情婷婷 | 成人毛片网站 | 久久久久久艹 | 中文字幕免费观看视频 | 视频一区二区在线播放 | 黄色在线播放 | 国产在线www | 久久久久久国产 | 999在线视频 | 91久久国产综合久久91精品网站 | 成人网页 | 亚洲人在线 | 日韩精品一级 | 国产男女无遮挡猛进猛出 | 国产高清在线观看 | 91精品国产乱码久久久久 | 亚洲人在线 | 毛片毛片毛片毛片毛片 | (function(){ var bp = document.createElement('script'); var curProtocol = window.location.protocol.split(':')[0]; if (curProtocol === 'https') { bp.src = 'https://zz.bdstatic.com/linksubmit/push.js'; } else { bp.src = 'http://push.zhanzhang.baidu.com/push.js'; } var s = document.getElementsByTagName("script")[0]; s.parentNode.insertBefore(bp, s); })(); <code id="ay8o6"><rt id="ay8o6"></rt></code><th id="ay8o6"><delect id="ay8o6"></delect></th><acronym id="ay8o6"></acronym><samp id="ay8o6"></samp><wbr id="ay8o6"><pre id="ay8o6"></pre></wbr>