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.
- Capturing image from camera source
- Converting into a HSV image and applying InRange function.
- Applying a threshold on image.
- 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 :
Please share your input image ,current output and desired output! Please try to make a complete code.
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
"current output and desired output" Please update these images also.