Split an image into multiple images based on result from cv2.HoughLinesRegion of Interest opencv pythonHow to return multiple values from a function?Split Strings into words with multiple word boundary delimitersPeak detection in a 2D arraySplit string with multiple delimiters in PythonSelect rows from a DataFrame based on values in a column in pandasPython cv2 HoughLines grid line detectioncv2.HoughLinesP on a skeletonized imageDetecting lines in an image using OpenCV with PythonHow do I transform the values of an accumulator [Hough Transformation] back to a line on a canvas?QImage - Process finished with exit code -1073741819 (0xC0000005)
Java - What do constructor type arguments mean when placed *before* the type?
Do all polymers contain either carbon or silicon?
The One-Electron Universe postulate is true - what simple change can I make to change the whole universe?
Can a Gentile theist be saved?
Superhero words!
Meta programming: Declare a new struct on the fly
Giant Toughroad SLR 2 for 200 miles in two days, will it make it?
How do I repair my stair bannister?
Science Fiction story where a man invents a machine that can help him watch history unfold
Freedom of speech and where it applies
Golf game boilerplate
Lifted its hind leg on or lifted its hind leg towards?
Is there a good way to store credentials outside of a password manager?
Simple recursive Sudoku solver
Simulating a probability of 1 of 2^N with less than N random bits
Why is delta-v is the most useful quantity for planning space travel?
Are taller landing gear bad for aircraft, particulary large airliners?
What was required to accept "troll"?
Organic chemistry Iodoform Reaction
What is the term when two people sing in harmony, but they aren't singing the same notes?
Could solar power be utilized and substitute coal in the 19th century?
Lightning Web Component - do I need to track changes for every single input field in a form
How can a jailer prevent the Forge Cleric's Artisan's Blessing from being used?
My boss asked me to take a one-day class, then signs it up as a day off
Split an image into multiple images based on result from cv2.HoughLines
Region of Interest opencv pythonHow to return multiple values from a function?Split Strings into words with multiple word boundary delimitersPeak detection in a 2D arraySplit string with multiple delimiters in PythonSelect rows from a DataFrame based on values in a column in pandasPython cv2 HoughLines grid line detectioncv2.HoughLinesP on a skeletonized imageDetecting lines in an image using OpenCV with PythonHow do I transform the values of an accumulator [Hough Transformation] back to a line on a canvas?QImage - Process finished with exit code -1073741819 (0xC0000005)
I want to split this image into multiple images based on the black lines
I use cv2.HoughLines to get some lines, merging them to avoid overlapping lines.
And here my drawing code:
# After get lines from cv2.HoughLines()
for line in lines:
rho, theta = line
a = np.cos(theta)
b = np.sin(theta)
x0 = a * rho
y0 = b * rho
x1 = int(x0 + 1000 * (-b))
y1 = int(y0 + 1000 * (a))
x2 = int(x0 - 1000 * (-b))
y2 = int(y0 - 1000 * (a))
cv2.line(image, (x1, y1), (x2, y2), (0, 200, 0), 2)
cv2.imwrite('results/result.jpg', image)
Here's the result:
I wonder how can I split the images into multiple small images with those green lines
python cv2
add a comment |
I want to split this image into multiple images based on the black lines
I use cv2.HoughLines to get some lines, merging them to avoid overlapping lines.
And here my drawing code:
# After get lines from cv2.HoughLines()
for line in lines:
rho, theta = line
a = np.cos(theta)
b = np.sin(theta)
x0 = a * rho
y0 = b * rho
x1 = int(x0 + 1000 * (-b))
y1 = int(y0 + 1000 * (a))
x2 = int(x0 - 1000 * (-b))
y2 = int(y0 - 1000 * (a))
cv2.line(image, (x1, y1), (x2, y2), (0, 200, 0), 2)
cv2.imwrite('results/result.jpg', image)
Here's the result:
I wonder how can I split the images into multiple small images with those green lines
python cv2
add a comment |
I want to split this image into multiple images based on the black lines
I use cv2.HoughLines to get some lines, merging them to avoid overlapping lines.
And here my drawing code:
# After get lines from cv2.HoughLines()
for line in lines:
rho, theta = line
a = np.cos(theta)
b = np.sin(theta)
x0 = a * rho
y0 = b * rho
x1 = int(x0 + 1000 * (-b))
y1 = int(y0 + 1000 * (a))
x2 = int(x0 - 1000 * (-b))
y2 = int(y0 - 1000 * (a))
cv2.line(image, (x1, y1), (x2, y2), (0, 200, 0), 2)
cv2.imwrite('results/result.jpg', image)
Here's the result:
I wonder how can I split the images into multiple small images with those green lines
python cv2
I want to split this image into multiple images based on the black lines
I use cv2.HoughLines to get some lines, merging them to avoid overlapping lines.
And here my drawing code:
# After get lines from cv2.HoughLines()
for line in lines:
rho, theta = line
a = np.cos(theta)
b = np.sin(theta)
x0 = a * rho
y0 = b * rho
x1 = int(x0 + 1000 * (-b))
y1 = int(y0 + 1000 * (a))
x2 = int(x0 - 1000 * (-b))
y2 = int(y0 - 1000 * (a))
cv2.line(image, (x1, y1), (x2, y2), (0, 200, 0), 2)
cv2.imwrite('results/result.jpg', image)
Here's the result:
I wonder how can I split the images into multiple small images with those green lines
python cv2
python cv2
asked Mar 8 at 8:22
BlurieBlurie
5918
5918
add a comment |
add a comment |
2 Answers
2
active
oldest
votes
Suppose image
is the variable in which the image is read by opencv as an nd-array.
image = cv2.imread(image_filepath)
Now if lines
is the variable assigned after the houghline transformation like :
lines = cv2.HoughLinesP(...)
Get its's shape :
a,b,c = lines.shape
Initiate a variable to get the coordinates and append the bounding-boxes :
line_coords_list = []
for i in range(a):
line_coords_list.append([(lines[i][0][0], lines[i][0][1]), (lines[i][0][2], lines[i][0][3])])
Now, loop through the list of bounding boxes and crop the main image and write them with some filename :
temp_img = image[start_y_coordinate : end_y_coordinate , start_x_coorinate : end_x_coordinate]
temp_name = image_filepath[:-4] + "_"+str(start_y_coordinate )+"_"+str(end_y_coordinate)+ "_" + str(start_x_coorinate) + "_" + str(end_x_coordinate) + ".png"
cv2.imwrite(temp_name, temp_img)
If you are using cv2.HoughLines(...)
, then you probably have to find contours in the image using :
_, blackAndWhite = cv2.threshold(img, 100, 255, cv2.THRESH_BINARY_INV)
_,contours,h = cv2.findContours(blackAndWhite,cv2.RETR_LIST ,cv2.CHAIN_APPROX_SIMPLE)
and, then loop through the contours :
for cnt in contours:
x,y,w,h = cv2.boundingRect(cnt)
line_coords_list.append((x,y,w,h))
Here while finding contours the third and fourth items are width and height respectively. So end_y_coordinate = y+h
and end_x_coordinate = x+w
.
The cv2.HoughLines(...) return only rho and theta, I don't know how to get start_y_coordinate, start_y_coordinate, etc.
– Blurie
Mar 8 at 8:51
add a comment |
See "region of interest"
(Region of Interest opencv python - StackOverflow)
Read this to get x/y:
(Hough Line Transform - Opencv Phyton Tutorials 1 documentation)
add a comment |
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%2f55059236%2fsplit-an-image-into-multiple-images-based-on-result-from-cv2-houghlines%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
Suppose image
is the variable in which the image is read by opencv as an nd-array.
image = cv2.imread(image_filepath)
Now if lines
is the variable assigned after the houghline transformation like :
lines = cv2.HoughLinesP(...)
Get its's shape :
a,b,c = lines.shape
Initiate a variable to get the coordinates and append the bounding-boxes :
line_coords_list = []
for i in range(a):
line_coords_list.append([(lines[i][0][0], lines[i][0][1]), (lines[i][0][2], lines[i][0][3])])
Now, loop through the list of bounding boxes and crop the main image and write them with some filename :
temp_img = image[start_y_coordinate : end_y_coordinate , start_x_coorinate : end_x_coordinate]
temp_name = image_filepath[:-4] + "_"+str(start_y_coordinate )+"_"+str(end_y_coordinate)+ "_" + str(start_x_coorinate) + "_" + str(end_x_coordinate) + ".png"
cv2.imwrite(temp_name, temp_img)
If you are using cv2.HoughLines(...)
, then you probably have to find contours in the image using :
_, blackAndWhite = cv2.threshold(img, 100, 255, cv2.THRESH_BINARY_INV)
_,contours,h = cv2.findContours(blackAndWhite,cv2.RETR_LIST ,cv2.CHAIN_APPROX_SIMPLE)
and, then loop through the contours :
for cnt in contours:
x,y,w,h = cv2.boundingRect(cnt)
line_coords_list.append((x,y,w,h))
Here while finding contours the third and fourth items are width and height respectively. So end_y_coordinate = y+h
and end_x_coordinate = x+w
.
The cv2.HoughLines(...) return only rho and theta, I don't know how to get start_y_coordinate, start_y_coordinate, etc.
– Blurie
Mar 8 at 8:51
add a comment |
Suppose image
is the variable in which the image is read by opencv as an nd-array.
image = cv2.imread(image_filepath)
Now if lines
is the variable assigned after the houghline transformation like :
lines = cv2.HoughLinesP(...)
Get its's shape :
a,b,c = lines.shape
Initiate a variable to get the coordinates and append the bounding-boxes :
line_coords_list = []
for i in range(a):
line_coords_list.append([(lines[i][0][0], lines[i][0][1]), (lines[i][0][2], lines[i][0][3])])
Now, loop through the list of bounding boxes and crop the main image and write them with some filename :
temp_img = image[start_y_coordinate : end_y_coordinate , start_x_coorinate : end_x_coordinate]
temp_name = image_filepath[:-4] + "_"+str(start_y_coordinate )+"_"+str(end_y_coordinate)+ "_" + str(start_x_coorinate) + "_" + str(end_x_coordinate) + ".png"
cv2.imwrite(temp_name, temp_img)
If you are using cv2.HoughLines(...)
, then you probably have to find contours in the image using :
_, blackAndWhite = cv2.threshold(img, 100, 255, cv2.THRESH_BINARY_INV)
_,contours,h = cv2.findContours(blackAndWhite,cv2.RETR_LIST ,cv2.CHAIN_APPROX_SIMPLE)
and, then loop through the contours :
for cnt in contours:
x,y,w,h = cv2.boundingRect(cnt)
line_coords_list.append((x,y,w,h))
Here while finding contours the third and fourth items are width and height respectively. So end_y_coordinate = y+h
and end_x_coordinate = x+w
.
The cv2.HoughLines(...) return only rho and theta, I don't know how to get start_y_coordinate, start_y_coordinate, etc.
– Blurie
Mar 8 at 8:51
add a comment |
Suppose image
is the variable in which the image is read by opencv as an nd-array.
image = cv2.imread(image_filepath)
Now if lines
is the variable assigned after the houghline transformation like :
lines = cv2.HoughLinesP(...)
Get its's shape :
a,b,c = lines.shape
Initiate a variable to get the coordinates and append the bounding-boxes :
line_coords_list = []
for i in range(a):
line_coords_list.append([(lines[i][0][0], lines[i][0][1]), (lines[i][0][2], lines[i][0][3])])
Now, loop through the list of bounding boxes and crop the main image and write them with some filename :
temp_img = image[start_y_coordinate : end_y_coordinate , start_x_coorinate : end_x_coordinate]
temp_name = image_filepath[:-4] + "_"+str(start_y_coordinate )+"_"+str(end_y_coordinate)+ "_" + str(start_x_coorinate) + "_" + str(end_x_coordinate) + ".png"
cv2.imwrite(temp_name, temp_img)
If you are using cv2.HoughLines(...)
, then you probably have to find contours in the image using :
_, blackAndWhite = cv2.threshold(img, 100, 255, cv2.THRESH_BINARY_INV)
_,contours,h = cv2.findContours(blackAndWhite,cv2.RETR_LIST ,cv2.CHAIN_APPROX_SIMPLE)
and, then loop through the contours :
for cnt in contours:
x,y,w,h = cv2.boundingRect(cnt)
line_coords_list.append((x,y,w,h))
Here while finding contours the third and fourth items are width and height respectively. So end_y_coordinate = y+h
and end_x_coordinate = x+w
.
Suppose image
is the variable in which the image is read by opencv as an nd-array.
image = cv2.imread(image_filepath)
Now if lines
is the variable assigned after the houghline transformation like :
lines = cv2.HoughLinesP(...)
Get its's shape :
a,b,c = lines.shape
Initiate a variable to get the coordinates and append the bounding-boxes :
line_coords_list = []
for i in range(a):
line_coords_list.append([(lines[i][0][0], lines[i][0][1]), (lines[i][0][2], lines[i][0][3])])
Now, loop through the list of bounding boxes and crop the main image and write them with some filename :
temp_img = image[start_y_coordinate : end_y_coordinate , start_x_coorinate : end_x_coordinate]
temp_name = image_filepath[:-4] + "_"+str(start_y_coordinate )+"_"+str(end_y_coordinate)+ "_" + str(start_x_coorinate) + "_" + str(end_x_coordinate) + ".png"
cv2.imwrite(temp_name, temp_img)
If you are using cv2.HoughLines(...)
, then you probably have to find contours in the image using :
_, blackAndWhite = cv2.threshold(img, 100, 255, cv2.THRESH_BINARY_INV)
_,contours,h = cv2.findContours(blackAndWhite,cv2.RETR_LIST ,cv2.CHAIN_APPROX_SIMPLE)
and, then loop through the contours :
for cnt in contours:
x,y,w,h = cv2.boundingRect(cnt)
line_coords_list.append((x,y,w,h))
Here while finding contours the third and fourth items are width and height respectively. So end_y_coordinate = y+h
and end_x_coordinate = x+w
.
edited Mar 8 at 9:32
answered Mar 8 at 8:36
pistol2myheadpistol2myhead
1,5061923
1,5061923
The cv2.HoughLines(...) return only rho and theta, I don't know how to get start_y_coordinate, start_y_coordinate, etc.
– Blurie
Mar 8 at 8:51
add a comment |
The cv2.HoughLines(...) return only rho and theta, I don't know how to get start_y_coordinate, start_y_coordinate, etc.
– Blurie
Mar 8 at 8:51
The cv2.HoughLines(...) return only rho and theta, I don't know how to get start_y_coordinate, start_y_coordinate, etc.
– Blurie
Mar 8 at 8:51
The cv2.HoughLines(...) return only rho and theta, I don't know how to get start_y_coordinate, start_y_coordinate, etc.
– Blurie
Mar 8 at 8:51
add a comment |
See "region of interest"
(Region of Interest opencv python - StackOverflow)
Read this to get x/y:
(Hough Line Transform - Opencv Phyton Tutorials 1 documentation)
add a comment |
See "region of interest"
(Region of Interest opencv python - StackOverflow)
Read this to get x/y:
(Hough Line Transform - Opencv Phyton Tutorials 1 documentation)
add a comment |
See "region of interest"
(Region of Interest opencv python - StackOverflow)
Read this to get x/y:
(Hough Line Transform - Opencv Phyton Tutorials 1 documentation)
See "region of interest"
(Region of Interest opencv python - StackOverflow)
Read this to get x/y:
(Hough Line Transform - Opencv Phyton Tutorials 1 documentation)
edited Mar 8 at 19:19
answered Mar 8 at 8:32
busybytebusybyte
195
195
add a comment |
add a comment |
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%2f55059236%2fsplit-an-image-into-multiple-images-based-on-result-from-cv2-houghlines%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