Skip to content

Commit 00aeb08

Browse files
committed
Add EDColor code to EdgeDrawing Class
fix for params.PFmode=true Update edge_drawing.py
1 parent 438e67f commit 00aeb08

File tree

5 files changed

+618
-165
lines changed

5 files changed

+618
-165
lines changed

modules/ximgproc/include/opencv2/ximgproc/edge_drawing.hpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -70,9 +70,9 @@ class CV_EXPORTS_W EdgeDrawing : public Algorithm
7070
void write(FileStorage& fs) const;
7171
};
7272

73-
/** @brief Detects edges in a grayscale image and prepares them to detect lines and ellipses.
73+
/** @brief Detects edges in a grayscale or color image and prepares them to detect lines and ellipses.
7474
75-
@param src 8-bit, single-channel, grayscale input image.
75+
@param src 8-bit, single-channel or color input image.
7676
*/
7777
CV_WRAP virtual void detectEdges(InputArray src) = 0;
7878

modules/ximgproc/samples/edge_drawing.py

Lines changed: 23 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -16,18 +16,9 @@
1616
import random as rng
1717
import sys
1818

19-
rng.seed(12345)
20-
21-
def main():
22-
try:
23-
fn = sys.argv[1]
24-
except IndexError:
25-
fn = 'board.jpg'
26-
27-
src = cv.imread(cv.samples.findFile(fn))
28-
gray = cv.cvtColor(src, cv.COLOR_BGR2GRAY)
29-
cv.imshow("source", src)
19+
def EdgeDrawingDemo(src, convert_to_gray):
3020

21+
rng.seed(12345)
3122
ssrc = src.copy()*0
3223
lsrc = src.copy()
3324
esrc = src.copy()
@@ -43,9 +34,16 @@ def main():
4334

4435
ed.setParams(EDParams)
4536

37+
if convert_to_gray:
38+
img_to_detect = cv.cvtColor(src, cv.COLOR_BGR2GRAY)
39+
else:
40+
img_to_detect = src
41+
42+
cv.imshow("source image", img_to_detect)
43+
4644
# Detect edges
4745
# you should call this before detectLines() and detectEllipses()
48-
ed.detectEdges(gray)
46+
ed.detectEdges(img_to_detect)
4947

5048
segments = ed.getSegments()
5149
lines = ed.detectLines()
@@ -78,11 +76,21 @@ def main():
7876
cv.ellipse(esrc, center, axes, angle,0, 360, color, 2, cv.LINE_AA)
7977

8078
cv.imshow("detected circles and ellipses", esrc)
81-
cv.waitKey(0)
82-
print('Done')
79+
print('Press any key to swich color conversion code. Press Esc to exit.')
8380

8481

8582
if __name__ == '__main__':
8683
print(__doc__)
87-
main()
84+
try:
85+
fn = sys.argv[1]
86+
except IndexError:
87+
fn = 'board.jpg'
88+
src = cv.imread(cv.samples.findFile(fn))
89+
90+
convert_to_gray = True
91+
key = 0
92+
while key is not 27:
93+
EdgeDrawingDemo(src, convert_to_gray)
94+
key = cv.waitKey()
95+
convert_to_gray = not convert_to_gray
8896
cv.destroyAllWindows()

0 commit comments

Comments
 (0)