Menu
  • HOME
  • TAGS

how to use SIFT features for bag of words in opencv?

Tag: opencv,sift,multilabel-classification

I have read a lot of articles about implementing bag of words after taking sift features of an image, but I'm still confused what to do next. What do i specifically do?

Thank you so much in advance for the guidance.

This is the code that i have so far.

cv::Mat mat_img = cropped.clone();
Mat grayForML;
cvtColor(mat_img, grayForML, CV_BGR2GRAY);
IplImage grayImageForML = grayForML.operator IplImage();


//create another copy of iplGray
IplImage *input = cvCloneImage(&grayImageForML);
Mat matInput = cvarrToMat(input);
//  Mat matInput = copy_gray.clone();
cv::SiftFeatureDetector detector;
std::vector<cv::KeyPoint> keyPoints;
detector.detect(input, keyPoints);
//add results to image and save.
cv::Mat output;
cv::drawKeypoints(input, keyPoints, output);    //SIFT OUTPUT RESULT


//resize and display
cv::Mat output_reduced;
cv::resize(output, output_reduced, cv::Size2i(output.cols / 2, output.rows / 2));


imshow("SIFT result", output_reduced);

Best How To :

Training a bag of words system goes as follows:

  1. Compute the features for each image of the training set
  2. Cluster those features
  3. Label each cluster with the images that have features in that cluster

At this point the training is done and you can start with the testing as follows:

  1. Compute the features of the test image
  2. For each feature, find the nearest cluster
  3. Add a tick for each training image that belong to this cluster
  4. Repeat for all features of the test image
  5. The image that has the highest number of ticks is the best match and the image with the second highest number of ticks is the second best match and so on

As you can notice, there is no restriction to using SIFT. You can try different feature extractors and descriptors.

Detecting face using haar-like cascade in opencv using c++

c++,opencv

You must be seeing compiler errors like this: /tmp/cckqEgtd.o: In function `main': face.cpp:(.text+0x50): undefined reference to `cv::imread(std::string const&, int)' face.cpp:(.text+0x87): undefined reference to `cv::_InputArray::_InputArray(cv::Mat const&)' face.cpp:(.text+0xca): undefined reference to `cv::imshow(std::string const&, cv::_InputArray const&)' face.cpp:(.text+0x101): undefined reference to `cv::_OutputArray::_OutputArray(cv::Mat&)' face.cpp:(.text+0x11a): undefined reference to...

error using already compiled version of openCV

c++,c,linux,opencv

You have not linked the executable against several libraries that are required by the program Try using this: g++ -lpthread `pkg-config opencv --libs` -I/usr/local/include/ -lraspicam -lraspicam_cv -L/opt/vc/lib -lmmal -lmmal_core -lmmal_util -I/usr/include -lwiringPi test3.cpp -o test3 ...

Cmake errors: The CXX Compiler identification is unknown, The C compiler identification is unknown

c++,opencv,cmake,arm,cmake-gui

From the output it appears that cmake was able to find your cross compiler but as the output says it can't compile a simple program. I would start with creating Hello World in C++ and trying to compile that with your cross compiler. If that doesn't work that is your...

Creating a 25fps slow motion video from a 100fps GoPro .mp4 video with C++/OpenCV

c++,opencv,video,visual-studio-2013,slowmotion

As I suspected, it's the Coded! I used many of them, but then I found this question: Create Video from images using VideoCapture (OpenCV) then I used the coded MJPG in: outputVideo.open(name, CV_FOURCC('M', 'J', 'P', 'G'), 25, size, true); // create a new videoFile with 25fps and it worked! Here's...

Camera calibration and conversion of coordinates(OpenCV)

c++,opencv,c++11,computer-vision

