Git Product home page Git Product logo

opencv-tutorial's Introduction

OpenCV Tutorial

This repository contains source code of OpenCV Tutorial application.

Samples list (done)

  • Edge detection (Canny, Sobel, Schaar)
  • Image transformations (Sepia, negative, contrast and brightness adjustments)
  • Feature Detection (SURF, ORB, FREAK)
  • Video tracking (KLT, BRIEF, ORB)

Samples list (plans)

  • PTAM

Step by step tutorials

Roadmap

http://computer-vision-talks.com/opencv-tutorial-roadmap/

Copyright

Idea and development by Eugene Khvedchenya [email protected]

http://computer-vision-talks.com

This application is provided via BSD licence, it is free for both academic and commercial use.

This application is provided as-is, with no warranty expressed or implied. Use this application at your own risk. The author assumes no liability for any loss associated with the use of this application. If you do not agree with the terms of this license, do not install this application.

Contributors

opencv-tutorial's People

Contributors

bloodaxe avatar kudit avatar neptilo avatar valeriyvan avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

opencv-tutorial's Issues

featureDetectionClass openCV Error: Assertion failed

OpenCV Error: Assertion failed (type == src2.type() && src1.cols == src2.cols && (type == CV_32F || type == CV_8U)) in batchDistance, file /Users/vp/work/opencv/modules/core/src/stat.cpp, line 3208
libc++abi.dylib: terminating with uncaught exception of type cv::Exception: /Users/vp/work/opencv/modules/core/src/stat.cpp:3208: error: (-215) type == src2.type() && src1.cols == src2.cols && (type == CV_32F || type == CV_8U) in function batchDistance

Getting this error when i move my device away from the image.
Below is Line where crashing:
matcher->knnMatch(descriptors1,
descriptors2,
matches1, // vector of matches (up to 2 per entry)
2); // return 2 nearest neighbours

Build Errors for iOS 8.4 in Xcode 7.0.1

Conversion errors are not shown.

iOS 8.4

CameraCalibrationAlgorithm.cpp

  • Code will never be executed
if (false && m_patternfound)
{
    const cv::TermCriteria tc = cv::TermCriteria(cv::TermCriteria::EPS + cv::TermCriteria::COUNT, 30, 0.1);
    cv::cornerSubPix(frame, corners2d, cv::Size(5, 5), cv::Size(-1, -1), tc);
}
  • Unused variable 'rms'
double rms = cv::calibrateCamera(objectPoints, imagePoints, imageSize, cameraMatrix,
                                 distCoeffs, rvecs, tvecs, flags | cv::CALIB_FIX_K4 | cv::CALIB_FIX_K5);
  • LEAK: Value stored to 'rms' during its initialization is never read

ImageViewController.mm

  • ’setContentSizeForViewInPopover:' is deprecated: first deprecated in iOS 7.0 - Use UIViewController.preferredContentSize instead.

BaseSampleViewController.mm

  • ’TWTweetComposeViewController' is deprecated: first deprecated in iOS 6.0
  • ’presentModalViewController:animated:' is deprecated: first deprecated in iOS 6.0

UIImage2OpenCV.mm

  • LEAK: Potential leak of an object stored into 'imageRef'
    • Call to function 'CGImageCreateWithImageInRect' returns a Core Foundation object with a +1 retain count
    • Object leaked: object allocated and stored into 'imageRef' is not referenced later in this execution path and has a retain count of +1

SampleOptionsTableViewDelegate.mm

  • LEAK: Instance variable used while 'self' is not set to the result of '[(super or self) init...]'
  • LEAK: Returning 'self' while it is not set to the result of '[(super or self) init...]'

FeatureDetectionClass.cpp

  • LEAK: Value stored to 'removed' during its initialization is never read
  • LEAK: FeatureDetectionClass.cpp:268:5: Value stored to 'removed' is never read

(null): warning: Could not resolve external type _ZTSNSt3__113basic_ostreamIcNS_11char_traitsIcEEE6sentryE
(null): warning: Could not resolve external type _ZTSNSt3__16vectorIfNS_9allocatorIfEEE24__RAII_IncreaseAnnotatorE
(null): warning: Could not resolve external type _ZTSNSt3__16vectorIN2cv8KeyPointENS_9allocatorIS2_EEE24__RAII_IncreaseAnnotatorE
(null): warning: Could not resolve external type _ZTSNSt3__16vectorIN2cv3MatENS_9allocatorIS2_EEE24__RAII_IncreaseAnnotatorE
(null): warning: Could not resolve external type _ZTSNSt3__16vectorIhNS_9allocatorIhEEE24__RAII_IncreaseAnnotatorE

iOS 9

