Sift Beginner

asked 2016-03-14 07:25:50 -0600

mmmmhw gravatar image

updated 2016-03-14 08:06:02 -0600

berak gravatar image

Please ignore the first question that i have posted

Again the problem i encountered is about SIFT

Here is my actual code and error

   #include "opencv2/core/core_c.h"
   #include "opencv2/core/core.hpp"
   #include "opencv2/flann/miniflann.hpp"
   #include "opencv2/imgproc/imgproc_c.h"
   #include "opencv2/imgproc/imgproc.hpp"
   #include "opencv2/video/video.hpp"
   #include "opencv2/features2d/features2d.hpp"
   #include "opencv2/objdetect/objdetect.hpp"
   #include "opencv2/calib3d/calib3d.hpp"
   #include "opencv2/ml/ml.hpp"
   #include "opencv2/highgui/highgui_c.h"
   #include "opencv2/highgui/highgui.hpp"
   #include "opencv2/contrib/contrib.hpp"


int main()
{    
 import cv2
  import numpy as np

     img = cv2.imread('python.jpeg')
     gray= cv2.cvtColor(img,cv2.COLOR_BGR2GRAY)

     sift = cv2.xfeatures2d.SIFT_create()
     kp = sift.detect(gray,None)

    img=cv2.drawKeypoints(gray,kp)

    cv2.imwrite('sift_keypoints.jpg',img)

   img=cv2.drawKeypoints(gray,kp,flags=cv2.DRAW_MATCHES_FLAGS_DRAW_RICH_KEYPOINTS)
    cv2.imwrite('sift_keypoints.jpg',img)

}

the error i have encountered

sift.cpp:21:23: warning: character constant too long for its type [enabled by default]

      img = cv2.imread('python.jpeg')
                       ^
sift.cpp:29:17: warning: character constant too long for its type [enabled by default]

     cv2.imwrite('sift_keypoints.jpg',img)
                 ^
sift.cpp:31:17: warning: character constant too long for its type [enabled by default]

     cv2.imwrite('sift_keypoints.jpg',img)
                 ^
sift.cpp: In function ‘int main()’:

sift.cpp:18:2: error: ‘import’ was not declared in this scope

  import cv2
  ^
sift.cpp:18:9: error: expected ‘;’ before ‘cv2’

  import cv2
         ^
edit retag flag offensive close merge delete

Comments

your whole content of main() is python, not c++., you're confusing languages.

berak gravatar imageberak ( 2016-03-14 08:06:52 -0600 )edit

is there a way to implement it in C++?

mmmmhw gravatar imagemmmmhw ( 2016-03-14 08:14:30 -0600 )edit

which opencv version are you using ? here's it for 3.x

berak gravatar imageberak ( 2016-03-14 08:19:51 -0600 )edit

opencv 3.1.0

mmmmhw gravatar imagemmmmhw ( 2016-03-14 08:27:33 -0600 )edit