Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

How to detect led is blinking or not at multiple frequency?

I'm using iPhone camera to capture whether led is no or off at 25khz frequency. My camera fps is 30 frames per seconds. So my led is blinking on 25khz but human eye cannot see that. i want to capture led blinking.

This things i'm doing right now.

  1. Capturing image from camera source
  2. Converting into a HSV image and applying InRange function.
  3. Applying a threshold on image.
  4. finding contours

This my complete code :

Mat hsv_image, mask, temp, gray_image, grayImage, res;

cvtColor(img, hsv_image, CV_BGR2HSV);
inRange(hsv_image, Scalar(110,50,50), Scalar(130,255,255), mask);
bitwise_and(img, img, res, mask= mask);

cv::Mat erodeElement = getStructuringElement( cv::MORPH_ERODE,    cvSize(4,4));
//dilate with larger element so make sure object is nicely visible
cv::Mat dilateElement = getStructuringElement(  cv::MORPH_DILATE,cvSize(4,4));
erode(res,res,erodeElement);
erode(res,res,erodeElement);
dilate(res,res,dilateElement);
dilate(res,res,dilateElement);

// Mat element = getStructuringElement(MORPH_GRADIENT, cv::Size(3, 3), cv::Point(4,4) ); // morphologyEx(res, res, CV_MOP_CLOSE, element);

cvtColor(res, grayImage, CV_BGR2GRAY);
Mat blur_image;

// GaussianBlur(grayImage, blur_image, cv::Size( 5, 5 ),0);

threshold(grayImage, grayImage, SENSITIVITY_VALUE, 255, CV_THRESH_BINARY+CV_THRESH_OTSU);
blur(grayImage, blur_image, cv::Size( BLUR_SIZE, BLUR_SIZE ));
threshold(blur_image, blur_image, SENSITIVITY_VALUE, 255, CV_THRESH_BINARY+CV_THRESH_OTSU);
blur_image.copyTo(temp);
vector<vector<cv::Point> > contours;
vector<Vec4i> hierarchy;
findContours(temp, contours, hierarchy, CV_RETR_EXTERNAL, CV_CHAIN_APPROX_NONE, cv::Point(0, 0));
size_t largestContour = 0;

Mat drawing = Mat::zeros( temp.size(), CV_8UC3 );
double area = 0.0, length = 0.0;
Point2f center;
float radius;
for( size_t i = 0; i< contours.size(); i++ )
{
    if (cv::contourArea(contours[i]) > cv::contourArea(contours[largestContour]))
        largestContour = i;
}
if ((contours.size() == 0 || contours.size() > 0) && is_light_on == true) {

    if (contours.size() > 0) {
        cout << 1 << endl;
    } else {
        cout << 0 << endl;
    }
    cout<<"*****************"<<endl;
} else if (contours.size() > 0) {
    is_light_on = true;
}

How to detect led is blinking or not at multiple frequency?

I'm using iPhone camera to capture whether led is no or off at 25khz frequency. My camera fps is 30 frames per seconds. So my led is blinking on 25khz but human eye cannot see that. i want to capture led blinking.

This things i'm doing right now.

  1. Capturing image from camera source
  2. Converting into a HSV image and applying InRange function.
  3. Applying a threshold on image.
  4. finding contours

This my complete code :

Mat hsv_image, mask, temp, gray_image, grayImage, res;

cvtColor(img, hsv_image, CV_BGR2HSV);
inRange(hsv_image, Scalar(110,50,50), Scalar(130,255,255), mask);
bitwise_and(img, img, res, mask= mask);

cv::Mat erodeElement = getStructuringElement( cv::MORPH_ERODE,    cvSize(4,4));
//dilate with larger element so make sure object is nicely visible
cv::Mat dilateElement = getStructuringElement(  cv::MORPH_DILATE,cvSize(4,4));
erode(res,res,erodeElement);
erode(res,res,erodeElement);
dilate(res,res,dilateElement);
dilate(res,res,dilateElement);

// Mat element = getStructuringElement(MORPH_GRADIENT, cv::Size(3, 3), cv::Point(4,4) ); // morphologyEx(res, res, CV_MOP_CLOSE, element);

cvtColor(res, grayImage, CV_BGR2GRAY);
Mat blur_image;

// GaussianBlur(grayImage, blur_image, cv::Size( 5, 5 ),0);

