1
0
mirror of https://github.com/opencv/opencv.git synced 2026-07-29 23:33:05 +04:00

Merge pull request #5371 from Dikay900:ports_to_master

This commit is contained in:
Alexander Alekhin
2015-09-21 13:52:45 +00:00
9 changed files with 182 additions and 52 deletions
+3
View File
@@ -1695,6 +1695,9 @@ cvSeqRemoveSlice( CvSeq* seq, CvSlice slice )
slice.end_index = slice.start_index + length;
if ( slice.start_index == slice.end_index )
return;
if( slice.end_index < total )
{
CvSeqReader reader_to, reader_from;
+10 -2
View File
@@ -2331,8 +2331,8 @@ void cv::minMaxIdx(InputArray _src, double* minVal,
size_t minidx = 0, maxidx = 0;
int iminval = INT_MAX, imaxval = INT_MIN;
float fminval = FLT_MAX, fmaxval = -FLT_MAX;
double dminval = DBL_MAX, dmaxval = -DBL_MAX;
float fminval = std::numeric_limits<float>::infinity(), fmaxval = -fminval;
double dminval = std::numeric_limits<double>::infinity(), dmaxval = -dminval;
size_t startidx = 1;
int *minval = &iminval, *maxval = &imaxval;
int planeSize = (int)it.size*cn;
@@ -2345,6 +2345,14 @@ void cv::minMaxIdx(InputArray _src, double* minVal,
for( size_t i = 0; i < it.nplanes; i++, ++it, startidx += planeSize )
func( ptrs[0], ptrs[1], minval, maxval, &minidx, &maxidx, planeSize, startidx );
if (!src.empty() && mask.empty())
{
if( minidx == 0 )
minidx = 1;
if( maxidx == 0 )
maxidx = 1;
}
if( minidx == 0 )
dminval = dmaxval = 0;
else if( depth == CV_32F )
+18 -1
View File
@@ -1792,7 +1792,6 @@ INSTANTIATE_TEST_CASE_P(Arithm, SubtractOutputMatNotEmpty, testing::Combine(
testing::Values(-1, CV_16S, CV_32S, CV_32F),
testing::Bool()));
TEST(Core_FindNonZero, singular)
{
Mat img(10, 10, CV_8U, Scalar::all(0));
@@ -1816,3 +1815,21 @@ TEST(Core_BoolVector, support)
ASSERT_EQ( nz, countNonZero(test) );
ASSERT_FLOAT_EQ((float)nz/n, (float)(mean(test)[0]));
}
TEST(MinMaxLoc, Mat_IntMax_Without_Mask)
{
Mat_<int> mat(50, 50);
int iMaxVal = numeric_limits<int>::max();
mat.setTo(iMaxVal);
double min, max;
Point minLoc, maxLoc;
minMaxLoc(mat, &min, &max, &minLoc, &maxLoc, Mat());
ASSERT_EQ(iMaxVal, min);
ASSERT_EQ(iMaxVal, max);
ASSERT_EQ(Point(0, 0), minLoc);
ASSERT_EQ(Point(0, 0), maxLoc);
}
+74 -27
View File
@@ -1372,6 +1372,49 @@ void CV_GetQuadSubPixTest::prepare_to_validation( int /*test_case_idx*/ )
dst.convertTo(dst0, dst0.depth());
}
////////////////////////////// resizeArea /////////////////////////////////
template <typename T>
static void check_resize_area(const Mat& expected, const Mat& actual, double tolerance = 1.0)
{
ASSERT_EQ(actual.type(), expected.type());
ASSERT_EQ(actual.size(), expected.size());
Mat diff;
absdiff(actual, expected, diff);
Mat one_channel_diff = diff; //.reshape(1);
Size dsize = actual.size();
bool next = true;
for (int dy = 0; dy < dsize.height && next; ++dy)
{
const T* eD = expected.ptr<T>(dy);
const T* aD = actual.ptr<T>(dy);
for (int dx = 0; dx < dsize.width && next; ++dx)
if (fabs(static_cast<double>(aD[dx] - eD[dx])) > tolerance)
{
cvtest::TS::ptr()->printf(cvtest::TS::SUMMARY, "Inf norm: %f\n", static_cast<float>(norm(actual, expected, NORM_INF)));
cvtest::TS::ptr()->printf(cvtest::TS::SUMMARY, "Error in : (%d, %d)\n", dx, dy);
const int radius = 3;
int rmin = MAX(dy - radius, 0), rmax = MIN(dy + radius, dsize.height);
int cmin = MAX(dx - radius, 0), cmax = MIN(dx + radius, dsize.width);
std::cout << "Abs diff:" << std::endl << diff << std::endl;
std::cout << "actual result:\n" << actual(Range(rmin, rmax), Range(cmin, cmax)) << std::endl;
std::cout << "expected result:\n" << expected(Range(rmin, rmax), Range(cmin, cmax)) << std::endl;
next = false;
}
}
ASSERT_EQ(0, norm(one_channel_diff, cv::NORM_INF));
}
///////////////////////////////////////////////////////////////////////////
TEST(Imgproc_cvWarpAffine, regression)
{
IplImage* src = cvCreateImage(cvSize(100, 100), IPL_DEPTH_8U, 1);
@@ -1501,41 +1544,45 @@ TEST(Imgproc_resize_area, regression)
cv::resize(src, actual, cv::Size(), 0.3, 0.3, INTER_AREA);
ASSERT_EQ(actual.type(), expected.type());
ASSERT_EQ(actual.size(), expected.size());
check_resize_area<ushort>(expected, actual, 1.0);
}
Mat diff;
absdiff(actual, expected, diff);
TEST(Imgproc_resize_area, regression_half_round)
{
static uchar input_data[32 * 32];
for(int i = 0; i < 32 * 32; ++i)
input_data[i] = (uchar)(i % 2 + 253 + i / (16 * 32));
Mat one_channel_diff = diff; //.reshape(1);
static uchar expected_data[16 * 16];
for(int i = 0; i < 16 * 16; ++i)
expected_data[i] = (uchar)(254 + i / (16 * 8));
float elem_diff = 1.0f;
Size dsize = actual.size();
bool next = true;
for (int dy = 0; dy < dsize.height && next; ++dy)
{
ushort* eD = expected.ptr<ushort>(dy);
ushort* aD = actual.ptr<ushort>(dy);
cv::Mat src(32, 32, CV_8UC1, input_data);
cv::Mat expected(16, 16, CV_8UC1, expected_data);
cv::Mat actual(expected.size(), expected.type());
for (int dx = 0; dx < dsize.width && next; ++dx)
if (fabs(static_cast<float>(aD[dx] - eD[dx])) > elem_diff)
{
cvtest::TS::ptr()->printf(cvtest::TS::SUMMARY, "Inf norm: %f\n", static_cast<float>(norm(actual, expected, NORM_INF)));
cvtest::TS::ptr()->printf(cvtest::TS::SUMMARY, "Error in : (%d, %d)\n", dx, dy);
cv::resize(src, actual, cv::Size(), 0.5, 0.5, INTER_AREA);
const int radius = 3;
int rmin = MAX(dy - radius, 0), rmax = MIN(dy + radius, dsize.height);
int cmin = MAX(dx - radius, 0), cmax = MIN(dx + radius, dsize.width);
check_resize_area<uchar>(expected, actual, 0.5);
}
std::cout << "Abs diff:" << std::endl << diff << std::endl;
std::cout << "actual result:\n" << actual(Range(rmin, rmax), Range(cmin, cmax)) << std::endl;
std::cout << "expected result:\n" << expected(Range(rmin, rmax), Range(cmin, cmax)) << std::endl;
TEST(Imgproc_resize_area, regression_quarter_round)
{
static uchar input_data[32 * 32];
for(int i = 0; i < 32 * 32; ++i)
input_data[i] = (uchar)(i % 2 + 253 + i / (16 * 32));
next = false;
}
}
static uchar expected_data[8 * 8];
for(int i = 0; i < 8 * 8; ++i)
expected_data[i] = 254;
ASSERT_EQ(cvtest::norm(one_channel_diff, cv::NORM_INF), 0);
cv::Mat src(32, 32, CV_8UC1, input_data);
cv::Mat expected(8, 8, CV_8UC1, expected_data);
cv::Mat actual(expected.size(), expected.type());
cv::resize(src, actual, cv::Size(), 0.25, 0.25, INTER_AREA);
check_resize_area<uchar>(expected, actual, 0.5);
}
+6 -9
View File
@@ -980,12 +980,12 @@ minMaxLoc_(const _Tp* src, size_t total, size_t startidx,
for( size_t i = 0; i < total; i++ )
{
_Tp val = src[i];
if( minval > val )
if( minval > val || !minpos )
{
minval = val;
minpos = startidx + i;
}
if( maxval < val )
if( maxval < val || !maxpos )
{
maxval = val;
maxpos = startidx + i;
@@ -997,12 +997,12 @@ minMaxLoc_(const _Tp* src, size_t total, size_t startidx,
for( size_t i = 0; i < total; i++ )
{
_Tp val = src[i];
if( minval > val && mask[i] )
if( (minval > val || !minpos) && mask[i] )
{
minval = val;
minpos = startidx + i;
}
if( maxval < val && mask[i] )
if( (maxval < val || !maxpos) && mask[i] )
{
maxval = val;
maxpos = startidx + i;
@@ -1049,8 +1049,8 @@ void minMaxLoc(const Mat& src, double* _minval, double* _maxval,
size_t startidx = 1, total = planes[0].total();
size_t i, nplanes = it.nplanes;
int depth = src.depth();
double maxval = depth < CV_32F ? INT_MIN : depth == CV_32F ? -FLT_MAX : -DBL_MAX;
double minval = depth < CV_32F ? INT_MAX : depth == CV_32F ? FLT_MAX : DBL_MAX;
double minval = 0;
double maxval = 0;
size_t maxidx = 0, minidx = 0;
for( i = 0; i < nplanes; i++, ++it, startidx += total )
@@ -1093,9 +1093,6 @@ void minMaxLoc(const Mat& src, double* _minval, double* _maxval,
}
}
if( minidx == 0 )
minval = maxval = 0;
if( _maxval )
*_maxval = maxval;
if( _minval )
@@ -71,6 +71,7 @@
@property (nonatomic, readonly) BOOL captureSessionLoaded;
@property (nonatomic, assign) int defaultFPS;
@property (nonatomic, readonly) AVCaptureVideoPreviewLayer *captureVideoPreviewLayer;
@property (nonatomic, assign) AVCaptureDevicePosition defaultAVCaptureDevicePosition;
@property (nonatomic, assign) AVCaptureVideoOrientation defaultAVCaptureVideoOrientation;
@property (nonatomic, assign) BOOL useAVCaptureVideoPreviewLayer;
@@ -145,6 +146,7 @@
- (void)layoutPreviewLayer;
- (void)saveVideo;
- (NSURL *)videoFileURL;
- (NSString *)videoFileString;
@end
+8 -2
View File
@@ -41,7 +41,9 @@ static CGFloat DegreesToRadians(CGFloat degrees) {return degrees * M_PI / 180;}
@interface CvVideoCamera ()
@interface CvVideoCamera () {
int recordingCountDown;
}
- (void)createVideoDataOutput;
- (void)createVideoFileOutput;
@@ -98,6 +100,7 @@ static CGFloat DegreesToRadians(CGFloat degrees) {return degrees * M_PI / 180;}
- (void)start;
{
recordingCountDown = 10;
[super start];
if (self.recordVideo == YES) {
@@ -551,7 +554,8 @@ static CGFloat DegreesToRadians(CGFloat degrees) {return degrees * M_PI / 180;}
});
if (self.recordVideo == YES) {
recordingCountDown--;
if (self.recordVideo == YES && recordingCountDown < 0) {
lastSampleTime = CMSampleBufferGetPresentationTimeStamp(sampleBuffer);
// CMTimeShow(lastSampleTime);
if (self.recordAssetWriter.status != AVAssetWriterStatusWriting) {
@@ -571,6 +575,8 @@ static CGFloat DegreesToRadians(CGFloat degrees) {return degrees * M_PI / 180;}
withPresentationTime:lastSampleTime] ) {
NSLog(@"Video Writing Error");
}
if (pixelBuffer != nullptr)
CVPixelBufferRelease(pixelBuffer);
}
}