how to extract x,y coordinates from OpenCV “cv2.keypoint” object?Declare empty array of specific typeHow to randomly select an item from a list?How to return multiple values from a function?Extracting extension from filename in PythonHow to know if an object has an attribute in PythonHow to make a flat list out of list of listsProper way to declare custom exceptions in modern Python?How to access environment variable values?Cannot find module cv2 when using OpenCVWhy is “1000000000000000 in range(1000000000000001)” so fast in Python 3?How load cv2.KeyPoint and Descriptors correctly on OpenCV 3 with Python 3?
For a benzene shown in a skeletal structure, what does a substituent to the center of the ring mean?
How to 'Let Go' in Meditation?
Upside-Down Pyramid Addition...REVERSED!
Is it cheaper to drop cargo than to land it?
What happens if I start too many background jobs?
Is there a legal ground for stripping the UK of its UN Veto if Scotland and/or N.Ireland split from the UK?
Comment rendre "naysayers" ?
Point of the the Dothraki's attack in GoT S8E3?
Unknowingly ran an infinite loop in terminal
A non-technological, repeating, phenomenon in the sky, holding its position in the sky for hours
Airbnb - host wants to reduce rooms, can we get refund?
Has any spacecraft ever had the ability to directly communicate with civilian air traffic control?
In Endgame, why were these characters still around?
What is it called when you multiply something eight times?
Number of seconds in 6 weeks
Would "lab meat" be able to feed a much larger global population
Do I really need diodes to receive MIDI?
Why was the battle set up *outside* Winterfell?
Sub query result is 0
Should I replace my bicycle tires if they have not been inflated in multiple years
How do I tell my manager that his code review comment is wrong?
Pressure inside an infinite ocean?
CRT Oscilloscope - part of the plot is missing
Why do money exchangers give different rates to different bills?
how to extract x,y coordinates from OpenCV “cv2.keypoint” object?
Declare empty array of specific typeHow to randomly select an item from a list?How to return multiple values from a function?Extracting extension from filename in PythonHow to know if an object has an attribute in PythonHow to make a flat list out of list of listsProper way to declare custom exceptions in modern Python?How to access environment variable values?Cannot find module cv2 when using OpenCVWhy is “1000000000000000 in range(1000000000000001)” so fast in Python 3?How load cv2.KeyPoint and Descriptors correctly on OpenCV 3 with Python 3?
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty height:90px;width:728px;box-sizing:border-box;
I tried to use the following code:
xCoordinate=point.x
(point is type of cv2.keyPoint)
It gives me error saying cv2.keyPoint has no attribute 'x'
python opencv numpy
add a comment |
I tried to use the following code:
xCoordinate=point.x
(point is type of cv2.keyPoint)
It gives me error saying cv2.keyPoint has no attribute 'x'
python opencv numpy
add a comment |
I tried to use the following code:
xCoordinate=point.x
(point is type of cv2.keyPoint)
It gives me error saying cv2.keyPoint has no attribute 'x'
python opencv numpy
I tried to use the following code:
xCoordinate=point.x
(point is type of cv2.keyPoint)
It gives me error saying cv2.keyPoint has no attribute 'x'
python opencv numpy
python opencv numpy
asked Mar 9 '16 at 6:21
mengmengxyzmengmengxyz
1692510
1692510
add a comment |
add a comment |
6 Answers
6
active
oldest
votes
You can use:
import numpy as np
pts = np.float([kp[idx].pt for idx in range(0, len(kp))]).reshape(-1, 1, 2)
pts
will be an array
of keypoints.
add a comment |
point.pt is a tuple
(x,y)`.
So,
x = point.pt[0]
y = point.pt[1]
or,
(x,y) = point.pt
add a comment |
Read the docs.
class KeyPoint
Data structure for salient point detectors.
Point2f pt
-- coordinates of the keypointfloat size
-- diameter of the meaningful keypoint neighborhoodfloat angle ...¶
So point.pt
is a Point2f.
Try x,y= point.pt
2
point.pt.x
is invalid, please correct it as:x, y = point.pt
– Nirmal
Oct 26 '18 at 5:30
add a comment |
Here is my take (runable code):
import cv2, os
import numpy as np
import matplotlib.pyplot as plt
# INITIALISATION
filename = os.path.join('foo', 'bar.jpg')
img0 = cv2.imread(filename) # original image
gray = cv2.cvtColor(img0, cv2.COLOR_BGR2GRAY) # convert to grayscale
sift = cv2.xfeatures2d.SIFT_create() # initialize SIFT
f, (ax1, ax2) = plt.subplots(1, 2) # create subplots
# DETECT AND DRAW KEYPOINTS
# sift.detect() returns a list of keypoints
# keypoint is a standard class of opencv (not just SIFT-related)
kp = sift.detect(gray,None) # calculates SIFT points
img1=cv2.drawKeypoints(gray,kp, None) # mae new image with keypoints drawn
ax1.imshow(img1) # plot
# RETREIVE KEYPOINTS COORDINATES AND DRAW MANUALLY
# Reade these and make numpy array
pts = np.asarray([[p.pt[0], p.pt[1]] for p in kp])
cols = pts[:,0]
rows = pts[:,1]
ax2.imshow(cv2.cvtColor(img0, cv2.COLOR_BGR2RGB))
ax2.scatter(cols, rows)
plt.show()
add a comment |
OpenCV provides a function for this. You can run:
pts = cv2.KeyPoint_convert(kp)
add a comment |
I solved your problem like this.
kp,des = surf.detectAndCompute(img,None)
pts = [p.pt for p in kp]
Now you get a list of x,y co-ordinates for all keypoints in your image.
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%2f35884409%2fhow-to-extract-x-y-coordinates-from-opencv-cv2-keypoint-object%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
6 Answers
6
active
oldest
votes
6 Answers
6
active
oldest
votes
active
oldest
votes
active
oldest
votes
You can use:
import numpy as np
pts = np.float([kp[idx].pt for idx in range(0, len(kp))]).reshape(-1, 1, 2)
pts
will be an array
of keypoints.
add a comment |
You can use:
import numpy as np
pts = np.float([kp[idx].pt for idx in range(0, len(kp))]).reshape(-1, 1, 2)
pts
will be an array
of keypoints.
add a comment |
You can use:
import numpy as np
pts = np.float([kp[idx].pt for idx in range(0, len(kp))]).reshape(-1, 1, 2)
pts
will be an array
of keypoints.
You can use:
import numpy as np
pts = np.float([kp[idx].pt for idx in range(0, len(kp))]).reshape(-1, 1, 2)
pts
will be an array
of keypoints.
edited Mar 22 at 20:59
user664303
1,51221027
1,51221027
answered Mar 9 '16 at 8:40
Francesco NazzaroFrancesco Nazzaro
1,839717
1,839717
add a comment |
add a comment |
point.pt is a tuple
(x,y)`.
So,
x = point.pt[0]
y = point.pt[1]
or,
(x,y) = point.pt
add a comment |
point.pt is a tuple
(x,y)`.
So,
x = point.pt[0]
y = point.pt[1]
or,
(x,y) = point.pt
add a comment |
point.pt is a tuple
(x,y)`.
So,
x = point.pt[0]
y = point.pt[1]
or,
(x,y) = point.pt
point.pt is a tuple
(x,y)`.
So,
x = point.pt[0]
y = point.pt[1]
or,
(x,y) = point.pt
edited Dec 22 '18 at 4:45
skumhest
54
54
answered May 6 '17 at 8:13
saikat sarkarsaikat sarkar
11115
11115
add a comment |
add a comment |
Read the docs.
class KeyPoint
Data structure for salient point detectors.
Point2f pt
-- coordinates of the keypointfloat size
-- diameter of the meaningful keypoint neighborhoodfloat angle ...¶
So point.pt
is a Point2f.
Try x,y= point.pt
2
point.pt.x
is invalid, please correct it as:x, y = point.pt
– Nirmal
Oct 26 '18 at 5:30
add a comment |
Read the docs.
class KeyPoint
Data structure for salient point detectors.
Point2f pt
-- coordinates of the keypointfloat size
-- diameter of the meaningful keypoint neighborhoodfloat angle ...¶
So point.pt
is a Point2f.
Try x,y= point.pt
2
point.pt.x
is invalid, please correct it as:x, y = point.pt
– Nirmal
Oct 26 '18 at 5:30
add a comment |
Read the docs.
class KeyPoint
Data structure for salient point detectors.
Point2f pt
-- coordinates of the keypointfloat size
-- diameter of the meaningful keypoint neighborhoodfloat angle ...¶
So point.pt
is a Point2f.
Try x,y= point.pt
Read the docs.
class KeyPoint
Data structure for salient point detectors.
Point2f pt
-- coordinates of the keypointfloat size
-- diameter of the meaningful keypoint neighborhoodfloat angle ...¶
So point.pt
is a Point2f.
Try x,y= point.pt
edited Nov 20 '18 at 2:05
answered Mar 9 '16 at 6:37
roadrunner66roadrunner66
3,92331834
3,92331834
2
point.pt.x
is invalid, please correct it as:x, y = point.pt
– Nirmal
Oct 26 '18 at 5:30
add a comment |
2
point.pt.x
is invalid, please correct it as:x, y = point.pt
– Nirmal
Oct 26 '18 at 5:30
2
2
point.pt.x
is invalid, please correct it as: x, y = point.pt
– Nirmal
Oct 26 '18 at 5:30
point.pt.x
is invalid, please correct it as: x, y = point.pt
– Nirmal
Oct 26 '18 at 5:30
add a comment |
Here is my take (runable code):
import cv2, os
import numpy as np
import matplotlib.pyplot as plt
# INITIALISATION
filename = os.path.join('foo', 'bar.jpg')
img0 = cv2.imread(filename) # original image
gray = cv2.cvtColor(img0, cv2.COLOR_BGR2GRAY) # convert to grayscale
sift = cv2.xfeatures2d.SIFT_create() # initialize SIFT
f, (ax1, ax2) = plt.subplots(1, 2) # create subplots
# DETECT AND DRAW KEYPOINTS
# sift.detect() returns a list of keypoints
# keypoint is a standard class of opencv (not just SIFT-related)
kp = sift.detect(gray,None) # calculates SIFT points
img1=cv2.drawKeypoints(gray,kp, None) # mae new image with keypoints drawn
ax1.imshow(img1) # plot
# RETREIVE KEYPOINTS COORDINATES AND DRAW MANUALLY
# Reade these and make numpy array
pts = np.asarray([[p.pt[0], p.pt[1]] for p in kp])
cols = pts[:,0]
rows = pts[:,1]
ax2.imshow(cv2.cvtColor(img0, cv2.COLOR_BGR2RGB))
ax2.scatter(cols, rows)
plt.show()
add a comment |
Here is my take (runable code):
import cv2, os
import numpy as np
import matplotlib.pyplot as plt
# INITIALISATION
filename = os.path.join('foo', 'bar.jpg')
img0 = cv2.imread(filename) # original image
gray = cv2.cvtColor(img0, cv2.COLOR_BGR2GRAY) # convert to grayscale
sift = cv2.xfeatures2d.SIFT_create() # initialize SIFT
f, (ax1, ax2) = plt.subplots(1, 2) # create subplots
# DETECT AND DRAW KEYPOINTS
# sift.detect() returns a list of keypoints
# keypoint is a standard class of opencv (not just SIFT-related)
kp = sift.detect(gray,None) # calculates SIFT points
img1=cv2.drawKeypoints(gray,kp, None) # mae new image with keypoints drawn
ax1.imshow(img1) # plot
# RETREIVE KEYPOINTS COORDINATES AND DRAW MANUALLY
# Reade these and make numpy array
pts = np.asarray([[p.pt[0], p.pt[1]] for p in kp])
cols = pts[:,0]
rows = pts[:,1]
ax2.imshow(cv2.cvtColor(img0, cv2.COLOR_BGR2RGB))
ax2.scatter(cols, rows)
plt.show()
add a comment |
Here is my take (runable code):
import cv2, os
import numpy as np
import matplotlib.pyplot as plt
# INITIALISATION
filename = os.path.join('foo', 'bar.jpg')
img0 = cv2.imread(filename) # original image
gray = cv2.cvtColor(img0, cv2.COLOR_BGR2GRAY) # convert to grayscale
sift = cv2.xfeatures2d.SIFT_create() # initialize SIFT
f, (ax1, ax2) = plt.subplots(1, 2) # create subplots
# DETECT AND DRAW KEYPOINTS
# sift.detect() returns a list of keypoints
# keypoint is a standard class of opencv (not just SIFT-related)
kp = sift.detect(gray,None) # calculates SIFT points
img1=cv2.drawKeypoints(gray,kp, None) # mae new image with keypoints drawn
ax1.imshow(img1) # plot
# RETREIVE KEYPOINTS COORDINATES AND DRAW MANUALLY
# Reade these and make numpy array
pts = np.asarray([[p.pt[0], p.pt[1]] for p in kp])
cols = pts[:,0]
rows = pts[:,1]
ax2.imshow(cv2.cvtColor(img0, cv2.COLOR_BGR2RGB))
ax2.scatter(cols, rows)
plt.show()
Here is my take (runable code):
import cv2, os
import numpy as np
import matplotlib.pyplot as plt
# INITIALISATION
filename = os.path.join('foo', 'bar.jpg')
img0 = cv2.imread(filename) # original image
gray = cv2.cvtColor(img0, cv2.COLOR_BGR2GRAY) # convert to grayscale
sift = cv2.xfeatures2d.SIFT_create() # initialize SIFT
f, (ax1, ax2) = plt.subplots(1, 2) # create subplots
# DETECT AND DRAW KEYPOINTS
# sift.detect() returns a list of keypoints
# keypoint is a standard class of opencv (not just SIFT-related)
kp = sift.detect(gray,None) # calculates SIFT points
img1=cv2.drawKeypoints(gray,kp, None) # mae new image with keypoints drawn
ax1.imshow(img1) # plot
# RETREIVE KEYPOINTS COORDINATES AND DRAW MANUALLY
# Reade these and make numpy array
pts = np.asarray([[p.pt[0], p.pt[1]] for p in kp])
cols = pts[:,0]
rows = pts[:,1]
ax2.imshow(cv2.cvtColor(img0, cv2.COLOR_BGR2RGB))
ax2.scatter(cols, rows)
plt.show()
edited Nov 2 '18 at 12:58
answered Nov 2 '18 at 10:40
quickbugquickbug
1,72441117
1,72441117
add a comment |
add a comment |
OpenCV provides a function for this. You can run:
pts = cv2.KeyPoint_convert(kp)
add a comment |
OpenCV provides a function for this. You can run:
pts = cv2.KeyPoint_convert(kp)
add a comment |
OpenCV provides a function for this. You can run:
pts = cv2.KeyPoint_convert(kp)
OpenCV provides a function for this. You can run:
pts = cv2.KeyPoint_convert(kp)
answered Mar 28 at 13:29
VikVik
304210
304210
add a comment |
add a comment |
I solved your problem like this.
kp,des = surf.detectAndCompute(img,None)
pts = [p.pt for p in kp]
Now you get a list of x,y co-ordinates for all keypoints in your image.
add a comment |
I solved your problem like this.
kp,des = surf.detectAndCompute(img,None)
pts = [p.pt for p in kp]
Now you get a list of x,y co-ordinates for all keypoints in your image.
add a comment |
I solved your problem like this.
kp,des = surf.detectAndCompute(img,None)
pts = [p.pt for p in kp]
Now you get a list of x,y co-ordinates for all keypoints in your image.
I solved your problem like this.
kp,des = surf.detectAndCompute(img,None)
pts = [p.pt for p in kp]
Now you get a list of x,y co-ordinates for all keypoints in your image.
edited Oct 6 '17 at 9:06
Shaido
13.4k123045
13.4k123045
answered Oct 6 '17 at 8:49
Alexander HuntAlexander Hunt
1
1
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%2f35884409%2fhow-to-extract-x-y-coordinates-from-opencv-cv2-keypoint-object%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