threshold(grayImage, grayImage, SENSITIVITY_VALUE, 255, CV_THRESH_BINARY+CV_THRESH_OTSU);
blur(grayImage, blur_image, cv::Size( BLUR_SIZE, BLUR_SIZE ));
threshold(blur_image, blur_image, SENSITIVITY_VALUE, 255, CV_THRESH_BINARY+CV_THRESH_OTSU);
blur_image.copyTo(temp);
vector<vector<cv::Point> > contours;
vector<Vec4i> hierarchy;
findContours(temp, contours, hierarchy, CV_RETR_EXTERNAL, CV_CHAIN_APPROX_NONE, cv::Point(0, 0));
size_t largestContour = 0;

Mat drawing = Mat::zeros( temp.size(), CV_8UC3 );
double area = 0.0, length = 0.0;
Point2f center;
float radius;
for( size_t i = 0; i< contours.size(); i++ )
{
    if (cv::contourArea(contours[i]) > cv::contourArea(contours[largestContour]))
        largestContour = i;
}
if ((contours.size() == 0 || contours.size() > 0) && is_light_on == true) {

    if (contours.size() > 0) {
        cout << 1 << endl;
    } else {
        cout << 0 << endl;
    }
    cout<<"*****************"<<endl;
} else if (contours.size() > 0) {
    is_light_on = true;
}

Input :

C:\fakepath\Screen Shot 2018-05-02 at 6.19.42 PM.png

How to detect led is blinking or not at multiple frequency?

I'm using iPhone camera to capture whether led is no or off at 25khz frequency. My camera fps is 30 frames per seconds. So my led is blinking on 25khz but human eye cannot see that. i want to capture led blinking.

This things i'm doing right now.

  1. Capturing image from camera source
  2. Converting into a HSV image and applying InRange function.
  3. Applying a threshold on image.
  4. finding contours

This my complete code :

- (Mat)fetchDataFromImage {
Mat hsv_image, mask, temp, gray_image, grayImage, res;

cvtColor(img, hsv_image, CV_BGR2HSV);
inRange(hsv_image, Scalar(110,50,50), Scalar(130,255,255), mask);
bitwise_and(img, img, res, mask= mask);

cv::Mat erodeElement = getStructuringElement( cv::MORPH_ERODE,    cvSize(4,4));
//dilate with larger element so make sure object is nicely visible
cv::Mat dilateElement = getStructuringElement(  cv::MORPH_DILATE,cvSize(4,4));
erode(res,res,erodeElement);
erode(res,res,erodeElement);
dilate(res,res,dilateElement);
dilate(res,res,dilateElement);

// Mat element = getStructuringElement(MORPH_GRADIENT, cv::Size(3, 3), cv::Point(4,4) ); // morphologyEx(res, res, CV_MOP_CLOSE, element);

 cvtColor(res, grayImage, CV_BGR2GRAY);
Mat blur_image;

// GaussianBlur(grayImage, blur_image, cv::Size( 5, 5 ),0);

 threshold(grayImage, grayImage, SENSITIVITY_VALUE, 255, CV_THRESH_BINARY+CV_THRESH_OTSU);
blur(grayImage, blur_image, cv::Size( BLUR_SIZE, BLUR_SIZE ));
threshold(blur_image, blur_image, SENSITIVITY_VALUE, 255, CV_THRESH_BINARY+CV_THRESH_OTSU);
blur_image.copyTo(temp);
vector<vector<cv::Point> > contours;
vector<Vec4i> hierarchy;
findContours(temp, contours, hierarchy, CV_RETR_EXTERNAL, CV_CHAIN_APPROX_NONE, cv::Point(0, 0));
size_t largestContour = 0;

Mat drawing = Mat::zeros( temp.size(), CV_8UC3 );
double area = 0.0, length = 0.0;
Point2f center;
float radius;
for( size_t i = 0; i< contours.size(); i++ )
{
    if (cv::contourArea(contours[i]) > cv::contourArea(contours[largestContour]))
        largestContour = i;
}
if ((contours.size() == 0 || contours.size() > 0) && is_light_on == true) {

    if (contours.size() > 0) {
        cout << 1 << endl;
    } else {
        cout << 0 << endl;
    }
    cout<<"*****************"<<endl;
} else if (contours.size() > 0) {
    is_light_on = true;
}
}


- (void)processImage:(Mat&)image
{

   img = image;
   image = [self fetchDataFromImage];
}

Input :

C:\fakepath\Screen Shot 2018-05-02 at 6.19.42 PM.png