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

如何消除數獨方塊中的凸性缺陷?

How to remove convexity defects in a Sudoku square?(如何消除數獨方塊中的凸性缺陷?)
本文介紹了如何消除數獨方塊中的凸性缺陷?的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

問題描述

我正在做一個有趣的項目:使用 OpenCV(如在 Google 護目鏡等中)從輸入圖像中求解數獨.而且我已經完成了任務,但是最后我發現了一個小問題,所以我來到這里.

I was doing a fun project: Solving a Sudoku from an input image using OpenCV (as in Google goggles etc). And I have completed the task, but at the end I found a little problem for which I came here.

我使用 OpenCV 2.3.1 的 Python API 進行了編程.

I did the programming using Python API of OpenCV 2.3.1.

以下是我所做的:

  1. 閱讀圖片
  2. 尋找輪廓
  3. 選擇面積最大的那個,(也有點相當于正方形).
  4. 找到角點.

  1. Read the image
  2. Find the contours
  3. Select the one with maximum area, ( and also somewhat equivalent to square).
  4. Find the corner points.

例如下面給出:

(請注意,這里的綠線與數獨的真實邊界正確重合,因此數獨可以正確扭曲.查看下一張圖片)

將圖像變形為完美的正方形

warp the image to a perfect square

例如圖片:

執行 OCR(為此我使用了我在 OpenCV-Python 中的簡單數字識別 OCR )

Perform OCR ( for which I used the method I have given in Simple Digit Recognition OCR in OpenCV-Python )

而且這個方法效果很好.

And the method worked well.

問題:

查看這張圖片.

在此圖像上執行第 4 步會得到以下結果:

Performing the step 4 on this image gives the result below:

畫出的紅線是原始輪廓,是數獨邊界的真實輪廓.

The red line drawn is the original contour which is the true outline of sudoku boundary.

繪制的綠線是近似輪廓,將是扭曲圖像的輪廓.

The green line drawn is approximated contour which will be the outline of warped image.

當然,數獨上邊緣的綠線和紅線是有區別的.所以在變形時,我沒有得到數獨的原始邊界.

Which of course, there is difference between green line and red line at the top edge of sudoku. So while warping, I am not getting the original boundary of the Sudoku.

我的問題:

如何在數獨的正確邊界(即紅線)上扭曲圖像,或者如何消除紅線和綠線之間的差異?OpenCV中有什么方法嗎?

How can I warp the image on the correct boundary of the Sudoku, i.e. the red line OR how can I remove the difference between red line and green line? Is there any method for this in OpenCV?

推薦答案

我有一個可行的解決方案,但您必須自己將其翻譯成 OpenCV.它是用 Mathematica 編寫的.

I have a solution that works, but you'll have to translate it to OpenCV yourself. It's written in Mathematica.

第一步是調整圖像中的亮度,通過將每個像素除以關閉操作的結果:

The first step is to adjust the brightness in the image, by dividing each pixel with the result of a closing operation:

src = ColorConvert[Import["http://davemark.com/images/sudoku.jpg"], "Grayscale"];
white = Closing[src, DiskMatrix[5]];
srcAdjusted = Image[ImageData[src]/ImageData[white]]

下一步是找到數獨區域,這樣我就可以忽略(屏蔽)背景.為此,我使用連通分量分析,并選擇具有最大凸面面積的分量:

The next step is to find the sudoku area, so I can ignore (mask out) the background. For that, I use connected component analysis, and select the component that's got the largest convex area:

components = 
  ComponentMeasurements[
    ColorNegate@Binarize[srcAdjusted], {"ConvexArea", "Mask"}][[All, 
    2]];
largestComponent = Image[SortBy[components, First][[-1, 2]]]

通過填充這張圖片,我得到了數獨網格的掩碼:

By filling this image, I get a mask for the sudoku grid:

mask = FillingTransform[largestComponent]

現在,我可以使用二階導數過濾器在兩個單獨的圖像中找到垂直線和水平線:

Now, I can use a 2nd order derivative filter to find the vertical and horizontal lines in two separate images:

lY = ImageMultiply[MorphologicalBinarize[GaussianFilter[srcAdjusted, 3, {2, 0}], {0.02, 0.05}], mask];
lX = ImageMultiply[MorphologicalBinarize[GaussianFilter[srcAdjusted, 3, {0, 2}], {0.02, 0.05}], mask];

我再次使用連通分量分析從這些圖像中提取網格線.網格線比數字長得多,所以我可以使用卡尺長度來僅選擇網格線連接的組件.按位置對它們進行排序,我得到圖像中每個垂直/水平網格線的 2x10 蒙版圖像:

