Football field line detection
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty height:90px;width:728px;box-sizing:border-box;
I wanted to create a model which can detect penalty area field lines.
I managed to get desirable results for one specific image by changing some hyperparamaters, but the same code doesn't work for another image.
i.e. the code is quite specific for an image.
If I want to the code to work for every image what changes should I make.
One of the input images I took as input is here
the output for the image is here
One of the failure case which I got for an image while executing the code is here
this code is specific for the image provided above and is not working for some other image.
Please let me know how can I improve my code.
import numpy as np
import cv2
import matplotlib.pyplot as plt
img = cv2.imread("C:/Users/user/Desktop/football1.jpg")
low_threshold = np.array([0,90,0], dtype=np.uint8)
high_threshold = np.array([170,255,255], dtype=np.uint8)
mask1 = cv2.inRange(img, low_threshold, high_threshold)
cv2.imshow("mask1",mask1)
l_threshold = np.array([0, 115, 0], dtype=np.uint8)
h_threshold = np.array([75, 147, 172], dtype=np.uint8)
mask2=cv2.inRange(img, low_threshold , high_threshold)
cv2.imshow("mask2",mask2)
and1=cv2.bitwise_and(img,img,mask=mask1)
cv2.imshow("and1",and1)
and2=cv2.bitwise_and(and1,and1,mask=mask2)
cv2.imshow("and2",and2)
lowest=np.array([73, 145, 45], dtype=np.uint8)
highest=np.array([114, 255, 255], dtype=np.uint8)
mask3=cv2.inRange(and2, lowest , highest)
cv2.imshow("and3",mask3)
and3=cv2.bitwise_and(and2,and2,mask=mask3)
cv2.imshow("and3",and3)
gray=cv2.cvtColor(and3,cv2.COLOR_BGR2GRAY)
cv2.imshow("gray",gray)
gaussian=cv2.GaussianBlur(gray, (3, 3), 5)
cv2.imshow("gaussian",gaussian)
edge=cv2.Canny(gaussian, 10, 150)
cv2.imshow("edge",edge)
rho = 1
# 1 degree
theta = (np.pi/180) * 1
threshold = 15
min_line_length = 20
max_line_gap = 10
lines=cv2.HoughLinesP(edge, rho, theta, threshold, np.array(),
minLineLength=min_line_length, maxLineGap=max_line_gap)
for line in lines:
for x1,y1,x2,y2 in line:
cv2.line(img, (x1, y1), (x2, y2), [0,255,0], 1)
m=(y2-y1)/(x2-x1)
print ("y="+str(round(m,2))+ "x+"+str(y2-y1))
cv2.imshow('output',img)
cv2.waitKey(0)
cv2.destroyAllWindows()
#cv2.imshow('output',img)
cv2.waitKey(0)
cv2.destroyAllWindows()
computer-vision masking hough-transform houghlinesp straight-line-detection
add a comment |
I wanted to create a model which can detect penalty area field lines.
I managed to get desirable results for one specific image by changing some hyperparamaters, but the same code doesn't work for another image.
i.e. the code is quite specific for an image.
If I want to the code to work for every image what changes should I make.
One of the input images I took as input is here
the output for the image is here
One of the failure case which I got for an image while executing the code is here
this code is specific for the image provided above and is not working for some other image.
Please let me know how can I improve my code.
import numpy as np
import cv2
import matplotlib.pyplot as plt
img = cv2.imread("C:/Users/user/Desktop/football1.jpg")
low_threshold = np.array([0,90,0], dtype=np.uint8)
high_threshold = np.array([170,255,255], dtype=np.uint8)
mask1 = cv2.inRange(img, low_threshold, high_threshold)
cv2.imshow("mask1",mask1)
l_threshold = np.array([0, 115, 0], dtype=np.uint8)
h_threshold = np.array([75, 147, 172], dtype=np.uint8)
mask2=cv2.inRange(img, low_threshold , high_threshold)
cv2.imshow("mask2",mask2)
and1=cv2.bitwise_and(img,img,mask=mask1)
cv2.imshow("and1",and1)
and2=cv2.bitwise_and(and1,and1,mask=mask2)
cv2.imshow("and2",and2)
lowest=np.array([73, 145, 45], dtype=np.uint8)
highest=np.array([114, 255, 255], dtype=np.uint8)
mask3=cv2.inRange(and2, lowest , highest)
cv2.imshow("and3",mask3)
and3=cv2.bitwise_and(and2,and2,mask=mask3)
cv2.imshow("and3",and3)
gray=cv2.cvtColor(and3,cv2.COLOR_BGR2GRAY)
cv2.imshow("gray",gray)
gaussian=cv2.GaussianBlur(gray, (3, 3), 5)
cv2.imshow("gaussian",gaussian)
edge=cv2.Canny(gaussian, 10, 150)
cv2.imshow("edge",edge)
rho = 1
# 1 degree
theta = (np.pi/180) * 1
threshold = 15
min_line_length = 20
max_line_gap = 10
lines=cv2.HoughLinesP(edge, rho, theta, threshold, np.array(),
minLineLength=min_line_length, maxLineGap=max_line_gap)
for line in lines:
for x1,y1,x2,y2 in line:
cv2.line(img, (x1, y1), (x2, y2), [0,255,0], 1)
m=(y2-y1)/(x2-x1)
print ("y="+str(round(m,2))+ "x+"+str(y2-y1))
cv2.imshow('output',img)
cv2.waitKey(0)
cv2.destroyAllWindows()
#cv2.imshow('output',img)
cv2.waitKey(0)
cv2.destroyAllWindows()
computer-vision masking hough-transform houghlinesp straight-line-detection
Can you post an example of a failure case? It's hard to advise you without knowing how variable the input images are and what sort of failures you are experiencing.
– Mozglubov
Nov 15 '18 at 21:19
@Mozglubov I have added one failure case.In that case the lines or the boundaries are not being formed properly over the white penalty boundary lines. Thank you
– Manas Sikri
Nov 16 '18 at 17:45
Ah, okay, so the images are always from roughly that camera angle, and it's more an issue of the thresholds?
– Mozglubov
Nov 16 '18 at 18:34
add a comment |
I wanted to create a model which can detect penalty area field lines.
I managed to get desirable results for one specific image by changing some hyperparamaters, but the same code doesn't work for another image.
i.e. the code is quite specific for an image.
If I want to the code to work for every image what changes should I make.
One of the input images I took as input is here
the output for the image is here
One of the failure case which I got for an image while executing the code is here
this code is specific for the image provided above and is not working for some other image.
Please let me know how can I improve my code.
import numpy as np
import cv2
import matplotlib.pyplot as plt
img = cv2.imread("C:/Users/user/Desktop/football1.jpg")
low_threshold = np.array([0,90,0], dtype=np.uint8)
high_threshold = np.array([170,255,255], dtype=np.uint8)
mask1 = cv2.inRange(img, low_threshold, high_threshold)
cv2.imshow("mask1",mask1)
l_threshold = np.array([0, 115, 0], dtype=np.uint8)
h_threshold = np.array([75, 147, 172], dtype=np.uint8)
mask2=cv2.inRange(img, low_threshold , high_threshold)
cv2.imshow("mask2",mask2)
and1=cv2.bitwise_and(img,img,mask=mask1)
cv2.imshow("and1",and1)
and2=cv2.bitwise_and(and1,and1,mask=mask2)
cv2.imshow("and2",and2)
lowest=np.array([73, 145, 45], dtype=np.uint8)
highest=np.array([114, 255, 255], dtype=np.uint8)
mask3=cv2.inRange(and2, lowest , highest)
cv2.imshow("and3",mask3)
and3=cv2.bitwise_and(and2,and2,mask=mask3)
cv2.imshow("and3",and3)
gray=cv2.cvtColor(and3,cv2.COLOR_BGR2GRAY)
cv2.imshow("gray",gray)
gaussian=cv2.GaussianBlur(gray, (3, 3), 5)
cv2.imshow("gaussian",gaussian)
edge=cv2.Canny(gaussian, 10, 150)
cv2.imshow("edge",edge)
rho = 1
# 1 degree
theta = (np.pi/180) * 1
threshold = 15
min_line_length = 20
max_line_gap = 10
lines=cv2.HoughLinesP(edge, rho, theta, threshold, np.array(),
minLineLength=min_line_length, maxLineGap=max_line_gap)
for line in lines:
for x1,y1,x2,y2 in line:
cv2.line(img, (x1, y1), (x2, y2), [0,255,0], 1)
m=(y2-y1)/(x2-x1)
print ("y="+str(round(m,2))+ "x+"+str(y2-y1))
cv2.imshow('output',img)
cv2.waitKey(0)
cv2.destroyAllWindows()
#cv2.imshow('output',img)
cv2.waitKey(0)
cv2.destroyAllWindows()
computer-vision masking hough-transform houghlinesp straight-line-detection
I wanted to create a model which can detect penalty area field lines.
I managed to get desirable results for one specific image by changing some hyperparamaters, but the same code doesn't work for another image.
i.e. the code is quite specific for an image.
If I want to the code to work for every image what changes should I make.
One of the input images I took as input is here
the output for the image is here
One of the failure case which I got for an image while executing the code is here
this code is specific for the image provided above and is not working for some other image.
Please let me know how can I improve my code.
import numpy as np
import cv2
import matplotlib.pyplot as plt
img = cv2.imread("C:/Users/user/Desktop/football1.jpg")
low_threshold = np.array([0,90,0], dtype=np.uint8)
high_threshold = np.array([170,255,255], dtype=np.uint8)
mask1 = cv2.inRange(img, low_threshold, high_threshold)
cv2.imshow("mask1",mask1)
l_threshold = np.array([0, 115, 0], dtype=np.uint8)
h_threshold = np.array([75, 147, 172], dtype=np.uint8)
mask2=cv2.inRange(img, low_threshold , high_threshold)
cv2.imshow("mask2",mask2)
and1=cv2.bitwise_and(img,img,mask=mask1)
cv2.imshow("and1",and1)
and2=cv2.bitwise_and(and1,and1,mask=mask2)
cv2.imshow("and2",and2)
lowest=np.array([73, 145, 45], dtype=np.uint8)
highest=np.array([114, 255, 255], dtype=np.uint8)
mask3=cv2.inRange(and2, lowest , highest)
cv2.imshow("and3",mask3)
and3=cv2.bitwise_and(and2,and2,mask=mask3)
cv2.imshow("and3",and3)
gray=cv2.cvtColor(and3,cv2.COLOR_BGR2GRAY)
cv2.imshow("gray",gray)
gaussian=cv2.GaussianBlur(gray, (3, 3), 5)
cv2.imshow("gaussian",gaussian)
edge=cv2.Canny(gaussian, 10, 150)
cv2.imshow("edge",edge)
rho = 1
# 1 degree
theta = (np.pi/180) * 1
threshold = 15
min_line_length = 20
max_line_gap = 10
lines=cv2.HoughLinesP(edge, rho, theta, threshold, np.array(),
minLineLength=min_line_length, maxLineGap=max_line_gap)
for line in lines:
for x1,y1,x2,y2 in line:
cv2.line(img, (x1, y1), (x2, y2), [0,255,0], 1)
m=(y2-y1)/(x2-x1)
print ("y="+str(round(m,2))+ "x+"+str(y2-y1))
cv2.imshow('output',img)
cv2.waitKey(0)
cv2.destroyAllWindows()
#cv2.imshow('output',img)
cv2.waitKey(0)
cv2.destroyAllWindows()
computer-vision masking hough-transform houghlinesp straight-line-detection
computer-vision masking hough-transform houghlinesp straight-line-detection
edited Nov 16 '18 at 17:34
Manas Sikri
asked Nov 15 '18 at 8:59
Manas SikriManas Sikri
11
11
Can you post an example of a failure case? It's hard to advise you without knowing how variable the input images are and what sort of failures you are experiencing.
– Mozglubov
Nov 15 '18 at 21:19
@Mozglubov I have added one failure case.In that case the lines or the boundaries are not being formed properly over the white penalty boundary lines. Thank you
– Manas Sikri
Nov 16 '18 at 17:45
Ah, okay, so the images are always from roughly that camera angle, and it's more an issue of the thresholds?
– Mozglubov
Nov 16 '18 at 18:34
add a comment |
Can you post an example of a failure case? It's hard to advise you without knowing how variable the input images are and what sort of failures you are experiencing.
– Mozglubov
Nov 15 '18 at 21:19
@Mozglubov I have added one failure case.In that case the lines or the boundaries are not being formed properly over the white penalty boundary lines. Thank you
– Manas Sikri
Nov 16 '18 at 17:45
Ah, okay, so the images are always from roughly that camera angle, and it's more an issue of the thresholds?
– Mozglubov
Nov 16 '18 at 18:34
Can you post an example of a failure case? It's hard to advise you without knowing how variable the input images are and what sort of failures you are experiencing.
– Mozglubov
Nov 15 '18 at 21:19
Can you post an example of a failure case? It's hard to advise you without knowing how variable the input images are and what sort of failures you are experiencing.
– Mozglubov
Nov 15 '18 at 21:19
@Mozglubov I have added one failure case.In that case the lines or the boundaries are not being formed properly over the white penalty boundary lines. Thank you
– Manas Sikri
Nov 16 '18 at 17:45
@Mozglubov I have added one failure case.In that case the lines or the boundaries are not being formed properly over the white penalty boundary lines. Thank you
– Manas Sikri
Nov 16 '18 at 17:45
Ah, okay, so the images are always from roughly that camera angle, and it's more an issue of the thresholds?
– Mozglubov
Nov 16 '18 at 18:34
Ah, okay, so the images are always from roughly that camera angle, and it's more an issue of the thresholds?
– Mozglubov
Nov 16 '18 at 18:34
add a comment |
0
active
oldest
votes
Your Answer
StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);
else
createEditor();
);
function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53315674%2ffootball-field-line-detection%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
0
active
oldest
votes
0
active
oldest
votes
active
oldest
votes
active
oldest
votes
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53315674%2ffootball-field-line-detection%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Can you post an example of a failure case? It's hard to advise you without knowing how variable the input images are and what sort of failures you are experiencing.
– Mozglubov
Nov 15 '18 at 21:19
@Mozglubov I have added one failure case.In that case the lines or the boundaries are not being formed properly over the white penalty boundary lines. Thank you
– Manas Sikri
Nov 16 '18 at 17:45
Ah, okay, so the images are always from roughly that camera angle, and it's more an issue of the thresholds?
– Mozglubov
Nov 16 '18 at 18:34