Ask Your Question

Ashiq KS's profile - activity

2017-09-30 04:14:20 -0500 commented question Hi I want to open camera in windows forms in cpp.

Dear Berak, I could open camera on windows form now. Thanks for your response.

2017-09-23 04:15:44 -0500 commented question Hi I want to open camera in windows forms in cpp.

Actually i have an application for reading characters from license plate by loading images from file by clicking a load

2017-09-23 03:55:53 -0500 edited question Hi I want to open camera in windows forms in cpp.

Hi I want to open camera in windows forms in cpp. I have an application to load images from files for processing, but I

2017-09-23 03:52:11 -0500 asked a question Hi I want to open camera in windows forms in cpp.

Hi I want to open camera in windows forms in cpp. I have an application to load images from files for processing, but I

2017-03-25 10:32:03 -0500 received badge  Supporter (source)
2017-03-25 07:26:38 -0500 asked a question hi, i have to draw contour over a rectangle shape, but its drawiing contours over other small features.here i put the code

since i have only one karma i cannot upload images the video is played on a white background with most of its area covered by the rectangle shape thing pls help me with a solution

include<opencv2 opencv.hpp="">

include "opencv2/highgui/highgui.hpp"

include "opencv2/imgproc/imgproc.hpp"

include <iostream>

include <stdio.h>

include <stdlib.h>

include <math.h>

using namespace cv; using namespace std;

Mat imgOriginal; int largest_area = 0; int largest_contour_index = 0; Rect bounding_rect;

int theObject[2] = { 0,0 };

Rect bounding_rect = Rect(0, 0, 0, 0);

void searchForMovement(Mat thresholdImage, Mat &cameraFeed) { bool objDetected = false; Mat temp; thresholdImage.copyTo(temp);

vector<vector<Point>>contours;
vector<Vec4i>hierarchy;
findContours(temp, contours, hierarchy, CV_RETR_EXTERNAL, CV_CHAIN_APPROX_SIMPLE);
printf("%ld\n", contours.size());
if (contours.size() > 0) objDetected = true;
else objDetected = false;
if (objDetected)
{



    for (size_t i = 0; i< contours.size(); i++) // iterate through each contour.
    {
        double area = contourArea(contours[i]);  //  Find the area of contour

        if (area > largest_area)
        {
            largest_area = area;
            largest_contour_index = i;               //Store the index of largest contour
            bounding_rect = boundingRect(contours[i]); // Find the bounding rectangle for biggest contour
        }
    }

}

Scalar color = Scalar(0, 0, 255);
drawContours(imgOriginal, contours, -1, color);

Mat roi = Mat(imgOriginal, bounding_rect);

// show the images
imshow("result", imgOriginal);
imshow("roi", roi);
Size size(411, 405);
Mat dst;
resize(roi, dst, size);
imwrite("result.png", dst);
//Mat q, w;
Mat e = imread("result0.png");

namedWindow("X", WINDOW_AUTOSIZE);
imshow("X", e);

cv::Mat Q(dst.size(), dst.type());
cv::threshold(dst, Q, 100, 255, cv::THRESH_BINARY);


cv::Mat W(e.size(), e.type());
cv::threshold(e, W, 100, 255, cv::THRESH_BINARY);


Mat Solar = Q - W;
int count_black = 0;
int count_white = 0;
for (int y = 0; y < Solar.rows; y++) {
    for (int x = 0; x < Solar.cols; x++) {
        if (Solar.at<cv::Vec3b>(y, x) == cv::Vec3b(255, 255, 255)) {
            count_white++;
        }
        else if (Solar.at<cv::Vec3b>(y, x) == cv::Vec3b(0, 0, 0)) {
            count_black++;
        }
    }
}
cout << count_black << endl;
cout << count_white << endl;
//long float g = 0;
//g = count_black / count_white;
//cout << g;


int x = theObject[0];
int y = theObject[1];
circle(cameraFeed, Point(x, y), 20, Scalar(0, 255, 0), 2);
line(cameraFeed, Point(x, y), Point(x, y - 25), Scalar(0, 255, 0), 2);
line(cameraFeed, Point(x, y), Point(x, y + 25), Scalar(0, 255, 0), 2);
line(cameraFeed, Point(x, y), Point(x - 25, y), Scalar(0, 255, 0), 2);
line(cameraFeed, Point(x, y), Point(x + 25, y), Scalar(0, 255, 0), 2);

}

