Ask Your Question
0

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

asked 2018-05-02 07:05:41 -0500

prabzz gravatar image

updated 2018-05-02 07:56:40 -0500

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));
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);

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

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

edit retag flag offensive close merge delete

Comments

Please share your input image ,current output and desired output! Please try to make a complete code.

Balaji R gravatar imageBalaji R ( 2018-05-02 07:41:28 -0500 )edit

have update the question with input image. So . what i exactly want led is blinking at higher frequency so human eye cannot see this and when led is off it will show some lighter image. based on that if image have full brightness then its on 25khz and its less then its on 120hz

prabzz gravatar imageprabzz ( 2018-05-02 07:59:30 -0500 )edit
1

"current output and desired output" Please update these images also.

Balaji R gravatar imageBalaji R ( 2018-05-02 08:02:53 -0500 )edit

1 answer

Sort by ยป oldest newest most voted
1

answered 2018-05-02 08:00:54 -0500

LBerger gravatar image

updated 2018-05-03 12:46:44 -0500

I remember an old post here http://answers.opencv.org/question/63... and this one too http://answers.opencv.org/question/65... and may be this code will solve your problem https://github.com/LaurentBerger/LedB...

I try to understand your question : you have got led blinking at frequency=24kHz : image description

A webcam (good one with a sensor regulated in temperature) grab a picture : it means light is accumulated for 1/1000s (1/1000 just an example) grey level is g(24000).

Now if frequency changed what happens to grey level :

image description

How to read this curve : frequency 24000Hz pixel level is 1 frequency 24500 Hz pixel level is 1.013 frequency 23554 Hz pixel level is 1.013

frequency range is given by shannon law 24000Hz +/- 250Hz

I integration time is changed you can get a new curve (0.0007s) you get a new curve :

image description

I say : Good luck it seems that it is possible

edit flag offensive delete link more

Comments

I tried that solution but didn't get result

prabzz gravatar imageprabzz ( 2018-05-02 08:05:29 -0500 )edit
1

@prabzz " didn't get result" is not a useful answer! Please explicitly specify your problem!

Balaji R gravatar imageBalaji R ( 2018-05-02 23:15:45 -0500 )edit

I want to get binary data from led lights. Led with be blinking based on binary data. for example: 10101010 this this pass to led so 1 means led on and 0 means led off. but it is running on higher frequency. So always getting same image with little bit changes in brightness and mask image.

prabzz gravatar imageprabzz ( 2018-05-03 00:28:57 -0500 )edit

@LBerger It seem good. Can you explain bit more how i can achieve this with opencv.

prabzz gravatar imageprabzz ( 2018-05-04 09:01:17 -0500 )edit

without any context it's difficult to improve my answer

LBerger gravatar imageLBerger ( 2018-05-04 09:46:53 -0500 )edit

Like the images you have shared it is on signal analyser. So my question is here how i can check frequency from led using image capture.

prabzz gravatar imageprabzz ( 2018-05-04 09:53:11 -0500 )edit

You need to understad second curve : if everything is perfect there is a relation between gray level and led frequency. You shoul make experience yourself :

   1   measure grey level ( no saturation in image) 
   2   change led  frequency 
   3  go to 1

you will be able to plot yourself curve 2 with real measurement. Becarefull variation is only 2% of grey level

LBerger gravatar imageLBerger ( 2018-05-04 10:02:08 -0500 )edit

You mean get frequency by using FFT/DFT.

prabzz gravatar imageprabzz ( 2018-05-07 06:47:57 -0500 )edit
Login/Signup to Answer

Question Tools

1 follower

Stats

Asked: 2018-05-02 07:05:41 -0500

Seen: 355 times

Last updated: May 03 '18