Open pradeep-chauhan opened 6 years ago
I want to detect led blinking on high frequency. here is my code:
int SENSITIVITY_VALUE = 63; int BLUR_SIZE = 3;; vector imageArray;
// Get masking
// Detect motion
(BOOL)detectMotion:(Mat &)thresholdImage { Mat temp; bool motionDetected = false; thresholdImage.copyTo(temp); vector<vector > contours; vector hierarchy; findContours(temp, contours, hierarchy, CV_RETR_EXTERNAL, CV_CHAIN_APPROX_SIMPLE, cv::Point(0, 0)); if (contours.size() > 0) { motionDetected = true; } return motionDetected; }
(BOOL)frameDiff:(Mat &)frame1 andFrmae2:(Mat &)frame2 { Mat grayImage1, grayImage2, differenceImage, threshImage; cvtColor(frame1, grayImage1, CV_BGR2GRAY); cvtColor(frame2, grayImage2, CV_BGR2GRAY); absdiff(grayImage1, grayImage2, differenceImage); threshold(differenceImage, threshImage, SENSITIVITY_VALUE, 255, CV_THRESH_BINARY); blur(threshImage, threshImage, cv::Size( BLUR_SIZE, BLUR_SIZE )); threshold(threshImage, threshImage, SENSITIVITY_VALUE, 255, CV_THRESH_BINARY); return [self detectMotion:threshImage]; }
Input image something like this:-
I give an answer
My method is not good with your image because image is saturated (led roi pixel values are 255).
I want to detect led blinking on high frequency. here is my code:
int SENSITIVITY_VALUE = 63; int BLUR_SIZE = 3;; vector imageArray;
imageArray.push_back(image); if (imageArray.size() == 30) { for (int i = 0; i < imageArray.size(); i++) { if (i > 0) { Mat frame1, frame2; frame1 = [self masking:imageArray[i]]; frame2 = [self masking:imageArray[i-1]]; int binaryValue = 0; if ([self frameDiff:frame1 andFrmae2:frame2]) { binaryValue = 1; } cout<< "binary value :" << binaryValue <<endl; } } imageArray.clear(); } }
// Get masking
// Detect motion
(BOOL)detectMotion:(Mat &)thresholdImage { Mat temp; bool motionDetected = false; thresholdImage.copyTo(temp); vector<vector > contours;
vector hierarchy;
findContours(temp, contours, hierarchy, CV_RETR_EXTERNAL, CV_CHAIN_APPROX_SIMPLE, cv::Point(0, 0));
if (contours.size() > 0) {
motionDetected = true;
}
return motionDetected;
}
(BOOL)frameDiff:(Mat &)frame1 andFrmae2:(Mat &)frame2 { Mat grayImage1, grayImage2, differenceImage, threshImage; cvtColor(frame1, grayImage1, CV_BGR2GRAY); cvtColor(frame2, grayImage2, CV_BGR2GRAY); absdiff(grayImage1, grayImage2, differenceImage); threshold(differenceImage, threshImage, SENSITIVITY_VALUE, 255, CV_THRESH_BINARY); blur(threshImage, threshImage, cv::Size( BLUR_SIZE, BLUR_SIZE )); threshold(threshImage, threshImage, SENSITIVITY_VALUE, 255, CV_THRESH_BINARY); return [self detectMotion:threshImage]; }
Input image something like this:-