問題描述
我有一個像:
我想刪除數字周圍的黑色行和列.所以我希望結果是:
i want to remove the black rows and cols round the number. So i want that the result is:
我試試這個:
所以我使用:
效果不佳,因為我嘗試檢查新圖像中是否存在黑色行或列.我能做什么?有人能幫我嗎?(對不起我的英語!)
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.