I use connected component analysis again to extract the grid lines from these images. The grid lines are much longer than the digits, so I can use caliper length to select only the grid lines-connected components. Sorting them by position, I get 2x10 mask images for each of the vertical/horizontal grid lines in the image:

verticalGridLineMasks = 
  SortBy[ComponentMeasurements[
      lX, {"CaliperLength", "Centroid", "Mask"}, # > 100 &][[All, 
      2]], #[[2, 1]] &][[All, 3]];
horizontalGridLineMasks = 
  SortBy[ComponentMeasurements[
      lY, {"CaliperLength", "Centroid", "Mask"}, # > 100 &][[All, 
      2]], #[[2, 2]] &][[All, 3]];

接下來我取每一對垂直/水平網格線,將它們擴大,逐個像素地計算交點,并計算結果的中心.這些點是網格線的交點:

Next I take each pair of vertical/horizontal grid lines, dilate them, calculate the pixel-by-pixel intersection, and calculate the center of the result. These points are the grid line intersections:

centerOfGravity[l_] := 
 ComponentMeasurements[Image[l], "Centroid"][[1, 2]]
gridCenters = 
  Table[centerOfGravity[
    ImageData[Dilation[Image[h], DiskMatrix[2]]]*
     ImageData[Dilation[Image[v], DiskMatrix[2]]]], {h, 
    horizontalGridLineMasks}, {v, verticalGridLineMasks}];

最后一步是通過這些點為 X/Y 映射定義兩個插值函數,并使用這些函數變換圖像:

The last step is to define two interpolation functions for X/Y mapping through these points, and transform the image using these functions:

fnX = ListInterpolation[gridCenters[[All, All, 1]]];
fnY = ListInterpolation[gridCenters[[All, All, 2]]];
transformed = 
 ImageTransformation[
  srcAdjusted, {fnX @@ Reverse[#], fnY @@ Reverse[#]} &, {9*50, 9*50},
   PlotRange -> {{1, 10}, {1, 10}}, DataRange -> Full]

所有的操作都是基本的圖像處理功能,所以這在 OpenCV 中應該也是可以的.基于樣條的圖像轉換可能更難,但我認為你并不需要它.使用您現在對每個單獨的單元格使用的透視變換可能會產生足夠好的結果.

All of the operations are basic image processing function, so this should be possible in OpenCV, too. The spline-based image transformation might be harder, but I don't think you really need it. Probably using the perspective transformation you use now on each individual cell will give good enough results.

這篇關于如何消除數獨方塊中的凸性缺陷?的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!

【網站聲明】本站部分內容來源于互聯網,旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯系我們刪除處理,感謝您的支持!

相關文檔推薦

How to draw a rectangle around a region of interest in python(如何在python中的感興趣區域周圍繪制一個矩形)
How can I detect and track people using OpenCV?(如何使用 OpenCV 檢測和跟蹤人員?)
How to apply threshold within multiple rectangular bounding boxes in an image?(如何在圖像的多個矩形邊界框中應用閾值?)
How can I download a specific part of Coco Dataset?(如何下載 Coco Dataset 的特定部分?)
Detect image orientation angle based on text direction(根據文本方向檢測圖像方向角度)
Detect centre and angle of rectangles in an image using Opencv(使用 Opencv 檢測圖像中矩形的中心和角度)
主站蜘蛛池模板: 欧美视频一级 | 无码日韩精品一区二区免费 | 国产成人精品久久久 | 日本黄视频在线观看 | 国产黄色大片在线免费观看 | 日本免费视频在线观看 | 日本黄色高清视频 | 国产成人免费视频网站视频社区 | 精品日韩一区二区三区av动图 | 日韩精品一区二区三区中文在线 | 成人免费视频网站在线观看 | 天天射网站| 日韩视频一区 | 亚洲国产精品美女 | 国产区视频在线观看 | 五月婷婷婷 | 日本视频在线播放 | 国产一区二区三区在线 | 久久91视频| 激情欧美一区二区三区中文字幕 | 久久国产成人 | 野狼在线社区2017入口 | 精品一区二区三区四区五区 | 91视频国产精品 | 精品久久久久一区二区国产 | 999精品网| 成人a免费| 日韩一区二区福利视频 | 精品国产免费一区二区三区五区 | 亚洲欧美在线观看 | 精品免费看 | 日韩av免费看 | 中文一区 | 久久高清精品 | 欧美多人在线 | 国产一区二区三区四区 | 国产大片黄色 | 91精品91久久久 | 在线一区二区三区 | 国产成人综合在线 | 欧美一级视频免费看 |