Ask Your Question

tesh94's profile - activity

2020-09-16 15:05:35 -0600 received badge  Student (source)
2019-12-17 01:26:21 -0600 received badge  Notable Question (source)
2018-12-21 06:23:06 -0600 received badge  Popular Question (source)
2017-04-10 20:02:46 -0600 received badge  Scholar (source)
2017-04-10 19:58:34 -0600 commented answer How to crop the rectangle part of the image?

Ok thanks. I've managed to do it.

2017-04-10 19:57:30 -0600 received badge  Supporter (source)
2017-04-09 23:20:02 -0600 asked a question How to crop the rectangle part of the image?

I have this image and I've used the code from the tutorial to find the contours.

#include "opencv2/highgui/highgui.hpp"
#include "opencv2/imgproc/imgproc.hpp"
#include <iostream>
#include <stdio.h>
#include <stdlib.h>

using namespace cv;
using namespace std;

Mat src; Mat src_gray;
int thresh = 100;
int max_thresh = 255;
RNG rng(12345);

/// Function header
void thresh_callback(int, void* );

/** @function main */
int main( int argc, char** argv )
{
  /// Load source image and convert it to gray
  src = imread( argv[1], 1 );

  /// Convert image to gray and blur it
  cvtColor( src, src_gray, CV_BGR2GRAY );
  blur( src_gray, src_gray, Size(3,3) );

  /// Create Window
  char* source_window = "Source";
  namedWindow( source_window, CV_WINDOW_AUTOSIZE );
  imshow( source_window, src );

  createTrackbar( " Canny thresh:", "Source", &thresh, max_thresh, thresh_callback );
  thresh_callback( 0, 0 );

  waitKey(0);
  return(0);
}

/** @function thresh_callback */
void thresh_callback(int, void* )
{
  Mat canny_output;
  vector<vector<Point> > contours;
  vector<Vec4i> hierarchy;

  /// Detect edges using canny
  Canny( src_gray, canny_output, thresh, thresh*2, 3 );
  /// Find contours
  findContours( canny_output, contours, hierarchy, CV_RETR_TREE, CV_CHAIN_APPROX_SIMPLE, Point(0, 0) );

  /// Draw contours
  Mat drawing = Mat::zeros( canny_output.size(), CV_8UC3 );
  for( int i = 0; i< contours.size(); i++ )
     {
       Scalar color = Scalar( rng.uniform(0, 255), rng.uniform(0,255), rng.uniform(0,255) );
       drawContours( drawing, contours, i, color, 2, 8, hierarchy, 0, Point() );
     }

  /// Show in a window
  namedWindow( "Contours", CV_WINDOW_AUTOSIZE );
  imshow( "Contours", drawing );
}

How do i then go on about to crop the rectangle part of the image?

2017-04-07 02:55:30 -0600 commented answer OpenCV setroi

yeap the size of the image was too small.

the image that was able to load had a larger size. i've sorted it out.

thanks

2017-04-06 21:31:13 -0600 asked a question OpenCV setroi

Hello to whomever is reading this. I'm new to opencv and I've only recently installed opencv.

I would like to ask as to how do I go on about in setting the ROI of an image. An example is I have an image of an electric meter and I would just like to get the ROI of the values part of the electric meter. Not the entire electric meter. I would love to post some image as example but I'm lacking in karma as I'm a new user. Sorry about that

I've used this code over here

#include "opencv2/core/core.hpp"
#include "opencv2/highgui/highgui.hpp"
using namespace cv;

int main() 
{
    namedWindow("Example1");
    Mat img = imread("D:/sample.jpg");
    if ( img.empty() ) { /* bark!!*/ }
    Mat roi = img( Rect(170,150,250,100));
    imshow("Example1",roi);
    waitKey(0);
    return 0; // yea, c++, no cleanup nessecary!
}

I've not set the proper rect for the ROI but for some reason I'm always getting an error even before I can test it out. The error has something to do with the + &ThisException 0x0000004532f7f6d0 {ExceptionCode=3765269347 ExceptionFlags=1 ExceptionRecord=0x0000000000000000 {ExceptionCode=...} ...} EHExceptionRecord *

When I use a different image, it isn't an issue.

Bear in mind I'm new to opencv so if the question does sound pretty noobish, sorry.