int main(int argc, char** argv) { VideoCapture cap(0); if (!cap.isOpened()) { cout << "Cannot open camera" << endl; return -1; } namedWindow("Control", WINDOW_AUTOSIZE);

while (true)
{
    bool bSuccess = cap.read(imgOriginal);
    if (!bSuccess)
    {
        cout << "Cannot read frame from video" << endl;
        break;
    }
    Mat image, imgThreshold;
    cvtColor(imgOriginal, image, CV_BGR2GRAY);
    threshold(image, imgThreshold, 150, 255, THRESH_BINARY_INV);


    searchForMovement(imgThreshold, imgOriginal);
    imshow("Thresholded Image", imgThreshold);
    imshow("Original", imgOriginal);
    if (waitKey(30) == 27)
    {
        cout << "Esc key pressed" << endl;
        break;
    }
}
return 0;

}

2017-03-24 10:58:15 -0500 asked a question Hi i want to pass information to arduino.Which additional libraries should be included?

i have a sample code .here i put the headers used

include "opencv2/objdetect/objdetect.hpp"

include "opencv2/highgui/highgui.hpp"

include "opencv2/imgproc/imgproc.hpp"

include <iostream>

include "Tserial.h"

the header #include "Tserial.h" showing error .what should i do

2017-03-23 09:08:53 -0500 commented question The cropped roi image is just tilted.I wanted it to be tilted to correct rectangular axes.What method should be used to do.Pls help me with a solution

Yes I want it to be rotated

2017-03-23 00:53:42 -0500 asked a question Hi,i want to give an output from opencv using visual studio to arduino.How can it be done?

Output from opencv is needed as output to arduino to make an external hardware work

2017-03-23 00:46:12 -0500 asked a question The cropped roi image is just tilted.I wanted it to be tilted to correct rectangular axes.What method should be used to do.Pls help me with a solution

image description

2017-03-22 11:55:52 -0500 commented answer Contour fn is not working well and not getting subpixel image by warpaffine fn

how to give loop around rotated rect

2017-03-22 11:38:01 -0500 commented answer Contour fn is not working well and not getting subpixel image by warpaffine fn

I changed the THRESH_BINARY in threshold fn to THRESH_BINARY_INV, but it showing some command error.Here i put the code to find contour with the change and the command window error. OpenCV Error:Assertion failed < scn==3||scn==4> in cv::cvtColor, file C:\build\master_winpack-build-win64-vc14\opencv\modules\imgproc\src\color.cpp,line 9748

2017-03-22 10:31:58 -0500 commented answer Contour fn is not working well and not getting subpixel image by warpaffine fn

Ok . let me try this.i will let you know the result.What about cropping? Moreover i use single channel image,but there is a fn Mat drawing = Mat::zeros(threshold_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_poly, i, color, 1, 8, vector<vec4i>(), 0, Point()); rectangle(drawing, boundRect[i].tl(), boundRect[i].br(), color, 2, 8, 0); //circle(drawing, center[i], (int)radius[i], color, 2, 8, 0); } will it cause a problem?

2017-03-22 07:28:34 -0500 commented question Contour fn is not working well and not getting subpixel image by warpaffine fn

i have only one karma point.The image is only a small rectangle shaped thing over white background,where the window is full of image

2017-03-22 06:26:06 -0500 asked a question Contour fn is not working well and not getting subpixel image by warpaffine fn

