working with opencv2.4.9, vs2008 express and windows xp,between these any compatibility problem [closed]

asked 2014-09-30 02:35:51 -0600

govardhana padavala gravatar image

Hi guys,

From last fews im working on opencv. Initially i started with opencv 3.0.0, vs2008 express, and windowsxp so, while working with this i got exception at imwrite() and findcontours(). After some suggestion i went to opencv 2.4.9. Now my system opencv 2.4.9, vs2008 express and windowsxp then again im again getting exception but now at imread(),it is first function in my program so i decided this may any compatibility problem...!

mycode:

include <cxcore.h>

include <highgui.h>

include <string>

include <iostream>

include <cv.h>

include "opencv2/objdetect/objdetect.hpp"

include "opencv2/highgui/highgui.hpp"

include "opencv2/imgproc/imgproc.hpp"

include "opencv2/core/core.hpp"

include <iostream>

include <windows.h>

ifdef _CH_

pragma package <opencv>

endif

ifndef _EiC

include "cv.h"

include "highgui.h"

include "ml.h"

include <stdio.h>

include <stdlib.h>

include <ctype.h>

endif

using namespace std; using namespace cv;

int getContours() { cv::Mat img = cv::imread("equation.jpg", 0);//Here im getting exception

//Apply blur to smooth edges and use adapative thresholding cv::Size size(3,3); cv::GaussianBlur(img,img,size,0); adaptiveThreshold(img, img,255,CV_ADAPTIVE_THRESH_MEAN_C, CV_THRESH_BINARY,75,10); cv::bitwise_not(img, img);

cv::Mat img2 = img.clone();

std::vector<cv::point> points; cv::Mat_<uchar>::iterator it = img.begin<uchar>(); cv::Mat_<uchar>::iterator end = img.end<uchar>(); for (; it != end; ++it) if (*it) points.push_back(it.pos());

cv::RotatedRect box = cv::minAreaRect(cv::Mat(points));

double angle = box.angle; if (angle < -45.) angle += 90.;

cv::Point2f vertices[4]; box.points(vertices); for(int i = 0; i < 4; ++i) cv::line(img, vertices[i], vertices[(i + 1) % 4], cv::Scalar(255, 0, 0), 1, CV_AA);

cv::Mat rot_mat = cv::getRotationMatrix2D(box.center, angle, 1);

cv::Mat rotated; cv::warpAffine(img2, rotated, rot_mat, img.size(), cv::INTER_CUBIC);

cv::Size box_size = box.size; if (box.angle < -45.) std::swap(box_size.width, box_size.height); cv::Mat cropped;

cv::getRectSubPix(rotated, box_size, box.center, cropped); cv::imshow("Cropped", cropped); imwrite("example5.jpg",cropped);

    Mat cropped2=cropped.clone();

cvtColor(cropped2,cropped2,CV_GRAY2RGB);

Mat cropped3 = cropped.clone(); cvtColor(cropped3,cropped3,CV_GRAY2RGB);

vector<vector<point> > contours; vector<vec4i> hierarchy;

/// Find contours cv:: findContours( cropped, contours, hierarchy, CV_RETR_EXTERNAL, CV_CHAIN_APPROX_TC89_KCOS, Point(0, 0) );

/// Approximate contours to polygons + get bounding rects and circles vector<vector<point> > contours_poly( contours.size() ); vector<rect> boundRect( contours.size() ); vector<point2f>center( contours.size() ); vector<float>radius( contours.size() );

//Get poly contours for( int i = 0; i < contours.size(); i++ ) { approxPolyDP( Mat(contours[i]), contours_poly[i], 3, true ); }

//Get only important contours, merge contours that are within another vector<vector<point> > validContours; for (int i=0;i<contours_poly.size();i++){< p="">

            Rect r = boundingRect(Mat(contours_poly[i]));
            if(r.area()<100)continue;
            bool inside = false;
            for(int j=0;j<contours_poly.size();j++){
                    if(j==i)continue;

                    Rect r2 = boundingRect(Mat(contours_poly[j]));
                    if(r2.area()<100||r2.area()<r.area())continue;
                    if(r.x>r2.x&&r.x+r.width<r2.x+r2.width&&
                            r.y>r2.y&&r ...
(more)
edit retag flag offensive reopen merge delete

Closed for the following reason question is not relevant or outdated by sturkmen
close date 2020-10-04 06:58:48.502317

Comments

  • please, format your code above (edit, mark it, press 10101 button)
  • the exact exception message, please.
  • are you using prebuild libs for 2.4.9 ?
  • try with a much simpler example(your code above is quite a mess), just read an image & show it.
  • please use only the opencv2 headers, and throw anything else away.
berak gravatar imageberak ( 2014-09-30 02:48:04 -0600 )edit

Please close, duplicate.

boaz001 gravatar imageboaz001 ( 2014-09-30 02:54:59 -0600 )edit

this is not duplicate, try to understand again

govardhana padavala gravatar imagegovardhana padavala ( 2014-09-30 04:04:48 -0600 )edit