VideoViewController.h

  • ’UIPopoverController' is deprecated: first deprecated in iOS 9.0 - UIPopoverController is deprecated. Popovers are now implemented as UIViewController presentations. Use a modal presentation style of UIModalPresentationPopover and UIPopoverPresentationController.

ImageViewController.h

  • ‘UIPopoverController' is deprecated: first deprecated in iOS 9.0 - UIPopoverController is deprecated. Popovers are now implemented as UIViewController presentations. Use a modal presentation style of UIModalPresentationPopover and UIPopoverPresentationController.

DetailViewController.mm

  • ’UIPopoverController' is deprecated: first deprecated in iOS 9.0 - UIPopoverController is deprecated. Popovers are now implemented as UIViewController presentations. Use a modal presentation style of UIModalPresentationPopover and UIPopoverPresentationController.

CameraCalibrationAlgorithm.cpp

  • Code will never be executed
if (false && m_patternfound)
{
    const cv::TermCriteria tc = cv::TermCriteria(cv::TermCriteria::EPS + cv::TermCriteria::COUNT, 30, 0.1);
    cv::cornerSubPix(frame, corners2d, cv::Size(5, 5), cv::Size(-1, -1), tc);
}
  • Unused variable 'rms'
double rms = cv::calibrateCamera(objectPoints, imagePoints, imageSize, cameraMatrix,
                                 distCoeffs, rvecs, tvecs, flags | cv::CALIB_FIX_K4 | cv::CALIB_FIX_K5);
  • LEAK: Value stored to 'rms' during its initialization is never read

VideoViewController.mm

  • ’UIPopoverController' is deprecated: first deprecated in iOS 9.0 - UIPopoverController is deprecated. Popovers are now implemented as UIViewController presentations. Use a modal presentation style of UIModalPresentationPopover and UIPopoverPresentationController.

ImageViewController.mm

  • ’UIPopoverController' is deprecated: first deprecated in iOS 9.0 - UIPopoverController is deprecated. Popovers are now implemented as UIViewController presentations. Use a modal presentation style of UIModalPresentationPopover and UIPopoverPresentationController.
  • ’UIPopoverController' is deprecated: first deprecated in iOS 9.0 - UIPopoverController is deprecated. Popovers are now implemented as UIViewController presentations. Use a modal presentation style of UIModalPresentationPopover and UIPopoverPresentationController.
  • ’setContentSizeForViewInPopover:' is deprecated: first deprecated in iOS 7.0 - Use UIViewController.preferredContentSize instead.
  • ’UIPopoverController' is deprecated: first deprecated in iOS 9.0 - UIPopoverController is deprecated. Popovers are now implemented as UIViewController presentations. Use a modal presentation style of UIModalPresentationPopover and UIPopoverPresentationController.
  • ’ALAssetsLibrary' is deprecated: first deprecated in iOS 9.0 - Use PHPhotoLibrary from the Photos framework instead
  • ’ALAssetsLibraryAssetForURLResultBlock' is deprecated: first deprecated in iOS 9.0 - Use fetchAssetsWithLocalIdentifiers:options: on PHAsset to fetch assets by local identifier (or to lookup PHAssets by a previously known ALAssetPropertyAssetURL use fetchAssetsWithALAssetURLs:options:) from the Photos framework instead
  • ’defaultRepresentation' is deprecated: first deprecated in iOS 9.0 - Use PHImageRequestOptions with the PHImageManager from the Photos framework instead
  • ’fullResolutionImage' is deprecated: first deprecated in iOS 9.0 - Use requestImageForAsset:targetSize:contentMode:options:resultHandler: on PHImageManager to request a targetSize PHImageManagerMaximumSize for a PHAsset from the Photos framework instead
  • ’ALAsset' is deprecated: first deprecated in iOS 9.0 - Use PHAsset from the Photos framework instead
  • ’ALAssetRepresentation' is deprecated: first deprecated in iOS 9.0 - Use PHImageRequestOptions with the PHImageManager from the Photos framework instead
  • ’ALAssetsLibraryAccessFailureBlock' is deprecated: first deprecated in iOS 9.0 - Use the Photos framework instead
  • ’assetForURL:resultBlock:failureBlock:' is deprecated: first deprecated in iOS 9.0 - Use fetchAssetsWithLocalIdentifiers:options: on PHAsset to fetch assets by local identifier (or to lookup PHAssets by a previously known ALAssetPropertyAssetURL use fetchAssetsWithALAssetURLs:options:) from the Photos framework instead

BaseSampleViewController.mm

  • ’TWTweetComposeViewController' is deprecated: first deprecated in iOS 6.0
  • ’presentModalViewController:animated:' is deprecated: first deprecated in iOS 6.0
  • ’UIAlertView' is deprecated: first deprecated in iOS 9.0 - UIAlertView is deprecated. Use UIAlertController with a preferredStyle of UIAlertControllerStyleAlert instead