The camera calibration process estimates the intrinsic camera parameters: the camera matrix, usually denoted K, and the lens distortion coefficients, D. (NB: the rotation translation matrices of the camera with respect to the pattern are also computed for each image used for the calibration, see "Extrinsic_Parameters", but they are generally...

OpenCV 2.4.3 Download [on hold]

c++,opencv

Downloaded 2.4.11 version couple weeks ago, so I guess that's the latest stable 2x version. You should be fine learning stuff from whole 2.4 version, most of them are essentially the same, this newspost tells that 2.4.3 version was more a bug and performance update. Offtopic, learning via Youtube videos...

Dividing main function into other functions in opencv using c++

c++,opencv

You should always do things that improve the readability and understandability of your code when first learning a language. (And, in many cases, well beyond that point.) Readability of code should be your number one priority at this point. That being said, functions do not really cost any more time...

adaptive thresholding ---ValueError: too many values to unpack

python,opencv,image-processing,adaptive-threshold

As per the documentation, the cv2.adaptiveThreshold() returns only 1 value that is the threshold image and in this case you are trying to receive 2 values from that method, that is why ValueError: too many values to unpack error is raised. After fixing the issue the code may look like:...

Error : Cmake can't generate openCV

opencv,cmake,codeblocks

just do the obvious thing, and specify your c, c++ compiler and the make tool in question: cmake -G "MinGW Makefiles" -DCMAKE_MAKE_PROGRAM="D:/Programme/MinGW/bin/mingw32-make.exe" -DCMAKE_CXX_COMPILER="D:/Programme/MinGW/bin/mingw32-g++.exe" -DCMAKE_C_COMPILER="D:/Programme/MinGW/bin/mingw32-gcc.exe" -DWITH_IPP=OFF .. (ofc. your path will vary, but i hope, you get the idea) ((if you read between the lines - the opencv devs seem to...

Using OpenCV in Swift iOS

ios,swift,opencv,image-processing

OpenCV is a framework written in C++. Apple's reference tell us that You cannot import C++ code directly into Swift. Instead, create an Objective-C or C wrapper for C++ code. so you cannot directly import and use OpenCV in a swift project, but this is actually not bad at all...

c++ read in image set with different file names without hardcoding

c++,image,opencv,boost,image-loading

For anyone else wondering: #include <boost/filesystem.hpp> namespace fs = boost::filesystem; std::vector<cv::Mat> imageVec; fs::path p ("."); fs::directory_iterator end_itr; // cycle through the directory for (fs::directory_iterator itr(p); itr != end_itr; ++itr){ // If it's not a directory, list it. If you want to list directories too, just remove this check. if (fs::is_regular_file(itr->path()))...

OpenCV / Image Processing techniques to find the centers of bright spots in an image

python,opencv,image-processing,feature-detection

The main thing to take away is energy function used in this context is any function that is used for a maximization problem. Here, the energy function is the sum of gradients/derivatives/differences (i.e. "detected borders likelihood" in this case). Since you seem to have a non-algorithmic background, I suggest you...

Creating and referencing a library for Android project (using command line and gradle)

java,android,linux,opencv,gradle

I was finally able to create a library and use it in my Android project! The following links were helpful: http://tools.android.com/tech-docs/new-build-system/user-guide#TOC-Dependencies-Android-Libraries-and-Multi-project-setup https://docs.gradle.org/current/userguide/multi_project_builds.html http://www.petrikainulainen.net/programming/gradle/getting-started-with-gradle-creating-a-multi-project-build/ This whole process made me understand why most people just use Ecipse or Adnroid Studio. But if anyone else wants to try this, I will...

Visual Studio 2013 LINK : fatal error LNK1181: cannot open input file

c++,visual-studio,opencv,visual-c++,visual-studio-2013

Remove all references to the library. Somewhere that project is pointing at the path you give above and you need to remove that. Then add the library into the executable project. Right click->add->existing item, change the type to all files, then browse to the file location. ...

opencv after install characters look awkward [duplicate]

opencv

problem solved from this link they had similar opencv :: Multiple unwanted window with Garbage name thanks for you all :) now am having one frame and perfect resolution...

Sending a Mat object over socket from Java to Java

java,sockets,opencv,mat

What I think is to Save Mat using FileStorage class using JNI. The following code can be used to save Mat as File Storage FileStorage storage("image.xml", FileStorage::WRITE); storage << "img" << mat; storage.release(); Then send the file using Socket and then retrive Mat back from File. FileStorage fs("image.xml", FileStorage::READ); Mat...

Error for cv::FileStorage in JNI

android,c++,opencv,android-ndk,file-storage

After a lot of debugging I found that the error was quite small The error was in the line LOCAL_LDLIBS := -llog -ldl The line should have been LOCAL_LDLIBS += -llog -ldl ...

Opencv mlp Same Data Different Results

c++,opencv,machine-learning,neural-network,weight

I've only done a little bit of poking around so far, but what I've seen confirms my first suspicion... It looks as though each time you start the program, the random number generator is seeded to a fixed value: rng = RNG((uint64)-1); So each time you run the program you're...

Camera Calibration with OpenCV: Using the distortion and rotation-translation matrix

c++,opencv,computer-vision,robotics

Answers in order: 1) "r" is the pixel's radius with respect to the distortion center. That is: r = sqrt((x - x_c)^2 + (y - y_c)^2) where (x_c, y_c) is the center of the nonlinear distortion (i.e. the point in the image that has zero nonlinear distortion. This is usually...

Android edit images on the fly

android,opencv,bitmap,android-bitmap,opencv4android

Well... It seems you haven´t googled enough :P What is the best java image processing library/approach? There are lots of pure java implementations for image manipulation and effects....

OpenCV & Python: quickly superimpose mask over image without overflow

python,opencv,numpy,mask

There might be better ways of applying a colorizing mask to an image, but if you want to do it the way you suggest, then this simple clipping will do what you want: import numpy as np image[:, :, 0] = np.clip(image[:, :, 0] + color_delta[0] * (mask[:, :, 0]...

Extracting Points from Lines using OpenCV

c++,opencv

You can get each point of the raster line using cv::LineIterator class, e.g.: // grabs pixels along the line (pt1, pt2) // from 8-bit 3-channel image to the buffer LineIterator it(img, pt1, pt2, 8); LineIterator it2 = it; vector<Vec3b> buf(it.count); for(int i = 0; i < it.count; i++, ++it) buf[i]...

OpenCV Save a Mat as Binary (1-bit depth) TIFF

opencv,tiff,binary-image

Only 8-bit (or 16-bit unsigned) single-channel or 3-channel images can be saved by imwrite.

Fastest way to copy some rows from one matrix to another in OpenCV

c++,matlab,opencv,matrix

So I tried different methods for this problem and the only way I could achieve a better performance than Matlab was using memcpy and directly copying the data myself. Mat out( index.cols, w2c.cols, w2c.type() ); for ( int i=0;i<index.cols;++i ){ int ind = index.at<int>(i)-1; const float *src = w2c.ptr<float> (ind);...

Must compile Opencv with Mingw in order to use in QT under Winodws?

qt,opencv,mingw

You can compile it with Visual Studio as well. The opencv includepaths already have the opencv2 part of it. So the correct includepath would only be: C:\\opencv2.4.11\\opencv\\build\\include ...

Extracting polygon given coordinates from an image using OpenCV

python,opencv,image-processing

Use cv2.fillConvexPoly so that you can specify a 2D array of points and define a mask which fills in the shape that is defined by these points to be white in the mask. Some fair warning should be made where the points that are defined in your polygon are convex...

How to evenly distribute numbers 0 to n into m different containers

c++,opencv,math

Solving this problem requires the knowledge of three simple tricks: 1. Interpolation: The process of gradually changing from one value to another is called interpolation. There are multiple ways of interpolating color values: the simplest one is to interpolate each component linearly, i.e. in the form of: interpolated = start...

conversion between Mat and Mat1b/Mat3b

c++,opencv,image-processing,mat

Mat1b and Mat3b are just two pre-defined cases of Mat types, which are defined in core.hpp as follows: typedef Mat_<uchar> Mat1b; ... typedef Mat_<Vec3b> Mat3b; That said, conversion between Mat and Mat1b/Mat3b should be quite natural/automatic: Mat1b mat1b; Mat3b mat3b; Mat mat; mat = mat1b; mat = mat3b; mat1b =...

opencv window not refreshing at mouse callback

c++,opencv

your code works for me. But you used cv::waitKey(0) which means that the program waits there until you press a keyboard key. So try pressing a key after drawing, or use cv::waitKey(30) instead. If this doesnt help you, please add some std::cout in your callback function to verify it is...

Kinectv2 normalizing depth values

c#,opencv,computer-vision,kinect,kinect-sdk

That line of code is used to normalize depth values, which are coded in 11 bits in the C++ API. With that command, the 11-bit representation is converted in an 8-bit one, which allows to display the depth map as a grayscale image. Anyway, you don't need to use that...

how to use SIFT features for bag of words in opencv?

opencv,sift,multilabel-classification

Training a bag of words system goes as follows: Compute the features for each image of the training set Cluster those features Label each cluster with the images that have features in that cluster At this point the training is done and you can start with the testing as follows:...

OpenCV return keypoints coordinates and area from blob detection, Python

python,opencv

The pt property: keypoints = detector.detect(frame) #list of blobs keypoints x = keypoints[i].pt[0] #i is the index of the blob you want to get the position y = keypoints[i].pt[1] Some documentation ...

How to call OpenCV's MatchTemplate method from C#

c#,opencv,image-processing,emgucv,opencvsharp

Not sure what's wrong with the original C-like code, but I'm managed to get it working with C++ like code: using OpenCvSharp; using OpenCvSharp.CPlusPlus; // ... var image = new Mat("Image.png"); var template = new Mat("Template.png"); double minVal, maxVal; Point minLoc, maxLoc; var result = image.MatchTemplate(template, MatchTemplateMethod.CCoeffNormed); result.MinMaxLoc(out minVal, out...

How to create thumbnails using opencv-python?

python,opencv,image-processing,python-imaging-library

You can use cv2.resize . Documentation here: http://docs.opencv.org/modules/imgproc/doc/geometric_transformations.html#resize In your case, assuming the input image im is a numpy array: maxsize = (1024,1024) imRes = cv2.resize(im,maxsize,interpolation=cv2.CV_INTER_AREA) There are different types of interpolation available (INTER_CUBIC, INTER_NEAREST, INTER_AREA,...) but according to the documentation if you need to shrink the image, you should...

how can i know if the image is in RGB or BGR format?

java,opencv,image-processing,rgb,bgr

If your image is a BufferedImage then you can ask for his type with getType(), and test against the several constants (see: BufferedImage).

Surface normal on depth image

c++,opencv,computer-vision

You need to know the camera's intrinsic parameters, so that you can also know the distance between pixels in the same units (mm). This distance between pixels is obviously true for a certain distance from the camera (i.e. the value of the center pixel) If the camera matrix is K...

How to create rotated rectangular or polygonal ROI/mask?

c++,opencv,mask,threshold,roi

The idea is to use fillPoly() to fill all the pixels inside the rotated-rectangle/polygon to 0, 255 otherwise: Mat mask = cv::Mat(img.size(), CV_8UC1, Scalar(255)); // suppose img is your image Mat vector<vector<Point>> pts = { { pt1, pt2, pt3, pt4 } }; fillPoly(mask, pts, Scalar(0)); // <- do it here...

opencv convertTo not working

c++,opencv

This is not the right way to test for type conversion. OpenCV's data variable in cv::Mat is always of type uchar. It is basically a pointer to memory, but it doesn't mean that the data is uchar. To get the type of the image data use the type() function. Here...

Sending live video frame over network in python opencv

python,opencv,numpy

Few things: use sendall instead of send since you're not guaranteed everything will be sent in one go pickle is ok for data serialization but you have to make a protocol of you own for the messages you exchange between the client and the server, this way you can know...

What's the fastest way to compare point elements with each other?I have used Nested for loop to do that, but it's very slow

c++,opencv,for-loop,dictionary,vector

for 20000 random points with about 27 neighbors for each point this function gave me a speed-up. It needed about 33% less time than your original method. std::vector<std::vector<cv::Point> > findNeighborsOptimized(std::vector<cv::Point> p, float maxDistance = 3.0f) { std::vector<std::vector<cv::Point> > centerbox(p.size()); // already create a output vector for each input point /*...

Is there a way to prevent rounding in opencv matrix divison

c++,opencv

Similar to @GPPK's optional method, you can hack it by: Mat tmp, dst; c.convertTo(tmp, CV_64F); tmp = tmp / 8 - 0.5; // simulate to prevent rounding by -0.5 tmp.convertTo(dst, CV_32S); cout << dst; ...

OpenCV - Method 'knnMatch' could not be resolved

c++,opencv,include

You're using a Ptr<DescriptorMatcher> so you should dereference it in order to call the method... matcher.knnMatch(descriptorsLeft, descriptorsRight,3); //error matcher->knnMatch(descriptorsLeft, descriptorsRight,3); // should be better ...

OpenCV - Detection of moving object C++

c++,opencv

Plenty of solutions are possible. A geometric approach would detect that the one moving blob is too big to be a single passenger car. Still, this may indicate a car with a caravan. That leads us to another question: if you have two blobs moving close together, how do you...

java.lang.NoClassDefFoundError: org/opencv/core/Core - Java Servlet + OpenCV

java,opencv,servlets

You need to make your OpenCV jar available to both the IDE as well as the application server. I believe you've already made it available to your IDE by adding it to your web project's classpath. Now to satisfy the dependency when running on the application server too, just copy...

best way to create a mat from a CIImage?

c++,xcode,osx,opencv,opencv3.0

Found a solution to get rid of the crash: use createCGImage:fromRect to skip the NSBitmapImageRef step: - (void)OpenCVdetectSmilesIn:(CIFaceFeature *)faceFeature usingImage:ciFrameImage { CGRect lowerFaceRectFull = faceFeature.bounds; lowerFaceRectFull.size.height *=0.5; CIImage *lowerFaceImageFull = [ciFrameImage imageByCroppingToRect:lowerFaceRectFull]; // Create the context and instruct CoreImage to draw the output image recipe into a CGImage if( self.context...

OpenCV FAST corner detection SSE implementation walkthrough

c,performance,opencv,optimization,sse

As harold said, delta is used to make unsigned comparsion. Let's describe this implementation by steps: __m128i x0 = _mm_sub_epi8(_mm_loadu_si128((const __m128i*)(ptr + pixel[0])), delta); __m128i x1 = _mm_sub_epi8(_mm_loadu_si128((const __m128i*)(ptr + pixel[4])), delta); __m128i x2 = _mm_sub_epi8(_mm_loadu_si128((const __m128i*)(ptr + pixel[8])), delta); __m128i x3 = _mm_sub_epi8(_mm_loadu_si128((const __m128i*)(ptr + pixel[12])), delta); m0 =...

Bandpass Filter in Python for Image Processing

python,image,opencv,image-processing,filtering

This might be what you're looking for: http://matplotlib.org/users/image_tutorial.html Specificially look at the "Examining a specific data range" This will allow you to easily clip the image....

solvePnP: Obtaining the rotation translation matrix

c++,opencv,matrix,computer-vision,transform

Reading the (excellent) OpenCV documentation for solvePnP might help: "rvec – Output rotation vector (see Rodrigues() ) that, together with tvec , brings points from the model coordinate system to the camera coordinate system." And following the link to Rodrigues(): src – Input rotation vector (3x1 or 1x3) or rotation...

How to install shared library and include files manually in linux?

linux,opencv,cmake,raspberry-pi

As a work around, I created tbb.pc file to /usr/lib/pkgconfig/. Here is a sample of that file. https://github.com/openembedded/meta-oe/blob/master/meta-oe/recipes-support/tbb/tbb/tbb.pc Change prefix, libdir and include dir path according to your own tbb path and you're good to go. Hope it helps....