There are no errors while compiling here in the image i need to draw a contour over only a rectangular subpixel image but contours are drawn all over the image and rectangle,moreover subpixel image is not cropped.pls help me with a soln

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( " Threshold:", "Source", &thresh, max_thresh, thresh_callback );
  thresh_callback( 0, 0 );
// rect is the RotatedRect (I got it from a contour...)
        RotatedRect rect;
        // matrices we'll use
        Mat M, rotated, cropped;
        // get angle and size from the bounding box
        float angle = rect.angle;
        Size rect_size = rect.size;
        if (rect.angle < -45.) {
            angle += 90.0;
            swap(rect_size.width, rect_size.height);
        }
        // get the rotation matrix
        M = getRotationMatrix2D(rect.center, angle, 1.0);
        // perform the affine transformation
        warpAffine(src, rotated, M, src.size(), INTER_CUBIC);
        // crop the resulting image
        getRectSubPix(rotated, rect_size, rect.center, cropped);
  waitKey(0);
  return(0);
}

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

  /// Detect edges using Threshold
  threshold( src_gray, threshold_output, thresh, 255, THRESH_BINARY );
  /// Find contours
  findContours( threshold_output, contours, hierarchy, CV_RETR_TREE, CV_CHAIN_APPROX_SIMPLE, 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() );

  for( int i = 0; i < contours.size(); i++ )
     { approxPolyDP( Mat(contours[i]), contours_poly[i], 3, true );
       boundRect[i] = boundingRect( Mat(contours_poly[i]) );
       minEnclosingCircle( (Mat)contours_poly[i], center[i], radius[i] );
     }


  /// Draw polygonal contour + bonding rects + circles
  Mat drawing = Mat::zeros( threshold_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_poly, i, color, 1, 8, vector<Vec4i>(), 0, Point() );
       rectangle( drawing, boundRect[i].tl(), boundRect[i].br(), color, 2, 8, 0 );
       circle( drawing, center[i], (int)radius[i], color, 2, 8, 0 );
     }

  /// Show in a window
  namedWindow( "Contours", CV_WINDOW_AUTOSIZE );
  imshow( "Contours", drawing );
}
2017-03-21 08:27:11 -0500 commented question The program to count number of white and black pixels in a binary image is not working.Here I paste the code i used.Please help me with a solution.

cv::Mat Q(q.size(), q.type()); cv::threshold(q, Q, 100, 255, cv::THRESH_BINARY);

2017-03-21 03:42:23 -0500 commented question The program to count number of white and black pixels in a binary image is not working.Here I paste the code i used.Please help me with a solution.

Sorry i did not get you

2017-03-21 03:05:19 -0500 asked a question The program to count number of white and black pixels in a binary image is not working.Here I paste the code i used.Please help me with a solution.
int count_white=0;
int count_black=0;

 for (int y = 0; y < image.rows; y++) {
            for (int x = 0; x < image.cols; x++) {
                if (image.at<cv::Vec3b>(y, x) == cv::Vec3b(255, 255, 255)) {
                    count_white++;
                }
                else if (image.at<cv::Vec3b>(y, x) == cv::Vec3b(0, 0, 0)) {
                    count_black++;
                }
            }
        }
2017-03-15 12:57:31 -0500 asked a question I have the codes for live video and finding contours separately.I would like to know how both the codes can be stitched together to find contours in a live video

CODE FOR LIVE VIDEO

#include<opencv2/opencv.hpp>
#include<iostream>


using namespace cv;

using namespace std;