UIImage2OpenCV.mm

  • LEAK: Potential leak of an object stored into 'imageRef'
    • Call to function 'CGImageCreateWithImageInRect' returns a Core Foundation object with a +1 retain count
    • Object leaked: object allocated and stored into 'imageRef' is not referenced later in this execution path and has a retain count of +1

SampleOptionsTableViewDelegate.mm

  • LEAK: Instance variable used while 'self' is not set to the result of '[(super or self) init...]'
  • LEAK: Returning 'self' while it is not set to the result of '[(super or self) init...]'

FeatureDetectionClass.cpp

  • LEAK: Value stored to 'removed' during its initialization is never read
  • LEAK: Value stored to 'removed' is never read

(null): warning: Could not resolve external type _ZTSNSt3__113basic_ostreamIcNS_11char_traitsIcEEE6sentryE
(null): warning: Could not resolve external type _ZTSNSt3__16vectorIfNS_9allocatorIfEEE24__RAII_IncreaseAnnotatorE
(null): warning: Could not resolve external type _ZTSNSt3__16vectorIN2cv8KeyPointENS_9allocatorIS2_EEE24__RAII_IncreaseAnnotatorE
(null): warning: Could not resolve external type _ZTSNSt3__16vectorIN2cv3MatENS_9allocatorIS2_EEE24__RAII_IncreaseAnnotatorE
(null): warning: Could not resolve external type _ZTSNSt3__16vectorIhNS_9allocatorIhEEE24__RAII_IncreaseAnnotatorE

Mastering OpenCV Chapter 3 : generating 3d points

I need a bit of help with this code. I am trying to generate 3d points for the keypoints extracted from the webcam. It executes the code but the 3d points cannot be viewed.
code
to compute the pose of each 2d point extracted I used the code

Transformation ARPipeline::computePose(const std::vectorcv::Point2f& points, const CameraCalibration& calibration,cv::Mat& camframe)
{
points3d.resize(points.size());

for(int i = 0; i < points.size();i++)
{
    points3d[i]=cv::Point3f(points[i].x, points[i].y, 0.0);
}

cv::Mat Rvec;

cv::Mat_ Tvec;
cv::Mat raux,taux;
cv::solvePnPRansac(points3d, points, calibration.getIntrinsic(), calibration.getDistorsion(),raux,taux);
raux.convertTo(Rvec,CV_32F);
taux.convertTo(Tvec ,CV_32F);

cv::Mat_ rotMat(3,3);
cv::Rodrigues(Rvec, rotMat);

// Copy to transformation matrix
for (int col=0; col<3; col++)
{
for (int row=0; row<3; row++)
{
pose3d.r().mat[row][col] = rotMat(row,col); // Copy rotation component
}
pose3d.t().data[col] = Tvec(col); // Copy translation component
}

// Since solvePnP finds camera location, w.r.t to marker pose, to get marker pose w.r.t to the camera we invert it.
pose3d = pose3d.getInverted();
return pose3d;
}

then to display the 3d point I use
drawPoint()
{
glPushAttrib(GL_COLOR_BUFFER_BIT | GL_CURRENT_BIT | GL_ENABLE_BIT | GL_LIGHTING_BIT | GL_POLYGON_BIT| GL_POINT|GL_POINTS|GL_POINT_BIT);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();

glEnable(GL_BLEND);
glEnable(GL_COLOR_MATERIAL);
glColor3f(0,1,1);
glPointSize(10);
glBegin(GL_POINTS);
std::cout<<"XXX"<<std::endl;
for(int i=0;i<m_points2.size();i++)
glVertex3f(m_points2[0].x, m_points2[0].y, 0.0);
glEnd();
glPopAttrib();
}

it is called by the function

void ARDrawingContext::drawAugmentedScene()
{
// Init augmentation projection
Matrix44 projectionMatrix;
int w = m_backgroundImage.cols;
int h = m_backgroundImage.rows;
buildProjectionMatrix(m_calibration, w, h, projectionMatrix);

glMatrixMode(GL_PROJECTION);
glLoadMatrixf(projectionMatrix.data);

glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
Matrix44 glMatrix = patternPose.getMat44();

glLoadMatrixf(reinterpret_cast<const GLfloat*>(&glMatrix.data[0]));

drawPoints();
}

I use the same approach as in chapter 3 of mastering OpenCV the only difference is I am trying to display a map of 3d points instead of cube and there is no pattern it only consists of keypoints from the web cam. I cant make out if any line is missing in the drawPoint function . I have used the same functions
void ARDrawingContext::drawCameraFrame(), buildProjectionMatrix()
void void ARDrawingContext::drawAugmentedScene and draw()
the extra is drawPoint()

am not sure which parameter is missing can you please help

Linker error for iOS6, libs in project don't have armv7s slices

