| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (c) 2011 The WebRTC project authors. All Rights Reserved. | 2 * Copyright (c) 2011 The WebRTC project authors. All Rights Reserved. |
| 3 * | 3 * |
| 4 * Use of this source code is governed by a BSD-style license | 4 * Use of this source code is governed by a BSD-style license |
| 5 * that can be found in the LICENSE file in the root of the source | 5 * that can be found in the LICENSE file in the root of the source |
| 6 * tree. An additional intellectual property rights grant can be found | 6 * tree. An additional intellectual property rights grant can be found |
| 7 * in the file PATENTS. All contributing project authors may | 7 * in the file PATENTS. All contributing project authors may |
| 8 * be found in the AUTHORS file in the root of the source tree. | 8 * be found in the AUTHORS file in the root of the source tree. |
| 9 */ | 9 */ |
| 10 | 10 |
| 11 #include "webrtc/modules/video_processing/include/video_processing.h" | |
| 12 #include "webrtc/modules/video_processing/brightness_detection.h" | 11 #include "webrtc/modules/video_processing/brightness_detection.h" |
| 13 | 12 |
| 14 #include <math.h> | 13 #include <math.h> |
| 15 | 14 |
| 15 #include "webrtc/modules/video_processing/include/video_processing.h" |
| 16 |
| 16 namespace webrtc { | 17 namespace webrtc { |
| 17 | 18 |
| 18 VPMBrightnessDetection::VPMBrightnessDetection() { | 19 VPMBrightnessDetection::VPMBrightnessDetection() { |
| 19 Reset(); | 20 Reset(); |
| 20 } | 21 } |
| 21 | 22 |
| 22 VPMBrightnessDetection::~VPMBrightnessDetection() {} | 23 VPMBrightnessDetection::~VPMBrightnessDetection() {} |
| 23 | 24 |
| 24 void VPMBrightnessDetection::Reset() { | 25 void VPMBrightnessDetection::Reset() { |
| 25 frame_cnt_bright_ = 0; | 26 frame_cnt_bright_ = 0; |
| 26 frame_cnt_dark_ = 0; | 27 frame_cnt_dark_ = 0; |
| 27 } | 28 } |
| 28 | 29 |
| 29 int32_t VPMBrightnessDetection::ProcessFrame( | 30 int32_t VPMBrightnessDetection::ProcessFrame( |
| 30 const VideoFrame& frame, | 31 const VideoFrame& frame, |
| 31 const VideoProcessingModule::FrameStats& stats) { | 32 const VideoProcessing::FrameStats& stats) { |
| 32 if (frame.IsZeroSize()) { | 33 if (frame.IsZeroSize()) { |
| 33 return VPM_PARAMETER_ERROR; | 34 return VPM_PARAMETER_ERROR; |
| 34 } | 35 } |
| 35 int width = frame.width(); | 36 int width = frame.width(); |
| 36 int height = frame.height(); | 37 int height = frame.height(); |
| 37 | 38 |
| 38 if (!VideoProcessingModule::ValidFrameStats(stats)) { | 39 if (!VideoProcessing::ValidFrameStats(stats)) { |
| 39 return VPM_PARAMETER_ERROR; | 40 return VPM_PARAMETER_ERROR; |
| 40 } | 41 } |
| 41 | 42 |
| 42 const uint8_t frame_cnt_alarm = 2; | 43 const uint8_t frame_cnt_alarm = 2; |
| 43 | 44 |
| 44 // Get proportion in lowest bins. | 45 // Get proportion in lowest bins. |
| 45 uint8_t low_th = 20; | 46 uint8_t low_th = 20; |
| 46 float prop_low = 0; | 47 float prop_low = 0; |
| 47 for (uint32_t i = 0; i < low_th; i++) { | 48 for (uint32_t i = 0; i < low_th; i++) { |
| 48 prop_low += stats.hist[i]; | 49 prop_low += stats.hist[i]; |
| 49 } | 50 } |
| 50 prop_low /= stats.num_pixels; | 51 prop_low /= stats.num_pixels; |
| 51 | 52 |
| 52 // Get proportion in highest bins. | 53 // Get proportion in highest bins. |
| 53 unsigned char high_th = 230; | 54 unsigned char high_th = 230; |
| 54 float prop_high = 0; | 55 float prop_high = 0; |
| 55 for (uint32_t i = high_th; i < 256; i++) { | 56 for (uint32_t i = high_th; i < 256; i++) { |
| 56 prop_high += stats.hist[i]; | 57 prop_high += stats.hist[i]; |
| 57 } | 58 } |
| 58 prop_high /= stats.num_pixels; | 59 prop_high /= stats.num_pixels; |
| 59 | 60 |
| 60 if (prop_high < 0.4) { | 61 if (prop_high < 0.4) { |
| 61 if (stats.mean < 90 || stats.mean > 170) { | 62 if (stats.mean < 90 || stats.mean > 170) { |
| 62 // Standard deviation of Y | 63 // Standard deviation of Y |
| 63 const uint8_t* buffer = frame.buffer(kYPlane); | 64 const uint8_t* buffer = frame.buffer(kYPlane); |
| 64 float std_y = 0; | 65 float std_y = 0; |
| 65 for (int h = 0; h < height; h += (1 << stats.subSamplHeight)) { | 66 for (int h = 0; h < height; h += (1 << stats.sub_sampling_factor)) { |
| 66 int row = h*width; | 67 int row = h*width; |
| 67 for (int w = 0; w < width; w += (1 << stats.subSamplWidth)) { | 68 for (int w = 0; w < width; w += (1 << stats.sub_sampling_factor)) { |
| 68 std_y += (buffer[w + row] - stats.mean) * (buffer[w + row] - | 69 std_y += (buffer[w + row] - stats.mean) * (buffer[w + row] - |
| 69 stats.mean); | 70 stats.mean); |
| 70 } | 71 } |
| 71 } | 72 } |
| 72 std_y = sqrt(std_y / stats.num_pixels); | 73 std_y = sqrt(std_y / stats.num_pixels); |
| 73 | 74 |
| 74 // Get percentiles. | 75 // Get percentiles. |
| 75 uint32_t sum = 0; | 76 uint32_t sum = 0; |
| 76 uint32_t median_y = 140; | 77 uint32_t median_y = 140; |
| 77 uint32_t perc05 = 0; | 78 uint32_t perc05 = 0; |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 115 } else { | 116 } else { |
| 116 frame_cnt_dark_ = 0; | 117 frame_cnt_dark_ = 0; |
| 117 frame_cnt_bright_ = 0; | 118 frame_cnt_bright_ = 0; |
| 118 } | 119 } |
| 119 } else { | 120 } else { |
| 120 frame_cnt_bright_++; | 121 frame_cnt_bright_++; |
| 121 frame_cnt_dark_ = 0; | 122 frame_cnt_dark_ = 0; |
| 122 } | 123 } |
| 123 | 124 |
| 124 if (frame_cnt_dark_ > frame_cnt_alarm) { | 125 if (frame_cnt_dark_ > frame_cnt_alarm) { |
| 125 return VideoProcessingModule::kDarkWarning; | 126 return VideoProcessing::kDarkWarning; |
| 126 } else if (frame_cnt_bright_ > frame_cnt_alarm) { | 127 } else if (frame_cnt_bright_ > frame_cnt_alarm) { |
| 127 return VideoProcessingModule::kBrightWarning; | 128 return VideoProcessing::kBrightWarning; |
| 128 } else { | 129 } else { |
| 129 return VideoProcessingModule::kNoWarning; | 130 return VideoProcessing::kNoWarning; |
| 130 } | 131 } |
| 131 } | 132 } |
| 132 | 133 |
| 133 } // namespace webrtc | 134 } // namespace webrtc |
| OLD | NEW |