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

OpenCv 2.3 C - 如何隔離圖像內的對象

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

問題描述

我有一個像:

我想刪除數字周圍的黑色行和列.所以我希望結果是:

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

我試試這個:

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);

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

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!)

推薦答案

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

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

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

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

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

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:

請注意,在生成的圖像中,邊框中有一個額外的非白色行/列像素.好吧,他們也不是黑人.那是因為我沒有執行任何閾值方法將圖像二值化為黑白.下面的代碼演示了在圖像的灰度版本上執行的邊界框技術.

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.

這幾乎是實現您想要的目標的路線圖.出于教育目的,我將分享我使用 OpenCV 的 C++ 接口編寫的代碼.我相信你有能力將它轉換成 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);
/
                【網站聲明】本站部分內容來源于互聯網,旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯系我們刪除處理,感謝您的支持!
                
上一篇:使用 CMake 編譯靜態可執行文件 下一篇:正方形檢測沒有找到正方形
相關文檔推薦 斷言失敗(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++ 中旋轉圖像而不使用 OpenCV 函數 Rotate an image in C++ without using OpenCV functions(在 C++ 中旋轉圖像而不使用 OpenCV 函數) OpenCV:處理每一幀 OpenCV: process every frame(OpenCV:處理每一幀) 為什么我不能在 openCV 中打開 avi 視頻? Why can#39;t I open avi video in openCV?(為什么我不能在 openCV 中打開 avi 視頻?) OpenCV 無法設置 SVM 參數 OpenCV unable to set up SVM Parameters(OpenCV 無法設置 SVM 參數) 使用 cvtColor 轉換單一顏色 Convert a single color with cvtColor(使用 cvtColor 轉換單一顏色)
欄目導航 前端問題解決Java問題php問題Python問題C#/.NET問題C/C++問題移動開發問題數據庫問題 最新文章 • 模塊化算法和 NTT(有限域 DF... • cout&lt;&lt;調用它打印的... • QPSQL 驅動未加載 Qt... • Qt如何刪除對象?存儲 QObject... • c++ 從.csv文件中讀取... • Qt GUI 應用程序中的控制臺輸... • 什么時候應該在 C++ 中使用“... • 使用 GCC 在可執行文件中嵌入... • Qt5 靜態構建產生無法加載平... • 如何在 C++11 中終止線程?... • 當 main() 退出時,分離的線程... • 為什么從`std::async` 阻塞返回... 熱門文章 • 模塊化算法和 NTT(有限域 DF... • cout&lt;&lt;調用它打印的... • QPSQL 驅動未加載 Qt... • Qt如何刪除對象?存儲 QObject... • c++ 從.csv文件中讀取... • Qt GUI 應用程序中的控制臺輸... • 什么時候應該在 C++ 中使用“... • 使用 GCC 在可執行文件中嵌入... • Qt5 靜態構建產生無法加載平... • 如何在 C++11 中終止線程?... • 當 main() 退出時,分離的線程... • 為什么從`std::async` 阻塞返回... 熱門標簽 掃碼點餐 門戶 驗證碼 廣告設計 商務合作 商城模板 bootstrap 進銷存系統 零售系統 ar 商城 視頻教程 微擎 o2o 分發系統 音樂 淘寶客 discuz模板 微小區 留學服務 ai 資源 小米 刷單 3d 小游戲 交友 蜘蛛池 卡券 你畫我猜 虛擬幣 區塊鏈 視頻 全景 漫畫網 OElove 按鈕切換 博客 物流網站 游戲模板 svg jquery angular 360 動畫模板 攝影 動畫特效 在線客服 扁平 地板 域名停放 域名頁 canvas html5 小程序 thinkphp 視頻打賞 java視頻 挖礦網 養生網 帝國cms 微信程序 電影源碼 css3 訂單系統 微商 微擎微贊 蘋果cms 郵件群發 小說源碼
網站首頁 - 聯系我們- 免責聲明- 網站公告 - 標簽分類- 網站地圖 Copyright © 2022-2023 HTML5模板網 版權所有并保留所有權 粵ICP備14083021號 感谢您访问我们的网站,您可能还对以下资源感兴趣: 久久久久久久av|日韩在线中文|看一级毛片视频|日本精品二区|成人深夜福利视频|武道仙尊动漫在线观看 主站蜘蛛池模板: 亚洲精久久久 | 国产在线精品一区二区 | 亚洲 日本 欧美 中文幕 | 亚洲精品国产精品国自产在线 | 古装人性做爰av网站 | 青青激情网 | 91久久久久久久久 | 国产三区视频在线观看 | 夜夜夜夜夜夜曰天天天 | 丁香久久| 亚洲国产中文在线 | 亚洲美女一区 | 亚洲成人动漫在线观看 | 久久国产精品视频 | 欧美xxxx做受欧美 | 成人网址在线观看 | 亚洲精选一区 | 国产欧美性成人精品午夜 | 一区二区三区精品视频 | 国产精品亚洲第一 | 亚洲综合一区二区三区 | 欧美中文在线 | 亚洲国产福利视频 | 久久中文字幕视频 | 一区二区三区精品在线 | 国产精品美女 | 精品无码久久久久国产 | 伊人激情综合网 | 国产日韩中文字幕 | eeuss国产一区二区三区四区 | 成人一区精品 | 特级黄一级播放 | 中文字幕亚洲欧美日韩在线不卡 | 亚洲国产成人av好男人在线观看 | 亚洲精品一区二区三区蜜桃久 | 一区二区三区在线播放 | 成人三级在线播放 | 激情国产 | 日韩欧美精品一区 | 欧美1区 | 成人一区二区三区在线观看 | (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); })(); <li id="aumie"><dl id="aumie"></dl></li><tr id="aumie"><ul id="aumie"></ul></tr><dl id="aumie"><acronym id="aumie"></acronym></dl><button id="aumie"></button><table id="aumie"></table><rt id="aumie"><acronym id="aumie"></acronym></rt><li id="aumie"><source id="aumie"></source></li><tr id="aumie"><ul id="aumie"></ul></tr><object id="aumie"></object><button id="aumie"></button>