int main()
    {
    Mat CameraFrame;
    Mat Grey;

    VideoCapture cap;
    char keypressed;

    //Opens the first imaging device.
    cap.open(0);

    //Check whether user selected camera is opened successfully.
    if( !cap.isOpened() )
    {
    cout << "***Could not initialize capturing...***\n";
   return -1;
   }

   //Create a windows to display camera preview.
   namedWindow("Camera Preview", CV_WINDOW_AUTOSIZE);

   //Loop infinitely to fetch frame from camera and display it.
   for(;;)
   {
   //Fetch frame from camera.
   cap >> CameraFrame;

   //Check whether received frame has valid pointer.
   if( CameraFrame.empty() )
   break;

   //Display the received frame
   imshow("Camera Preview", CameraFrame);

   //Wait for Escape keyevent to exit from loop
   keypressed = (char)waitKey(10);
   if( keypressed == 27 )
   break;
   }

   //Release the camera interface.
   cap.release();

   return 0;
   }

CODE FOR FINDING 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( " Threshold:", "Source", &thresh, max_thresh, thresh_callback );
      thresh_callback( 0, 0 );

      waitKey(0);
      return(0);
    }

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

      /// Detect edges using Threshold
      threshold( src_gray, threshold_output, thresh, 255, THRESH_BINARY );
      /// Find contours
      findContours( threshold_output, contours, hierarchy, CV_RETR_TREE, CV_CHAIN_APPROX_SIMPLE, 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() );

      for( int i = 0; i < contours.size(); i++ )
         { approxPolyDP( Mat(contours[i]), contours_poly[i], 3, true );
           boundRect[i] = boundingRect( Mat(contours_poly[i]) );
           minEnclosingCircle( (Mat)contours_poly[i], center[i], radius[i] );
         }


      /// Draw polygonal contour + bonding rects + circles
      Mat drawing = Mat::zeros( threshold_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_poly, i, color, 1, 8, vector<Vec4i>(), 0, Point() );
           rectangle( drawing, boundRect[i].tl(), boundRect[i].br(), color, 2, 8, 0 );
           circle( drawing, center[i], (int)radius[i], color, 2, 8, 0 );
         }

      /// Show in a window
      namedWindow( "Contours", CV_WINDOW_AUTOSIZE );
      imshow( "Contours", drawing );
    }
2017-03-15 11:45:37 -0500 asked a question I was able to open ids camera the code in visual studio 2012 with opencv 2.4.13,but now it can't open in visual studio 2015 opencv 3.2.0,c++.pls help me with a solution
#include<opencv2/opencv.hpp>
#include<iostream>


using namespace cv;

using namespace std;

