how to extract x,y coordinates from OpenCV “cv2.keypoint” object?
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
1442510
1442510
add a comment |
add a comment |
5 Answers
5
active
oldest
votes
You can use:
import numpy as np
pts = np.float([kp[idx].pt for idx in 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
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 |
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
5 Answers
5
active
oldest
votes
5 Answers
5
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 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 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 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 len(kp)]).reshape(-1, 1, 2)
pts
will be an array
of keypoints.
answered Mar 9 '16 at 8:40
Francesco NazzaroFrancesco Nazzaro
1,809617
1,809617
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
9114
9114
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
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
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,74321834
3,74321834
point.pt.x
is invalid, please correct it as:x, y = point.pt
– Nirmal
Oct 26 '18 at 5:30
add a comment |
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
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,65931117
1,65931117
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
12.6k122541
12.6k122541
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