ld: file is universal (2 slices) but does not contain a(n) armv7s slice: /Users/blablabla/Documents/OpenCV-Tutorial/opencv/lib/Debug/libzlib.a for architecture armv7s
clang: error: linker command failed with exit code 1 (use -v to see invocation)

That's from xcode 4.5.2.
xcode 4.4.1 (the last which supports armv6) builds project just fine for iPhone 4 as well as for simulator.

getting memory warning

I am using opencv framework for flood fill . It works perfectly but after some time getting memory warning ..

I am testing my app for leakages. I notice that my app grows by 3 to 4 mb each time I run my opencv functions.

Code For IPL image to UIImage:

  • (UIImage )UIImageFromIplImage:(IplImage)image {

CGColorSpaceRef colorSpace;

if (image->nChannels == 1) {
colorSpace = CGColorSpaceCreateDeviceGray();
}
else {
colorSpace = CGColorSpaceCreateDeviceRGB();
cvCvtColor(image, image, CV_BGR2RGB);
}

NSData *data = [NSData dataWithBytes:image->imageData length:image->imageSize];
CGDataProviderRef provider = CGDataProviderCreateWithCFData((CFDataRef)data);
CGImageRef imageRef = CGImageCreate(image->width,
image->height,
image->depth,
image->depth * image->nChannels,
image->widthStep,
colorSpace,
kCGImageAlphaNone|kCGBitmapByteOrderDefault,
provider,
NULL,
false,
kCGRenderingIntentDefault
);
UIImage *ret = [UIImage imageWithCGImage:imageRef];

CGImageRelease(imageRef);
CGDataProviderRelease(provider);
CGColorSpaceRelease(colorSpace);

data=nil;
return ret;
}

Code For UIImage to IPL image

  • (IplImage_)IplImageFromUIImage:(UIImage_)image {

CGImageRef imageRef = image.CGImage;
CGColorSpaceRef colorSpace = CGColorSpaceCreateDeviceRGB();
IplImage *iplimage = cvCreateImage(cvSize(image.size.width,image.size.height), IPL_DEPTH_8U, 4 );

CGContextRef contextRef = CGBitmapContextCreate(
iplimage->imageData,
iplimage->width,
iplimage->height,
iplimage->depth,
iplimage->widthStep,
colorSpace,
kCGImageAlphaPremultipliedLast|kCGBitmapByteOrderDefault
);

CGContextDrawImage(contextRef,CGRectMake(0, 0, image.size.width, image.size.height),imageRef);

CGContextRelease(contextRef);
CGColorSpaceRelease(colorSpace);

retImage = cvCreateImage(cvGetSize(iplimage), IPL_DEPTH_8U, 3);
cvCvtColor(iplimage, retImage, CV_RGBA2BGR);
cvReleaseImage(&iplimage);
iplimage =nil;
return retImage;
}

screen shot 2014-12-29 at 1 49 38 pm

Lexical or preprocessor error

Hi,
Please some one help on the below issue to solve
I am getting lexical or preprocessor error string not found in SampleOptions.h file,

if i set the Build settings->compiler source as -> Objective C

if i set the if i set the Build settings->compiler source as -> According to file type, then i am getting

Semantic Issue : VideoTracking.hpp:53:9: No type named 'BFMatcher' in namespace 'cv'
lexical or preprocessor error: CameraCalibrationAlgorithm.h:5:10: 'array' file not found
Semantic Issue : FeatureDetectionSample.h:41:17: No member named 'AKAZE' in namespace 'cv'

Opencv header file symbolic links don't resolve in xcode

When cloning your great project, it took me quite some time to figure out why it wouldn't compile. You'll get the warning: I get the error "opencv2/opencv.hpp" not found
I realized that the opencv version that is included in the git repository is broken since the header files are no longer reachable.
Ik made a post on stackoverflow about this issue:

http://stackoverflow.com/questions/34429936/opencv2-opencv-hpp-file-not-found-in-xcode/37187743#37187743

Regards,

Rudie

Video in iOS 8.4, Xcode 7.0.1 & opencv-3.0.0

Thanks for the tutorial. It should help with a important project I'm on. I've run into some issues with tutorial, though.

The demos on images work ok, but I don't think video is working.

  • It appears that none of the video examples work. For example, In the Object tracking demo nothing is tracked after I tap the captureReferenceFrame button.
  • The app crashes in VideoViewContoller.mm in
- (IBAction)toggleCameraPressed:(id)sender
{
    [self.videoSource switchCameras];
}

There's also layout issues in the storyboards and depreciation errors, but I can fix those.

Thanks for you time.

Interface Issues

The options table view is too low on the page on the iPhone
simulator screen shot oct 8 2015 9 37 39 am
simulator screen shot oct 8 2015 9 39 22 am

.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.