int main()
    {
    Mat CameraFrame;
    Mat Grey;

    VideoCapture cap;
    char keypressed;

    //Opens the first imaging device.
    cap.open(0);

    //Check whether user selected camera is opened successfully.
    if( !cap.isOpened() )
    {
    cout << "***Could not initialize capturing...***\n";
   return -1;
   }

   //Create a windows to display camera preview.
   namedWindow("Camera Preview", CV_WINDOW_AUTOSIZE);

   //Loop infinitely to fetch frame from camera and display it.
   for(;;)
   {
   //Fetch frame from camera.
   cap >> CameraFrame;

   //Check whether received frame has valid pointer.
   if( CameraFrame.empty() )
   break;

   //Display the received frame
   imshow("Camera Preview", CameraFrame);

   //Wait for Escape keyevent to exit from loop
   keypressed = (char)waitKey(10);
   if( keypressed == 27 )
   break;
   }

   //Release the camera interface.
   cap.release();
2017-03-11 12:21:55 -0500 received badge  Enthusiast
2017-03-10 10:06:47 -0500 commented question Hi, my project is to detect defects in solar panels running through a conveyor belt in a real time basis .Pls help me with a method to track down the solar panels and an optimum method to find the defects.

Surface defects such as cracks just for demo purpose in college project. It's to compare good one with faulty ones.

2017-03-10 05:10:57 -0500 commented question Hi, my project is to detect defects in solar panels running through a conveyor belt in a real time basis .Pls help me with a method to track down the solar panels and an optimum method to find the defects.

Sorry.I just asked for the steps to do in the opencv way.That's all.

2017-03-09 08:01:02 -0500 asked a question Hi, my project is to detect defects in solar panels running through a conveyor belt in a real time basis .Pls help me with a method to track down the solar panels and an optimum method to find the defects.

The project is to inspect solar panels ,passing through a conveyor belt,to find surface defects.The problem now I face is the alignment of solar panel in the live video,moreover,the method to find the defects.I use opencv3.2 in visual studio 2015 c++.Now I have the code for the live video.

2017-03-06 22:16:23 -0500 asked a question i'm doing a project where i need software triggering for the camera to capture image in every 2 seconds only for entire program.

My project is to detect defects in a solar panel,where solar panels are passed through a conveyor belt on a real time basis.When defective solar panels are found they are rejected . As my camera takes more than 20 frames a second, I don't need that.Instead I need my program to work in the way to capture one single frame at every 2 seconds only.I use opencv3.2 c++ .Here I cite the basic program for a live video .Pls help me with a solution. I use ids usb3.0 camera.

#include<opencv2/opencv.hpp>
#include<iostream>
using namespace cv;
using namespace std;
int main()
    {
    Mat CameraFrame;
    Mat Grey;
 VideoCapture cap;
    char keypressed;
  //Opens the first imaging device.
    cap.open(0);
  //Check whether user selected camera is opened successfully.
    if( !cap.isOpened() )
    {
    cout << "***Could not initialize capturing...***\n";
   return -1;
   }
 //Create a windows to display camera preview.
   namedWindow("Camera Preview", CV_WINDOW_AUTOSIZE);
   //Loop infinitely to fetch frame from camera and display it.
   for(;;)
   {
   //Fetch frame from camera.
   cap >> CameraFrame;
  //Check whether received frame has valid pointer.
   if( CameraFrame.empty() )
   break;
  //Display the received frame
   imshow("Camera Preview", CameraFrame);
 //Wait for Escape keyevent to exit from loop
   keypressed = (char)waitKey(10);
   if( keypressed == 27 )
   break;
   }
 //Release the camera interface.
   cap.release();
 return 0;
   }
2017-02-01 03:43:53 -0500 commented question My USB3.0 IDS camera cannot opened with opencv2.4.12.Please help me with a solution.

This is the code i used to open USB3.0 IDS camera in opencv.

#include<opencv2/opencv.hpp>
#include<iostream>
using namespace cv;
using namespace std;
int main()
    {
    Mat CameraFrame;
    Mat Grey;
    VideoCapture cap;
    char keypressed;
    cap.open(0);
    if( !cap.isOpened() )
    {cout << "***Could not initialize capturing...***\n";
   return -1;}
   namedWindow("Camera Preview", CV_WINDOW_AUTOSIZE);
   for(;;)
   {cap >> CameraFrame;
   if( CameraFrame.empty() )
   break;
   imshow("Camera Preview", CameraFrame);
   keypressed = (char)waitKey(10);
   if( keypressed == 27 )
   break;}
   cap.release();
  return 0;}
2017-02-01 03:30:09 -0500 commented question My USB3.0 IDS cannot opened with opencv2.4.12.Please help me with a solution.

Thanks buddy.your solution helped me to solve the problem.Thanks again

2017-02-01 03:27:13 -0500 commented question My USB3.0 IDS camera cannot opened with opencv2.4.12.Please help me with a solution.

feel pleasure to be commented.thanks for coming.just now the problem was solved.Thank U again

2017-02-01 02:36:16 -0500 asked a question My USB3.0 IDS camera cannot opened with opencv2.4.12.Please help me with a solution.

The camera is not opening while c++ program code for video read is executed.I am in the middle of a college project,please help me with a solution

2017-01-21 04:56:57 -0500 asked a question My USB3.0 IDS cannot opened with opencv2.4.12.Please help me with a solution.

I am using opencv2.4.12 for my college project. I am a new user to opencv and programs. The camera is USB3.0 uEye GigE vision camera. Please help me with a solution.