Unverified Commit 11eafca3 authored by Vadim Pisarevsky's avatar Vadim Pisarevsky Committed by GitHub

removed C API in the following modules: photo, video, imgcodecs, videoio (#13060)

* removed C API in the following modules: photo, video, imgcodecs, videoio

* trying to fix various compile errors and warnings on Windows and Linux

* continue to fix compile errors and warnings

* continue to fix compile errors, warnings, as well as the test failures

* trying to resolve compile warnings on Android

* Update cap_dc1394_v2.cpp

fix warning from the new GCC
parent 5087ff08
......@@ -44,12 +44,6 @@
#include "opencv2/core/core_c.h"
#include "opencv2/imgproc/imgproc_c.h"
#ifdef HAVE_OPENCV_IMGCODECS
#include "opencv2/imgcodecs/imgcodecs_c.h"
#endif
#ifdef HAVE_OPENCV_VIDEOIO
#include "opencv2/videoio/videoio_c.h"
#endif
#ifdef __cplusplus
extern "C" {
......
......@@ -47,11 +47,11 @@
#include "opencv2/core/utility.hpp"
#include "opencv2/core/private.hpp"
#include "opencv2/imgproc.hpp"
#include "opencv2/imgproc/imgproc_c.h"
#include "opencv2/highgui/highgui_c.h"
#include "opencv2/imgcodecs.hpp"
#include "opencv2/imgcodecs/imgcodecs_c.h"
#include <stdlib.h>
#include <stdio.h>
......
......@@ -2555,8 +2555,10 @@ void DefaultViewPort::updateImage(const CvArr* arr)
}
nbChannelOriginImage = cvGetElemType(mat);
cvConvertImage(mat, image2Draw_mat, (origin != 0 ? CV_CVTIMG_FLIP : 0) + CV_CVTIMG_SWAP_RB);
CV_Assert(origin == 0);
cv::Mat src = cv::cvarrToMat(mat), dst = cv::cvarrToMat(image2Draw_mat);
cv::cvtColor(src, dst, cv::COLOR_BGR2RGB, dst.channels());
CV_Assert(dst.data == image2Draw_mat->data.ptr);
viewport()->update();
}
......@@ -3002,7 +3004,7 @@ void DefaultViewPort::drawStatusBar()
if (nbChannelOriginImage==CV_8UC1)
{
//all the channel have the same value (because of cvconvertimage), so only the r channel is dsplayed
//all the channel have the same value (because of cv::cvtColor(GRAY=>RGB)), so only the r channel is dsplayed
centralWidget->myStatusBar_msg->setText(tr("<font color='black'>(x=%1, y=%2) ~ </font>")
.arg(mouseCoordinate.x())
.arg(mouseCoordinate.y())+
......
......@@ -41,6 +41,7 @@
//
//M*/
#include "precomp.hpp"
#include "opencv2/imgproc.hpp"
#import <TargetConditionals.h>
......@@ -910,9 +911,8 @@ static NSSize constrainAspectRatio(NSSize base, NSSize constraint) {
- (void)setImageData:(CvArr *)arr {
//cout << "setImageData" << endl;
NSAutoreleasePool* localpool = [[NSAutoreleasePool alloc] init];
CvMat *arrMat, dst, stub;
arrMat = cvGetMat(arr, &stub);
cv::Mat arrMat = cv::cvarrToMat(arr);
/*CGColorSpaceRef colorspace = NULL;
CGDataProviderRef provider = NULL;
int width = cvimage->width;
......@@ -933,40 +933,35 @@ static NSSize constrainAspectRatio(NSSize base, NSSize constraint) {
}*/
NSBitmapImageRep *bitmap = [[NSBitmapImageRep alloc] initWithBitmapDataPlanes:NULL
pixelsWide:arrMat->cols
pixelsHigh:arrMat->rows
pixelsWide:arrMat.cols
pixelsHigh:arrMat.rows
bitsPerSample:8
samplesPerPixel:3
hasAlpha:NO
isPlanar:NO
colorSpaceName:NSDeviceRGBColorSpace
bitmapFormat: kCGImageAlphaNone
bytesPerRow:((arrMat->cols * 3 + 3) & -4)
bytesPerRow:((arrMat.cols * 3 + 3) & -4)
bitsPerPixel:24];
if (bitmap) {
cvInitMatHeader(&dst, arrMat->rows, arrMat->cols, CV_8UC3, [bitmap bitmapData], [bitmap bytesPerRow]);
cvConvertImage(arrMat, &dst, CV_CVTIMG_SWAP_RB);
cv::Mat dst(arrMat.rows, arrMat.cols, CV_8UC3, [bitmap bitmapData], [bitmap bytesPerRow]);
cv::cvtColor(arrMat, dst, cv::COLOR_BGR2RGB);
}
else {
// It's not guaranteed to like the bitsPerPixel:24, but this is a lot slower so we'd rather not do it
bitmap = [[NSBitmapImageRep alloc] initWithBitmapDataPlanes:NULL
pixelsWide:arrMat->cols
pixelsHigh:arrMat->rows
pixelsWide:arrMat.cols
pixelsHigh:arrMat.rows
bitsPerSample:8
samplesPerPixel:3
hasAlpha:NO
isPlanar:NO
colorSpaceName:NSDeviceRGBColorSpace
bytesPerRow:(arrMat->cols * 4)
bytesPerRow:(arrMat.cols * 4)
bitsPerPixel:32];
uint8_t *data = [bitmap bitmapData];
cvInitMatHeader(&dst, arrMat->rows, arrMat->cols, CV_8UC3, data, (arrMat->cols * 3));
cvConvertImage(arrMat, &dst, CV_CVTIMG_SWAP_RB);
for (int i = (arrMat->rows * arrMat->cols) - 1; i >= 0; i--) {
memmove(data + i * 4, data + i * 3, 3);
data[i * 4 + 3] = 0;
}
cv::Mat dst(arrMat.rows, arrMat.cols, CV_8UC3, [bitmap bitmapData], [bitmap bytesPerRow]);
cv::cvtColor(arrMat, dst, cv::COLOR_BGR2RGBA);
}
if( image ) {
......
......@@ -140,8 +140,10 @@ void cvImageWidgetSetImage(CvImageWidget * widget, const CvArr *arr){
widget->original_image = cvCreateMat( mat->rows, mat->cols, CV_8UC3 );
gtk_widget_queue_resize( GTK_WIDGET( widget ) );
}
cvConvertImage( mat, widget->original_image,
(origin != 0 ? CV_CVTIMG_FLIP : 0) + CV_CVTIMG_SWAP_RB );
CV_Assert(origin == 0);
cv::Mat src = cv::cvarrToMat(arr), dst = cv::cvarrToMat(widget->original_image);
cv::cvtColor(src, dst, cv::COLOR_BGR2RGB, dst.channels());
CV_Assert(dst.data == widget->original_image->data.ptr);
if(widget->scaled_image){
cvResize( widget->original_image, widget->scaled_image, CV_INTER_AREA );
}
......
......@@ -1155,7 +1155,7 @@ cvShowImage( const char* name, const CvArr* arr )
void* dst_ptr = 0;
const int channels0 = 3;
int origin = 0;
CvMat stub, dst, *image;
CvMat stub, *image;
bool changed_size = false; // philipg
if( !name )
......@@ -1209,9 +1209,26 @@ cvShowImage( const char* name, const CvArr* arr )
DIB_RGB_COLORS, &dst_ptr, 0, 0));
}
cvInitMatHeader( &dst, size.cy, size.cx, CV_8UC3,
dst_ptr, (size.cx * channels + 3) & -4 );
cvConvertImage( image, &dst, origin == 0 ? CV_CVTIMG_FLIP : 0 );
{
cv::Mat src = cv::cvarrToMat(image);
cv::Mat dst(size.cy, size.cx, CV_8UC3, dst_ptr, (size.cx * channels + 3) & -4);
if (src.channels() == 1)
{
cv::cvtColor(src, dst, cv::COLOR_GRAY2BGR);
cv::flip(dst, dst, 0);
}
else if (src.channels() == 4)
{
cv::cvtColor(src, dst, cv::COLOR_BGRA2BGR);
cv::flip(dst, dst, 0);
}
else
{
CV_Assert(src.channels() == 3);
cv::flip(src, dst, 0);
}
CV_Assert(dst.data == (uchar*)dst_ptr);
}
// ony resize window if needed
if (changed_size)
......@@ -1223,86 +1240,6 @@ cvShowImage( const char* name, const CvArr* arr )
__END__;
}
#if 0
CV_IMPL void
cvShowImageHWND(HWND w_hWnd, const CvArr* arr)
{
CV_FUNCNAME( "cvShowImageHWND" );
__BEGIN__;
SIZE size = { 0, 0 };
int channels = 0;
void* dst_ptr = 0;
const int channels0 = 3;
int origin = 0;
CvMat stub, dst, *image;
bool changed_size = false;
BITMAPINFO tempbinfo;
HDC hdc = NULL;
if( !arr )
EXIT;
if( !w_hWnd )
EXIT;
hdc = GetDC(w_hWnd);
if( CV_IS_IMAGE_HDR( arr ) )
origin = ((IplImage*)arr)->origin;
CV_CALL( image = cvGetMat( arr, &stub ) );
if ( hdc )
{
//GetBitmapData
BITMAP bmp;
GdiFlush();
HGDIOBJ h = GetCurrentObject( hdc, OBJ_BITMAP );
if (h == NULL)
EXIT;
if (GetObject(h, sizeof(bmp), &bmp) == 0) //GetObject(): returns size of object, 0 if error
EXIT;
channels = bmp.bmBitsPixel/8;
dst_ptr = bmp.bmBits;
}
if( size.cx != image->width || size.cy != image->height || channels != channels0 )
{
changed_size = true;
uchar buffer[sizeof(BITMAPINFO) + 255*sizeof(RGBQUAD)];
BITMAPINFO* binfo = (BITMAPINFO*)buffer;
BOOL bDeleteObj = DeleteObject(GetCurrentObject(hdc, OBJ_BITMAP));
CV_Assert( FALSE != bDeleteObj );
size.cx = image->width;
size.cy = image->height;
channels = channels0;
FillBitmapInfo( binfo, size.cx, size.cy, channels*8, 1 );
SelectObject( hdc, CreateDIBSection( hdc, binfo, DIB_RGB_COLORS, &dst_ptr, 0, 0));
}
cvInitMatHeader( &dst, size.cy, size.cx, CV_8UC3, dst_ptr, (size.cx * channels + 3) & -4 );
cvConvertImage( image, &dst, origin == 0 ? CV_CVTIMG_FLIP : 0 );
// Image stretching to fit the window
RECT rect;
GetClientRect(w_hWnd, &rect);
StretchDIBits( hdc, 0, 0, rect.right, rect.bottom, 0, 0, image->width, image->height, dst_ptr, &tempbinfo, DIB_RGB_COLORS, SRCCOPY );
// ony resize window if needed
InvalidateRect(w_hWnd, 0, 0);
__END__;
}
#endif
CV_IMPL void cvResizeWindow(const char* name, int width, int height )
{
CV_FUNCNAME( "cvResizeWindow" );
......
......@@ -53,6 +53,52 @@
@}
*/
/* duplicate of "ImreadModes" enumeration for better compatibility with OpenCV 3.x */
enum
{
/* 8bit, color or not */
CV_LOAD_IMAGE_UNCHANGED =-1,
/* 8bit, gray */
CV_LOAD_IMAGE_GRAYSCALE =0,
/* ?, color */
CV_LOAD_IMAGE_COLOR =1,
/* any depth, ? */
CV_LOAD_IMAGE_ANYDEPTH =2,
/* ?, any color */
CV_LOAD_IMAGE_ANYCOLOR =4,
/* ?, no rotate */
CV_LOAD_IMAGE_IGNORE_ORIENTATION =128
};
/* duplicate of "ImwriteFlags" enumeration for better compatibility with OpenCV 3.x */
enum
{
CV_IMWRITE_JPEG_QUALITY =1,
CV_IMWRITE_JPEG_PROGRESSIVE =2,
CV_IMWRITE_JPEG_OPTIMIZE =3,
CV_IMWRITE_JPEG_RST_INTERVAL =4,
CV_IMWRITE_JPEG_LUMA_QUALITY =5,
CV_IMWRITE_JPEG_CHROMA_QUALITY =6,
CV_IMWRITE_PNG_COMPRESSION =16,
CV_IMWRITE_PNG_STRATEGY =17,
CV_IMWRITE_PNG_BILEVEL =18,
CV_IMWRITE_PNG_STRATEGY_DEFAULT =0,
CV_IMWRITE_PNG_STRATEGY_FILTERED =1,
CV_IMWRITE_PNG_STRATEGY_HUFFMAN_ONLY =2,
CV_IMWRITE_PNG_STRATEGY_RLE =3,
CV_IMWRITE_PNG_STRATEGY_FIXED =4,
CV_IMWRITE_PXM_BINARY =32,
CV_IMWRITE_EXR_TYPE = 48,
CV_IMWRITE_WEBP_QUALITY =64,
CV_IMWRITE_PAM_TUPLETYPE = 128,
CV_IMWRITE_PAM_FORMAT_NULL = 0,
CV_IMWRITE_PAM_FORMAT_BLACKANDWHITE = 1,
CV_IMWRITE_PAM_FORMAT_GRAYSCALE = 2,
CV_IMWRITE_PAM_FORMAT_GRAYSCALE_ALPHA = 3,
CV_IMWRITE_PAM_FORMAT_RGB = 4,
CV_IMWRITE_PAM_FORMAT_RGB_ALPHA = 5,
};
//////////////////////////////// image codec ////////////////////////////////
namespace cv
{
......@@ -250,6 +296,19 @@ CV_EXPORTS_W bool imencode( const String& ext, InputArray img,
CV_OUT std::vector<uchar>& buf,
const std::vector<int>& params = std::vector<int>());
/** @brief Returns true if the specified image can be decoded by OpenCV
@param filename File name of the image
*/
CV_EXPORTS_W bool haveImageReader( const String& filename );
/** @brief Returns true if an image with the specified filename can be encoded by OpenCV
@param filename File name of the image
*/
CV_EXPORTS_W bool haveImageWriter( const String& filename );
//! @} imgcodecs
} // cv
......
/*M///////////////////////////////////////////////////////////////////////////////////////
//
// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING.
//
// By downloading, copying, installing or using the software you agree to this license.
// If you do not agree to this license, do not download, install,
// copy or use the software.
//
//
// Intel License Agreement
// For Open Source Computer Vision Library
//
// Copyright (C) 2000, Intel Corporation, all rights reserved.
// Third party copyrights are property of their respective owners.
//
// Redistribution and use in source and binary forms, with or without modification,
// are permitted provided that the following conditions are met:
//
// * Redistribution's of source code must retain the above copyright notice,
// this list of conditions and the following disclaimer.
//
// * Redistribution's in binary form must reproduce the above copyright notice,
// this list of conditions and the following disclaimer in the documentation
// and/or other materials provided with the distribution.
//
// * The name of Intel Corporation may not be used to endorse or promote products
// derived from this software without specific prior written permission.
//
// This software is provided by the copyright holders and contributors "as is" and
// any express or implied warranties, including, but not limited to, the implied
// warranties of merchantability and fitness for a particular purpose are disclaimed.
// In no event shall the Intel Corporation or contributors be liable for any direct,
// indirect, incidental, special, exemplary, or consequential damages
// (including, but not limited to, procurement of substitute goods or services;
// loss of use, data, or profits; or business interruption) however caused
// and on any theory of liability, whether in contract, strict liability,
// or tort (including negligence or otherwise) arising in any way out of
// the use of this software, even if advised of the possibility of such damage.
//
//M*/
#ifndef OPENCV_IMGCODECS_H
#define OPENCV_IMGCODECS_H
#include "opencv2/core/core_c.h"
#ifdef __cplusplus
extern "C" {
#endif /* __cplusplus */
/** @addtogroup imgcodecs_c
@{
*/
enum
{
/* 8bit, color or not */
CV_LOAD_IMAGE_UNCHANGED =-1,
/* 8bit, gray */
CV_LOAD_IMAGE_GRAYSCALE =0,
/* ?, color */
CV_LOAD_IMAGE_COLOR =1,
/* any depth, ? */
CV_LOAD_IMAGE_ANYDEPTH =2,
/* ?, any color */
CV_LOAD_IMAGE_ANYCOLOR =4,
/* ?, no rotate */
CV_LOAD_IMAGE_IGNORE_ORIENTATION =128
};
/* load image from file
iscolor can be a combination of above flags where CV_LOAD_IMAGE_UNCHANGED
overrides the other flags
using CV_LOAD_IMAGE_ANYCOLOR alone is equivalent to CV_LOAD_IMAGE_UNCHANGED
unless CV_LOAD_IMAGE_ANYDEPTH is specified images are converted to 8bit
*/
CVAPI(IplImage*) cvLoadImage( const char* filename, int iscolor CV_DEFAULT(CV_LOAD_IMAGE_COLOR));
CVAPI(CvMat*) cvLoadImageM( const char* filename, int iscolor CV_DEFAULT(CV_LOAD_IMAGE_COLOR));
enum
{
CV_IMWRITE_JPEG_QUALITY =1,
CV_IMWRITE_JPEG_PROGRESSIVE =2,
CV_IMWRITE_JPEG_OPTIMIZE =3,
CV_IMWRITE_JPEG_RST_INTERVAL =4,
CV_IMWRITE_JPEG_LUMA_QUALITY =5,
CV_IMWRITE_JPEG_CHROMA_QUALITY =6,
CV_IMWRITE_PNG_COMPRESSION =16,
CV_IMWRITE_PNG_STRATEGY =17,
CV_IMWRITE_PNG_BILEVEL =18,
CV_IMWRITE_PNG_STRATEGY_DEFAULT =0,
CV_IMWRITE_PNG_STRATEGY_FILTERED =1,
CV_IMWRITE_PNG_STRATEGY_HUFFMAN_ONLY =2,
CV_IMWRITE_PNG_STRATEGY_RLE =3,
CV_IMWRITE_PNG_STRATEGY_FIXED =4,
CV_IMWRITE_PXM_BINARY =32,
CV_IMWRITE_EXR_TYPE = 48,
CV_IMWRITE_WEBP_QUALITY =64,
CV_IMWRITE_PAM_TUPLETYPE = 128,
CV_IMWRITE_PAM_FORMAT_NULL = 0,
CV_IMWRITE_PAM_FORMAT_BLACKANDWHITE = 1,
CV_IMWRITE_PAM_FORMAT_GRAYSCALE = 2,
CV_IMWRITE_PAM_FORMAT_GRAYSCALE_ALPHA = 3,
CV_IMWRITE_PAM_FORMAT_RGB = 4,
CV_IMWRITE_PAM_FORMAT_RGB_ALPHA = 5,
};
/* save image to file */
CVAPI(int) cvSaveImage( const char* filename, const CvArr* image,
const int* params CV_DEFAULT(0) );
/* decode image stored in the buffer */
CVAPI(IplImage*) cvDecodeImage( const CvMat* buf, int iscolor CV_DEFAULT(CV_LOAD_IMAGE_COLOR));
CVAPI(CvMat*) cvDecodeImageM( const CvMat* buf, int iscolor CV_DEFAULT(CV_LOAD_IMAGE_COLOR));
/* encode image and store the result as a byte vector (single-row 8uC1 matrix) */
CVAPI(CvMat*) cvEncodeImage( const char* ext, const CvArr* image,
const int* params CV_DEFAULT(0) );
enum
{
CV_CVTIMG_FLIP =1,
CV_CVTIMG_SWAP_RB =2
};
/* utility function: convert one image to another with optional vertical flip */
CVAPI(void) cvConvertImage( const CvArr* src, CvArr* dst, int flags CV_DEFAULT(0));
CVAPI(int) cvHaveImageReader(const char* filename);
CVAPI(int) cvHaveImageWriter(const char* filename);
/****************************************************************************************\
* Obsolete functions/synonyms *
\****************************************************************************************/
#define cvvLoadImage(name) cvLoadImage((name),1)
#define cvvSaveImage cvSaveImage
#define cvvConvertImage cvConvertImage
/** @} imgcodecs_c */
#ifdef __cplusplus
}
#endif
#endif // OPENCV_IMGCODECS_H
......@@ -142,7 +142,7 @@ void BaseImageEncoder::throwOnEror() const
if(!m_last_error.empty())
{
String msg = "Raw image encoder error: " + m_last_error;
CV_Error( CV_BadImageSize, msg.c_str() );
CV_Error( Error::BadImageSize, msg.c_str() );
}
}
......
......@@ -55,7 +55,7 @@ BmpDecoder::BmpDecoder()
m_signature = fmtSignBmp;
m_offset = -1;
m_buf_supported = true;
m_origin = 0;
m_origin = ORIGIN_TL;
m_bpp = 0;
m_rle_code = BMP_RGB;
}
......@@ -179,7 +179,7 @@ bool BmpDecoder::readHeader()
}
// in 32 bit case alpha channel is used - so require CV_8UC4 type
m_type = iscolor ? (m_bpp == 32 ? CV_8UC4 : CV_8UC3 ) : CV_8UC1;
m_origin = m_height > 0 ? IPL_ORIGIN_BL : IPL_ORIGIN_TL;
m_origin = m_height > 0 ? ORIGIN_BL : ORIGIN_TL;
m_height = std::abs(m_height);
if( !result )
......@@ -206,7 +206,7 @@ bool BmpDecoder::readData( Mat& img )
if( m_offset < 0 || !m_strm.isOpened())
return false;
if( m_origin == IPL_ORIGIN_BL )
if( m_origin == ORIGIN_BL )
{
data += (m_height - 1)*(size_t)step;
step = -step;
......@@ -238,7 +238,7 @@ bool BmpDecoder::readData( Mat& img )
m_strm.getBytes( src, src_pitch );
FillColorRow1( color ? data : bgr, src, m_width, m_palette );
if( !color )
icvCvt_BGR2Gray_8u_C3C1R( bgr, 0, data, 0, cvSize(m_width,1) );
icvCvt_BGR2Gray_8u_C3C1R( bgr, 0, data, 0, Size(m_width,1) );
}
result = true;
break;
......@@ -441,9 +441,9 @@ decode_rle8_bad: ;
{
m_strm.getBytes( src, src_pitch );
if( !color )
icvCvt_BGR5552Gray_8u_C2C1R( src, 0, data, 0, cvSize(m_width,1) );
icvCvt_BGR5552Gray_8u_C2C1R( src, 0, data, 0, Size(m_width,1) );
else
icvCvt_BGR5552BGR_8u_C2C3R( src, 0, data, 0, cvSize(m_width,1) );
icvCvt_BGR5552BGR_8u_C2C3R( src, 0, data, 0, Size(m_width,1) );
}
result = true;
break;
......@@ -453,9 +453,9 @@ decode_rle8_bad: ;
{
m_strm.getBytes( src, src_pitch );
if( !color )
icvCvt_BGR5652Gray_8u_C2C1R( src, 0, data, 0, cvSize(m_width,1) );
icvCvt_BGR5652Gray_8u_C2C1R( src, 0, data, 0, Size(m_width,1) );
else
icvCvt_BGR5652BGR_8u_C2C3R( src, 0, data, 0, cvSize(m_width,1) );
icvCvt_BGR5652BGR_8u_C2C3R( src, 0, data, 0, Size(m_width,1) );
}
result = true;
break;
......@@ -465,7 +465,7 @@ decode_rle8_bad: ;
{
m_strm.getBytes( src, src_pitch );
if(!color)
icvCvt_BGR2Gray_8u_C3C1R( src, 0, data, 0, cvSize(m_width,1) );
icvCvt_BGR2Gray_8u_C3C1R( src, 0, data, 0, Size(m_width,1) );
else
memcpy( data, src, m_width*3 );
}
......@@ -478,9 +478,9 @@ decode_rle8_bad: ;
m_strm.getBytes( src, src_pitch );
if( !color )
icvCvt_BGRA2Gray_8u_C4C1R( src, 0, data, 0, cvSize(m_width,1) );
icvCvt_BGRA2Gray_8u_C4C1R( src, 0, data, 0, Size(m_width,1) );
else if( img.channels() == 3 )
icvCvt_BGRA2BGR_8u_C4C3R(src, 0, data, 0, cvSize(m_width, 1));
icvCvt_BGRA2BGR_8u_C4C3R(src, 0, data, 0, Size(m_width, 1));
else if( img.channels() == 4 )
memcpy(data, src, m_width * 4);
}
......
......@@ -73,9 +73,15 @@ public:
protected:
enum Origin
{
ORIGIN_TL = 0,
ORIGIN_BL = 1
};
RLByteStream m_strm;
PaletteEntry m_palette[256];
int m_origin;
Origin m_origin;
int m_bpp;
int m_offset;
BmpCompression m_rle_code;
......
......@@ -453,16 +453,16 @@ bool JpegDecoder::readData( Mat& img )
if( color )
{
if( cinfo->out_color_components == 3 )
icvCvt_RGB2BGR_8u_C3R( buffer[0], 0, data, 0, cvSize(m_width,1) );
icvCvt_RGB2BGR_8u_C3R( buffer[0], 0, data, 0, Size(m_width,1) );
else
icvCvt_CMYK2BGR_8u_C4C3R( buffer[0], 0, data, 0, cvSize(m_width,1) );
icvCvt_CMYK2BGR_8u_C4C3R( buffer[0], 0, data, 0, Size(m_width,1) );
}
else
{
if( cinfo->out_color_components == 1 )
memcpy( data, buffer[0], m_width );
else
icvCvt_CMYK2Gray_8u_C4C1R( buffer[0], 0, data, 0, cvSize(m_width,1) );
icvCvt_CMYK2Gray_8u_C4C1R( buffer[0], 0, data, 0, Size(m_width,1) );
}
}
......@@ -689,12 +689,12 @@ bool JpegEncoder::write( const Mat& img, const std::vector<int>& params )
if( _channels == 3 )
{
icvCvt_BGR2RGB_8u_C3R( data, 0, buffer, 0, cvSize(width,1) );
icvCvt_BGR2RGB_8u_C3R( data, 0, buffer, 0, Size(width,1) );
ptr = buffer;
}
else if( _channels == 4 )
{
icvCvt_BGRA2BGR_8u_C4C3R( data, 0, buffer, 0, cvSize(width,1), 2 );
icvCvt_BGRA2BGR_8u_C4C3R( data, 0, buffer, 0, Size(width,1), 2 );
ptr = buffer;
}
......
......@@ -132,12 +132,12 @@ rgb_convert (void *src, void *target, int width, int target_channels, int target
switch (target_depth) {
case CV_8U:
icvCvt_RGB2BGR_8u_C3R( (uchar*) src, 0, (uchar*) target, 0,
cvSize(width,1) );
Size(width,1) );
ret = true;
break;
case CV_16U:
icvCvt_RGB2BGR_16u_C3R( (ushort *)src, 0, (ushort *)target, 0,
cvSize(width,1) );
Size(width,1) );
ret = true;
break;
default:
......@@ -147,12 +147,12 @@ rgb_convert (void *src, void *target, int width, int target_channels, int target
switch (target_depth) {
case CV_8U:
icvCvt_BGR2Gray_8u_C3C1R( (uchar*) src, 0, (uchar*) target, 0,
cvSize(width,1), 2 );
Size(width,1), 2 );
ret = true;
break;
case CV_16U:
icvCvt_BGRA2Gray_16u_CnC1R( (ushort *)src, 0, (ushort *)target, 0,
cvSize(width,1), 3, 2 );
Size(width,1), 3, 2 );
ret = true;
break;
default:
......
......@@ -342,14 +342,14 @@ bool PxMDecoder::readData( Mat& img )
if( color )
{
if( img.depth() == CV_8U )
icvCvt_RGB2BGR_8u_C3R( src, 0, data, 0, cvSize(m_width,1) );
icvCvt_RGB2BGR_8u_C3R( src, 0, data, 0, Size(m_width,1) );
else
icvCvt_RGB2BGR_16u_C3R( (ushort *)src, 0, (ushort *)data, 0, cvSize(m_width,1) );
icvCvt_RGB2BGR_16u_C3R( (ushort *)src, 0, (ushort *)data, 0, Size(m_width,1) );
}
else if( img.depth() == CV_8U )
icvCvt_BGR2Gray_8u_C3C1R( src, 0, data, 0, cvSize(m_width,1), 2 );
icvCvt_BGR2Gray_8u_C3C1R( src, 0, data, 0, Size(m_width,1), 2 );
else
icvCvt_BGRA2Gray_16u_CnC1R( (ushort *)src, 0, (ushort *)data, 0, cvSize(m_width,1), 3, 2 );
icvCvt_BGRA2Gray_16u_CnC1R( (ushort *)src, 0, (ushort *)data, 0, Size(m_width,1), 3, 2 );
}
}
result = true;
......@@ -522,10 +522,10 @@ bool PxMEncoder::write(const Mat& img, const std::vector<int>& params)
{
if( depth == 8 )
icvCvt_BGR2RGB_8u_C3R( (const uchar*)data, 0,
(uchar*)buffer, 0, cvSize(width,1) );
(uchar*)buffer, 0, Size(width,1) );
else
icvCvt_BGR2RGB_16u_C3R( (const ushort*)data, 0,
(ushort*)buffer, 0, cvSize(width,1) );
(ushort*)buffer, 0, Size(width,1) );
}
// swap endianness if necessary
......
......@@ -343,13 +343,13 @@ bad_decoding_end:
if( color )
{
if( m_type == RAS_FORMAT_RGB )
icvCvt_RGB2BGR_8u_C3R(src, 0, data, 0, cvSize(m_width,1) );
icvCvt_RGB2BGR_8u_C3R(src, 0, data, 0, Size(m_width,1) );
else
memcpy(data, src, std::min(step, (size_t)src_pitch));
}
else
{
icvCvt_BGR2Gray_8u_C3C1R(src, 0, data, 0, cvSize(m_width,1),
icvCvt_BGR2Gray_8u_C3C1R(src, 0, data, 0, Size(m_width,1),
m_type == RAS_FORMAT_RGB ? 2 : 0 );
}
}
......@@ -364,10 +364,10 @@ bad_decoding_end:
m_strm.getBytes( src + 3, src_pitch );
if( color )
icvCvt_BGRA2BGR_8u_C4C3R( src + 4, 0, data, 0, cvSize(m_width,1),
icvCvt_BGRA2BGR_8u_C4C3R( src + 4, 0, data, 0, Size(m_width,1),
m_type == RAS_FORMAT_RGB ? 2 : 0 );
else
icvCvt_BGRA2Gray_8u_C4C1R( src + 4, 0, data, 0, cvSize(m_width,1),
icvCvt_BGRA2Gray_8u_C4C1R( src + 4, 0, data, 0, Size(m_width,1),
m_type == RAS_FORMAT_RGB ? 2 : 0 );
}
result = true;
......
......@@ -408,19 +408,19 @@ bool TiffDecoder::readData( Mat& img )
{
icvCvt_BGRA2RGBA_8u_C4R( bstart + i*tile_width0*4, 0,
data + x*4 + img.step*(tile_height - i - 1), 0,
cvSize(tile_width,1) );
Size(tile_width,1) );
}
else
{
icvCvt_BGRA2BGR_8u_C4C3R( bstart + i*tile_width0*4, 0,
data + x*3 + img.step*(tile_height - i - 1), 0,
cvSize(tile_width,1), 2 );
Size(tile_width,1), 2 );
}
}
else
icvCvt_BGRA2Gray_8u_C4C1R( bstart + i*tile_width0*4, 0,
data + x + img.step*(tile_height - i - 1), 0,
cvSize(tile_width,1), 2 );
Size(tile_width,1), 2 );
break;
}
......@@ -445,13 +445,13 @@ bool TiffDecoder::readData( Mat& img )
{
icvCvt_Gray2BGR_16u_C1C3R(buffer16 + i*tile_width0*ncn, 0,
(ushort*)(data + img.step*i) + x*3, 0,
cvSize(tile_width,1) );
Size(tile_width,1) );
}
else if( ncn == 3 )
{
icvCvt_RGB2BGR_16u_C3R(buffer16 + i*tile_width0*ncn, 0,
(ushort*)(data + img.step*i) + x*3, 0,
cvSize(tile_width,1) );
Size(tile_width,1) );
}
else if (ncn == 4)
{
......@@ -459,20 +459,20 @@ bool TiffDecoder::readData( Mat& img )
{
icvCvt_BGRA2RGBA_16u_C4R(buffer16 + i*tile_width0*ncn, 0,
(ushort*)(data + img.step*i) + x * 4, 0,
cvSize(tile_width, 1));
Size(tile_width, 1));
}
else
{
icvCvt_BGRA2BGR_16u_C4C3R(buffer16 + i*tile_width0*ncn, 0,
(ushort*)(data + img.step*i) + x * 3, 0,
cvSize(tile_width, 1), 2);
Size(tile_width, 1), 2);
}
}
else
{
icvCvt_BGRA2BGR_16u_C4C3R(buffer16 + i*tile_width0*ncn, 0,
(ushort*)(data + img.step*i) + x*3, 0,
cvSize(tile_width,1), 2 );
Size(tile_width,1), 2 );
}
}
else
......@@ -487,7 +487,7 @@ bool TiffDecoder::readData( Mat& img )
{
icvCvt_BGRA2Gray_16u_CnC1R(buffer16 + i*tile_width0*ncn, 0,
(ushort*)(data + img.step*i) + x, 0,
cvSize(tile_width,1), ncn, 2 );
Size(tile_width,1), ncn, 2 );
}
}
}
......@@ -859,18 +859,18 @@ bool TiffEncoder::writeLibTiff( const std::vector<Mat>& img_vec, const std::vect
case 3:
{
if (depth == CV_8U)
icvCvt_BGR2RGB_8u_C3R( img.ptr(y), 0, buffer, 0, cvSize(width, 1));
icvCvt_BGR2RGB_8u_C3R( img.ptr(y), 0, buffer, 0, Size(width, 1));
else
icvCvt_BGR2RGB_16u_C3R( img.ptr<ushort>(y), 0, (ushort*)buffer, 0, cvSize(width, 1));
icvCvt_BGR2RGB_16u_C3R( img.ptr<ushort>(y), 0, (ushort*)buffer, 0, Size(width, 1));
break;
}
case 4:
{
if (depth == CV_8U)
icvCvt_BGRA2RGBA_8u_C4R( img.ptr(y), 0, buffer, 0, cvSize(width, 1));
icvCvt_BGRA2RGBA_8u_C4R( img.ptr(y), 0, buffer, 0, Size(width, 1));
else
icvCvt_BGRA2RGBA_16u_C4R( img.ptr<ushort>(y), 0, (ushort*)buffer, 0, cvSize(width, 1));
icvCvt_BGRA2RGBA_16u_C4R( img.ptr<ushort>(y), 0, (ushort*)buffer, 0, Size(width, 1));
break;
}
......
......@@ -301,8 +301,6 @@ static ImageEncoder findEncoder( const String& _ext )
}
enum { LOAD_CVMAT=0, LOAD_IMAGE=1, LOAD_MAT=2 };
static void ExifTransform(int orientation, Mat& img)
{
switch( orientation )
......@@ -397,15 +395,9 @@ static void ApplyExifOrientation(const Mat& buf, Mat& img)
* @param[in] scale_denom Scale value
*
*/
static void*
imread_( const String& filename, int flags, int hdrtype, Mat* mat=0 )
static bool
imread_( const String& filename, int flags, Mat& mat )
{
CV_Assert(mat || hdrtype != LOAD_MAT); // mat is required in LOAD_MAT case
IplImage* image = 0;
CvMat *matrix = 0;
Mat temp, *data = &temp;
/// Search for the relevant decoder to handle the imagery
ImageDecoder decoder;
......@@ -476,30 +468,13 @@ imread_( const String& filename, int flags, int hdrtype, Mat* mat=0 )
type = CV_MAKETYPE(CV_MAT_DEPTH(type), 1);
}
if( hdrtype == LOAD_CVMAT || hdrtype == LOAD_MAT )
{
if( hdrtype == LOAD_CVMAT )
{
matrix = cvCreateMat( size.height, size.width, type );
temp = cvarrToMat( matrix );
}
else
{
mat->create( size.height, size.width, type );
data = mat;
}
}
else
{
image = cvCreateImage(cvSize(size), cvIplDepth(type), CV_MAT_CN(type));
temp = cvarrToMat( image );
}
mat.create( size.height, size.width, type );
// read the image data
bool success = false;
CV_TRY
{
if (decoder->readData(*data))
if (decoder->readData(mat))
success = true;
}
CV_CATCH (cv::Exception, e)
......@@ -512,20 +487,16 @@ imread_( const String& filename, int flags, int hdrtype, Mat* mat=0 )
}
if (!success)
{
cvReleaseImage( &image );
cvReleaseMat( &matrix );
if( mat )
mat->release();
return 0;
mat.release();
return false;
}
if( decoder->setScale( scale_denom ) > 1 ) // if decoder is JpegDecoder then decoder->setScale always returns 1
{
resize( *mat, *mat, Size( size.width / scale_denom, size.height / scale_denom ), 0, 0, INTER_LINEAR_EXACT);
resize( mat, mat, Size( size.width / scale_denom, size.height / scale_denom ), 0, 0, INTER_LINEAR_EXACT);
}
return hdrtype == LOAD_CVMAT ? (void*)matrix :
hdrtype == LOAD_IMAGE ? (void*)image : (void*)mat;
return true;
}
......@@ -650,7 +621,7 @@ Mat imread( const String& filename, int flags )
Mat img;
/// load the data
imread_( filename, flags, LOAD_MAT, &img );
imread_( filename, flags, img );
/// optionally rotate the data if EXIF' orientation flag says so
if( !img.empty() && (flags & IMREAD_IGNORE_ORIENTATION) == 0 && flags != IMREAD_UNCHANGED )
......@@ -687,7 +658,7 @@ static bool imwrite_( const String& filename, const std::vector<Mat>& img_vec,
ImageEncoder encoder = findEncoder( filename );
if( !encoder )
CV_Error( CV_StsError, "could not find a writer for the specified extension" );
CV_Error( Error::StsError, "could not find a writer for the specified extension" );
for (size_t page = 0; page < img_vec.size(); page++)
{
......@@ -748,13 +719,10 @@ bool imwrite( const String& filename, InputArray _img,
return imwrite_(filename, img_vec, params, false);
}
static void*
imdecode_( const Mat& buf, int flags, int hdrtype, Mat* mat=0 )
static bool
imdecode_( const Mat& buf, int flags, Mat& mat )
{
CV_Assert(!buf.empty() && buf.isContinuous());
IplImage* image = 0;
CvMat *matrix = 0;
Mat temp, *data = &temp;
String filename;
ImageDecoder decoder = findDecoder(buf);
......@@ -771,11 +739,11 @@ imdecode_( const Mat& buf, int flags, int hdrtype, Mat* mat=0 )
if( fwrite( buf.ptr(), 1, bufSize, f ) != bufSize )
{
fclose( f );
CV_Error( CV_StsError, "failed to write image data to temporary file" );
CV_Error( Error::StsError, "failed to write image data to temporary file" );
}
if( fclose(f) != 0 )
{
CV_Error( CV_StsError, "failed to write image data to temporary file" );
CV_Error( Error::StsError, "failed to write image data to temporary file" );
}
decoder->setSource(filename);
}
......@@ -823,29 +791,12 @@ imdecode_( const Mat& buf, int flags, int hdrtype, Mat* mat=0 )
type = CV_MAKETYPE(CV_MAT_DEPTH(type), 1);
}
if( hdrtype == LOAD_CVMAT || hdrtype == LOAD_MAT )
{
if( hdrtype == LOAD_CVMAT )
{
matrix = cvCreateMat( size.height, size.width, type );
temp = cvarrToMat(matrix);
}
else
{
mat->create( size.height, size.width, type );
data = mat;
}
}
else
{
image = cvCreateImage(cvSize(size), cvIplDepth(type), CV_MAT_CN(type));
temp = cvarrToMat(image);
}
mat.create( size.height, size.width, type );
success = false;
CV_TRY
{
if (decoder->readData(*data))
if (decoder->readData(mat))
success = true;
}
CV_CATCH (cv::Exception, e)
......@@ -867,15 +818,11 @@ imdecode_( const Mat& buf, int flags, int hdrtype, Mat* mat=0 )
if (!success)
{
cvReleaseImage( &image );
cvReleaseMat( &matrix );
if( mat )
mat->release();
return 0;
mat.release();
return false;
}
return hdrtype == LOAD_CVMAT ? (void*)matrix :
hdrtype == LOAD_IMAGE ? (void*)image : (void*)mat;
return true;
}
......@@ -884,7 +831,7 @@ Mat imdecode( InputArray _buf, int flags )
CV_TRACE_FUNCTION();
Mat buf = _buf.getMat(), img;
imdecode_( buf, flags, LOAD_MAT, &img );
imdecode_( buf, flags, img );
/// optionally rotate the data if EXIF' orientation flag says so
if( !img.empty() && (flags & IMREAD_IGNORE_ORIENTATION) == 0 && flags != IMREAD_UNCHANGED )
......@@ -901,7 +848,7 @@ Mat imdecode( InputArray _buf, int flags, Mat* dst )
Mat buf = _buf.getMat(), img;
dst = dst ? dst : &img;
imdecode_( buf, flags, LOAD_MAT, dst );
imdecode_( buf, flags, *dst );
/// optionally rotate the data if EXIF' orientation flag says so
if( !dst->empty() && (flags & IMREAD_IGNORE_ORIENTATION) == 0 && flags != IMREAD_UNCHANGED )
......@@ -924,7 +871,7 @@ bool imencode( const String& ext, InputArray _image,
ImageEncoder encoder = findEncoder( ext );
if( !encoder )
CV_Error( CV_StsError, "could not find encoder for the specified extension" );
CV_Error( Error::StsError, "could not find encoder for the specified extension" );
if( !encoder->isFormatSupported(image.depth()) )
{
......@@ -964,94 +911,18 @@ bool imencode( const String& ext, InputArray _image,
return code;
}
}
/****************************************************************************************\
* Imgcodecs loading & saving function implementation *
\****************************************************************************************/
CV_IMPL int
cvHaveImageReader( const char* filename )
bool haveImageReader( const String& filename )
{
cv::ImageDecoder decoder = cv::findDecoder(filename);
ImageDecoder decoder = cv::findDecoder(filename);
return !decoder.empty();
}
CV_IMPL int cvHaveImageWriter( const char* filename )
bool haveImageWriter( const String& filename )
{
cv::ImageEncoder encoder = cv::findEncoder(filename);
return !encoder.empty();
}
CV_IMPL IplImage*
cvLoadImage( const char* filename, int iscolor )
{
return (IplImage*)cv::imread_(filename, iscolor, cv::LOAD_IMAGE );
}
CV_IMPL CvMat*
cvLoadImageM( const char* filename, int iscolor )
{
return (CvMat*)cv::imread_( filename, iscolor, cv::LOAD_CVMAT );
}
CV_IMPL int
cvSaveImage( const char* filename, const CvArr* arr, const int* _params )
{
int i = 0;
if( _params )
{
for( ; _params[i] > 0; i += 2 )
CV_Assert(i < CV_IO_MAX_IMAGE_PARAMS*2); // Limit number of params for security reasons
}
return cv::imwrite_(filename, cv::cvarrToMat(arr),
i > 0 ? std::vector<int>(_params, _params+i) : std::vector<int>(),
CV_IS_IMAGE(arr) && ((const IplImage*)arr)->origin == IPL_ORIGIN_BL );
}
/* decode image stored in the buffer */
CV_IMPL IplImage*
cvDecodeImage( const CvMat* _buf, int iscolor )
{
CV_Assert( _buf && CV_IS_MAT_CONT(_buf->type) );
cv::Mat buf(1, _buf->rows*_buf->cols*CV_ELEM_SIZE(_buf->type), CV_8U, _buf->data.ptr);
return (IplImage*)cv::imdecode_(buf, iscolor, cv::LOAD_IMAGE );
}
CV_IMPL CvMat*
cvDecodeImageM( const CvMat* _buf, int iscolor )
{
CV_Assert( _buf && CV_IS_MAT_CONT(_buf->type) );
cv::Mat buf(1, _buf->rows*_buf->cols*CV_ELEM_SIZE(_buf->type), CV_8U, _buf->data.ptr);
return (CvMat*)cv::imdecode_(buf, iscolor, cv::LOAD_CVMAT );
}
CV_IMPL CvMat*
cvEncodeImage( const char* ext, const CvArr* arr, const int* _params )
{
int i = 0;
if( _params )
{
for( ; _params[i] > 0; i += 2 )
CV_Assert(i < CV_IO_MAX_IMAGE_PARAMS*2); // Limit number of params for security reasons
}
cv::Mat img = cv::cvarrToMat(arr);
if( CV_IS_IMAGE(arr) && ((const IplImage*)arr)->origin == IPL_ORIGIN_BL )
{
cv::Mat temp;
cv::flip(img, temp, 0);
img = temp;
}
std::vector<uchar> buf;
bool code = cv::imencode(ext, img, buf,
i > 0 ? std::vector<int>(_params, _params+i) : std::vector<int>() );
if( !code )
return 0;
CvMat* _buf = cvCreateMat(1, (int)buf.size(), CV_8U);
memcpy( _buf->data.ptr, &buf[0], buf.size() );
return _buf;
}
/* End of file. */
......@@ -48,8 +48,6 @@
#include "opencv2/core/private.hpp"
#include "opencv2/imgproc.hpp"
#include "opencv2/imgproc/imgproc_c.h"
#include "opencv2/imgcodecs/imgcodecs_c.h"
#include <stdlib.h>
#include <stdio.h>
......
......@@ -42,6 +42,9 @@
#include "precomp.hpp"
#include "utils.hpp"
namespace cv
{
int validateToInt(size_t sz)
{
int valueInt = (int)sz;
......@@ -56,7 +59,7 @@ int validateToInt(size_t sz)
void icvCvt_BGR2Gray_8u_C3C1R( const uchar* rgb, int rgb_step,
uchar* gray, int gray_step,
CvSize size, int _swap_rb )
Size size, int _swap_rb )
{
int i;
int swap_rb = _swap_rb ? 2 : 0;
......@@ -75,7 +78,7 @@ void icvCvt_BGR2Gray_8u_C3C1R( const uchar* rgb, int rgb_step,
void icvCvt_BGRA2Gray_16u_CnC1R( const ushort* rgb, int rgb_step,
ushort* gray, int gray_step,
CvSize size, int ncn, int _swap_rb )
Size size, int ncn, int _swap_rb )
{
int i;
int swap_rb = _swap_rb ? 2 : 0;
......@@ -94,7 +97,7 @@ void icvCvt_BGRA2Gray_16u_CnC1R( const ushort* rgb, int rgb_step,
void icvCvt_BGRA2Gray_8u_C4C1R( const uchar* rgba, int rgba_step,
uchar* gray, int gray_step,
CvSize size, int _swap_rb )
Size size, int _swap_rb )
{
int i;
int swap_rb = _swap_rb ? 2 : 0;
......@@ -112,7 +115,7 @@ void icvCvt_BGRA2Gray_8u_C4C1R( const uchar* rgba, int rgba_step,
void icvCvt_Gray2BGR_8u_C1C3R( const uchar* gray, int gray_step,
uchar* bgr, int bgr_step, CvSize size )
uchar* bgr, int bgr_step, Size size )
{
int i;
for( ; size.height--; gray += gray_step )
......@@ -127,7 +130,7 @@ void icvCvt_Gray2BGR_8u_C1C3R( const uchar* gray, int gray_step,
void icvCvt_Gray2BGR_16u_C1C3R( const ushort* gray, int gray_step,
ushort* bgr, int bgr_step, CvSize size )
ushort* bgr, int bgr_step, Size size )
{
int i;
for( ; size.height--; gray += gray_step/sizeof(gray[0]) )
......@@ -143,7 +146,7 @@ void icvCvt_Gray2BGR_16u_C1C3R( const ushort* gray, int gray_step,
void icvCvt_BGRA2BGR_8u_C4C3R( const uchar* bgra, int bgra_step,
uchar* bgr, int bgr_step,
CvSize size, int _swap_rb )
Size size, int _swap_rb )
{
int i;
int swap_rb = _swap_rb ? 2 : 0;
......@@ -163,7 +166,7 @@ void icvCvt_BGRA2BGR_8u_C4C3R( const uchar* bgra, int bgra_step,
void icvCvt_BGRA2BGR_16u_C4C3R( const ushort* bgra, int bgra_step,
ushort* bgr, int bgr_step,
CvSize size, int _swap_rb )
Size size, int _swap_rb )
{
int i;
int swap_rb = _swap_rb ? 2 : 0;
......@@ -182,7 +185,7 @@ void icvCvt_BGRA2BGR_16u_C4C3R( const ushort* bgra, int bgra_step,
void icvCvt_BGRA2RGBA_8u_C4R( const uchar* bgra, int bgra_step,
uchar* rgba, int rgba_step, CvSize size )
uchar* rgba, int rgba_step, Size size )
{
int i;
for( ; size.height--; )
......@@ -200,7 +203,7 @@ void icvCvt_BGRA2RGBA_8u_C4R( const uchar* bgra, int bgra_step,
}
void icvCvt_BGRA2RGBA_16u_C4R( const ushort* bgra, int bgra_step,
ushort* rgba, int rgba_step, CvSize size )
ushort* rgba, int rgba_step, Size size )
{
int i;
for( ; size.height--; )
......@@ -220,7 +223,7 @@ void icvCvt_BGRA2RGBA_16u_C4R( const ushort* bgra, int bgra_step,
void icvCvt_BGR2RGB_8u_C3R( const uchar* bgr, int bgr_step,
uchar* rgb, int rgb_step, CvSize size )
uchar* rgb, int rgb_step, Size size )
{
int i;
for( ; size.height--; )
......@@ -237,7 +240,7 @@ void icvCvt_BGR2RGB_8u_C3R( const uchar* bgr, int bgr_step,
void icvCvt_BGR2RGB_16u_C3R( const ushort* bgr, int bgr_step,
ushort* rgb, int rgb_step, CvSize size )
ushort* rgb, int rgb_step, Size size )
{
int i;
for( ; size.height--; )
......@@ -256,7 +259,7 @@ void icvCvt_BGR2RGB_16u_C3R( const ushort* bgr, int bgr_step,
typedef unsigned short ushort;
void icvCvt_BGR5552Gray_8u_C2C1R( const uchar* bgr555, int bgr555_step,
uchar* gray, int gray_step, CvSize size )
uchar* gray, int gray_step, Size size )
{
int i;
for( ; size.height--; gray += gray_step, bgr555 += bgr555_step )
......@@ -273,7 +276,7 @@ void icvCvt_BGR5552Gray_8u_C2C1R( const uchar* bgr555, int bgr555_step,
void icvCvt_BGR5652Gray_8u_C2C1R( const uchar* bgr565, int bgr565_step,
uchar* gray, int gray_step, CvSize size )
uchar* gray, int gray_step, Size size )
{
int i;
for( ; size.height--; gray += gray_step, bgr565 += bgr565_step )
......@@ -290,7 +293,7 @@ void icvCvt_BGR5652Gray_8u_C2C1R( const uchar* bgr565, int bgr565_step,
void icvCvt_BGR5552BGR_8u_C2C3R( const uchar* bgr555, int bgr555_step,
uchar* bgr, int bgr_step, CvSize size )
uchar* bgr, int bgr_step, Size size )
{
int i;
for( ; size.height--; bgr555 += bgr555_step )
......@@ -308,7 +311,7 @@ void icvCvt_BGR5552BGR_8u_C2C3R( const uchar* bgr555, int bgr555_step,
void icvCvt_BGR5652BGR_8u_C2C3R( const uchar* bgr565, int bgr565_step,
uchar* bgr, int bgr_step, CvSize size )
uchar* bgr, int bgr_step, Size size )
{
int i;
for( ; size.height--; bgr565 += bgr565_step )
......@@ -326,7 +329,7 @@ void icvCvt_BGR5652BGR_8u_C2C3R( const uchar* bgr565, int bgr565_step,
void icvCvt_CMYK2BGR_8u_C4C3R( const uchar* cmyk, int cmyk_step,
uchar* bgr, int bgr_step, CvSize size )
uchar* bgr, int bgr_step, Size size )
{
int i;
for( ; size.height--; )
......@@ -346,7 +349,7 @@ void icvCvt_CMYK2BGR_8u_C4C3R( const uchar* cmyk, int cmyk_step,
void icvCvt_CMYK2Gray_8u_C4C1R( const uchar* cmyk, int cmyk_step,
uchar* gray, int gray_step, CvSize size )
uchar* gray, int gray_step, Size size )
{
int i;
for( ; size.height--; )
......@@ -371,7 +374,7 @@ void CvtPaletteToGray( const PaletteEntry* palette, uchar* grayPalette, int entr
int i;
for( i = 0; i < entries; i++ )
{
icvCvt_BGR2Gray_8u_C3C1R( (uchar*)(palette + i), 0, grayPalette + i, 0, cvSize(1,1) );
icvCvt_BGR2Gray_8u_C3C1R( (uchar*)(palette + i), 0, grayPalette + i, 0, Size(1,1) );
}
}
......@@ -598,103 +601,4 @@ uchar* FillGrayRow1( uchar* data, uchar* indices, int len, uchar* palette )
return data;
}
CV_IMPL void
cvConvertImage( const CvArr* srcarr, CvArr* dstarr, int flags )
{
CvMat* temp = 0;
CV_FUNCNAME( "cvConvertImage" );
__BEGIN__;
CvMat srcstub, *src;
CvMat dststub, *dst;
int src_cn, dst_cn, swap_rb = flags & CV_CVTIMG_SWAP_RB;
CV_CALL( src = cvGetMat( srcarr, &srcstub ));
CV_CALL( dst = cvGetMat( dstarr, &dststub ));
src_cn = CV_MAT_CN( src->type );
dst_cn = CV_MAT_CN( dst->type );
if( src_cn != 1 && src_cn != 3 && src_cn != 4 )
CV_ERROR( CV_BadNumChannels, "Source image must have 1, 3 or 4 channels" );
if( CV_MAT_DEPTH( dst->type ) != CV_8U )
CV_ERROR( CV_BadDepth, "Destination image must be 8u" );
if( CV_MAT_CN(dst->type) != 1 && CV_MAT_CN(dst->type) != 3 )
CV_ERROR( CV_BadNumChannels, "Destination image must have 1 or 3 channels" );
if( !CV_ARE_DEPTHS_EQ( src, dst ))
{
int src_depth = CV_MAT_DEPTH(src->type);
double scale = src_depth <= CV_8S ? 1 : src_depth <= CV_32S ? 1./256 : 255;
double shift = src_depth == CV_8S || src_depth == CV_16S ? 128 : 0;
if( !CV_ARE_CNS_EQ( src, dst ))
{
temp = cvCreateMat( src->height, src->width,
(src->type & CV_MAT_CN_MASK)|(dst->type & CV_MAT_DEPTH_MASK));
cvConvertScale( src, temp, scale, shift );
src = temp;
}
else
{
cvConvertScale( src, dst, scale, shift );
src = dst;
}
}
if( src_cn != dst_cn || (src_cn == 3 && swap_rb) )
{
uchar *s = src->data.ptr, *d = dst->data.ptr;
int s_step = src->step, d_step = dst->step;
int code = src_cn*10 + dst_cn;
CvSize size = {src->cols, src->rows};
if( CV_IS_MAT_CONT(src->type & dst->type) )
{
size.width *= size.height;
size.height = 1;
s_step = d_step = /*CV_STUB_STEP*/ (1 << 30);
}
switch( code )
{
case 13:
icvCvt_Gray2BGR_8u_C1C3R( s, s_step, d, d_step, size );
break;
case 31:
icvCvt_BGR2Gray_8u_C3C1R( s, s_step, d, d_step, size, swap_rb );
break;
case 33:
CV_Assert(swap_rb);
icvCvt_RGB2BGR_8u_C3R( s, s_step, d, d_step, size );
break;
case 41:
icvCvt_BGRA2Gray_8u_C4C1R( s, s_step, d, d_step, size, swap_rb );
break;
case 43:
icvCvt_BGRA2BGR_8u_C4C3R( s, s_step, d, d_step, size, swap_rb );
break;
default:
CV_ERROR( CV_StsUnsupportedFormat, "Unsupported combination of input/output formats" );
}
src = dst;
}
if( flags & CV_CVTIMG_FLIP )
{
CV_CALL( cvFlip( src, dst, 0 ));
}
else if( src != dst )
{
CV_CALL( cvCopy( src, dst ));
}
__END__;
cvReleaseMat( &temp );
}
......@@ -42,6 +42,9 @@
#ifndef _UTILS_H_
#define _UTILS_H_
namespace cv
{
int validateToInt(size_t step);
template <typename _Tp> static inline
......@@ -68,53 +71,53 @@ struct PaletteEntry
void icvCvt_BGR2Gray_8u_C3C1R( const uchar* bgr, int bgr_step,
uchar* gray, int gray_step,
CvSize size, int swap_rb=0 );
Size size, int swap_rb=0 );
void icvCvt_BGRA2Gray_8u_C4C1R( const uchar* bgra, int bgra_step,
uchar* gray, int gray_step,
CvSize size, int swap_rb=0 );
Size size, int swap_rb=0 );
void icvCvt_BGRA2Gray_16u_CnC1R( const ushort* bgra, int bgra_step,
ushort* gray, int gray_step,
CvSize size, int ncn, int swap_rb=0 );
Size size, int ncn, int swap_rb=0 );
void icvCvt_Gray2BGR_8u_C1C3R( const uchar* gray, int gray_step,
uchar* bgr, int bgr_step, CvSize size );
uchar* bgr, int bgr_step, Size size );
void icvCvt_Gray2BGR_16u_C1C3R( const ushort* gray, int gray_step,
ushort* bgr, int bgr_step, CvSize size );
ushort* bgr, int bgr_step, Size size );
void icvCvt_BGRA2BGR_8u_C4C3R( const uchar* bgra, int bgra_step,
uchar* bgr, int bgr_step,
CvSize size, int swap_rb=0 );
Size size, int swap_rb=0 );
void icvCvt_BGRA2BGR_16u_C4C3R( const ushort* bgra, int bgra_step,
ushort* bgr, int bgr_step,
CvSize size, int _swap_rb );
Size size, int _swap_rb );
void icvCvt_BGR2RGB_8u_C3R( const uchar* bgr, int bgr_step,
uchar* rgb, int rgb_step, CvSize size );
uchar* rgb, int rgb_step, Size size );
#define icvCvt_RGB2BGR_8u_C3R icvCvt_BGR2RGB_8u_C3R
void icvCvt_BGR2RGB_16u_C3R( const ushort* bgr, int bgr_step,
ushort* rgb, int rgb_step, CvSize size );
ushort* rgb, int rgb_step, Size size );
#define icvCvt_RGB2BGR_16u_C3R icvCvt_BGR2RGB_16u_C3R
void icvCvt_BGRA2RGBA_8u_C4R( const uchar* bgra, int bgra_step,
uchar* rgba, int rgba_step, CvSize size );
uchar* rgba, int rgba_step, Size size );
#define icvCvt_RGBA2BGRA_8u_C4R icvCvt_BGRA2RGBA_8u_C4R
void icvCvt_BGRA2RGBA_16u_C4R( const ushort* bgra, int bgra_step,
ushort* rgba, int rgba_step, CvSize size );
ushort* rgba, int rgba_step, Size size );
#define icvCvt_RGBA2BGRA_16u_C4R icvCvt_BGRA2RGBA_16u_C4R
void icvCvt_BGR5552Gray_8u_C2C1R( const uchar* bgr555, int bgr555_step,
uchar* gray, int gray_step, CvSize size );
uchar* gray, int gray_step, Size size );
void icvCvt_BGR5652Gray_8u_C2C1R( const uchar* bgr565, int bgr565_step,
uchar* gray, int gray_step, CvSize size );
uchar* gray, int gray_step, Size size );
void icvCvt_BGR5552BGR_8u_C2C3R( const uchar* bgr555, int bgr555_step,
uchar* bgr, int bgr_step, CvSize size );
uchar* bgr, int bgr_step, Size size );
void icvCvt_BGR5652BGR_8u_C2C3R( const uchar* bgr565, int bgr565_step,
uchar* bgr, int bgr_step, CvSize size );
uchar* bgr, int bgr_step, Size size );
void icvCvt_CMYK2BGR_8u_C4C3R( const uchar* cmyk, int cmyk_step,
uchar* bgr, int bgr_step, CvSize size );
uchar* bgr, int bgr_step, Size size );
void icvCvt_CMYK2Gray_8u_C4C1R( const uchar* ycck, int ycck_step,
uchar* gray, int gray_step, CvSize size );
uchar* gray, int gray_step, Size size );
void FillGrayPalette( PaletteEntry* palette, int bpp, bool negative = false );
bool IsColorPalette( PaletteEntry* palette, int bpp );
......@@ -136,4 +139,6 @@ CV_INLINE bool isBigEndian( void )
return (((const int*)"\0\x1\x2\x3\x4\x5\x6\x7")[0] & 255) != 0;
}
}
#endif/*_UTILS_H_*/
......@@ -191,7 +191,10 @@ void cvtColor( InputArray _src, OutputArray _dst, int code, int dcn )
{
case COLOR_BGR2BGRA: case COLOR_RGB2BGRA: case COLOR_BGRA2BGR:
case COLOR_RGBA2BGR: case COLOR_RGB2BGR: case COLOR_BGRA2RGBA:
cvtColorBGR2BGR(_src, _dst, dcn, swapBlue(code));
if(_src.channels() == 1)
cvtColorGray2BGR(_src, _dst, dcn);
else
cvtColorBGR2BGR(_src, _dst, dcn, swapBlue(code));
break;
case COLOR_BGR2BGR565: case COLOR_BGR2BGR555: case COLOR_BGRA2BGR565: case COLOR_BGRA2BGR555:
......
......@@ -61,6 +61,12 @@ camera calibration with multiple exposures and exposure fusion.
@}
*/
enum InpaintingModes
{
CV_INPAINT_NS =0,
CV_INPAINT_TELEA =1
};
namespace cv
{
......
/*M///////////////////////////////////////////////////////////////////////////////////////
//
// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING.
//
// By downloading, copying, installing or using the software you agree to this license.
// If you do not agree to this license, do not download, install,
// copy or use the software.
//
//
// License Agreement
// For Open Source Computer Vision Library
//
// Copyright (C) 2000-2008, Intel Corporation, all rights reserved.
// Copyright (C) 2008-2012, Willow Garage Inc., all rights reserved.
// Third party copyrights are property of their respective owners.
//
// Redistribution and use in source and binary forms, with or without modification,
// are permitted provided that the following conditions are met:
//
// * Redistribution's of source code must retain the above copyright notice,
// this list of conditions and the following disclaimer.
//
// * Redistribution's in binary form must reproduce the above copyright notice,
// this list of conditions and the following disclaimer in the documentation
// and/or other materials provided with the distribution.
//
// * The name of the copyright holders may not be used to endorse or promote products
// derived from this software without specific prior written permission.
//
// This software is provided by the copyright holders and contributors "as is" and
// any express or implied warranties, including, but not limited to, the implied
// warranties of merchantability and fitness for a particular purpose are disclaimed.
// In no event shall the Intel Corporation or contributors be liable for any direct,
// indirect, incidental, special, exemplary, or consequential damages
// (including, but not limited to, procurement of substitute goods or services;
// loss of use, data, or profits; or business interruption) however caused
// and on any theory of liability, whether in contract, strict liability,
// or tort (including negligence or otherwise) arising in any way out of
// the use of this software, even if advised of the possibility of such damage.
//
//M*/
#ifndef OPENCV_PHOTO_C_H
#define OPENCV_PHOTO_C_H
#include "opencv2/core/core_c.h"
#ifdef __cplusplus
extern "C" {
#endif
/** @addtogroup photo_c
@{
*/
/* Inpainting algorithms */
enum InpaintingModes
{
CV_INPAINT_NS =0,
CV_INPAINT_TELEA =1
};
/* Inpaints the selected region in the image */
CVAPI(void) cvInpaint( const CvArr* src, const CvArr* inpaint_mask,
CvArr* dst, double inpaintRange, int flags );
/** @} */
#ifdef __cplusplus
} //extern "C"
#endif
#endif //OPENCV_PHOTO_C_H
......@@ -47,7 +47,6 @@
#include "precomp.hpp"
#include "opencv2/imgproc/imgproc_c.h"
#include "opencv2/photo/photo_c.h"
#undef CV_MAT_ELEM_PTR_FAST
#define CV_MAT_ELEM_PTR_FAST( mat, row, col, pix_size ) \
......@@ -727,8 +726,8 @@ namespace cv {
template<> struct DefaultDeleter<IplConvKernel>{ void operator ()(IplConvKernel* obj) const { cvReleaseStructuringElement(&obj); } };
}
void
cvInpaint( const CvArr* _input_img, const CvArr* _inpaint_mask, CvArr* _output_img,
static void
icvInpaint( const CvArr* _input_img, const CvArr* _inpaint_mask, CvArr* _output_img,
double inpaintRange, int flags )
{
cv::Ptr<CvMat> mask, band, f, t, out;
......@@ -847,5 +846,5 @@ void cv::inpaint( InputArray _src, InputArray _mask, OutputArray _dst,
_dst.create( src.size(), src.type() );
Mat dst = _dst.getMat();
CvMat c_src = cvMat(src), c_mask = cvMat(mask), c_dst = cvMat(dst);
cvInpaint( &c_src, &c_mask, &c_dst, inpaintRange, flags );
icvInpaint( &c_src, &c_mask, &c_dst, inpaintRange, flags );
}
......@@ -47,6 +47,14 @@
#include "opencv2/core.hpp"
#include "opencv2/imgproc.hpp"
enum
{
CV_LKFLOW_PYR_A_READY = 1,
CV_LKFLOW_PYR_B_READY = 2,
CV_LKFLOW_INITIAL_GUESSES = 4,
CV_LKFLOW_GET_MIN_EIGENVALS = 8
};
namespace cv
{
......
This diff is collapsed.
This diff is collapsed.
......@@ -40,10 +40,12 @@
//M*/
#include "test_precomp.hpp"
#include "opencv2/video/tracking_c.h"
#include "opencv2/video/tracking.hpp"
namespace opencv_test { namespace {
using namespace cv;
class CV_TrackBaseTest : public cvtest::BaseTest
{
public:
......@@ -59,10 +61,10 @@ protected:
void generate_object();
int min_log_size, max_log_size;
CvMat* img;
CvBox2D box0;
CvSize img_size;
CvTermCriteria criteria;
Mat img;
RotatedRect box0;
Size img_size;
TermCriteria criteria;
int img_type;
};
......@@ -84,7 +86,7 @@ CV_TrackBaseTest::~CV_TrackBaseTest()
void CV_TrackBaseTest::clear()
{
cvReleaseMat( &img );
img.release();
cvtest::BaseTest::clear();
}
......@@ -103,8 +105,7 @@ int CV_TrackBaseTest::read_params( const cv::FileStorage& fs )
max_log_size = cvtest::clipInt( max_log_size, 1, 10 );
if( min_log_size > max_log_size )
{
int t;
CV_SWAP( min_log_size, max_log_size, t );
std::swap( min_log_size, max_log_size );
}
return 0;
......@@ -122,13 +123,12 @@ void CV_TrackBaseTest::generate_object()
double a = sin(angle), b = -cos(angle);
double inv_ww = 1./(width*width), inv_hh = 1./(height*height);
img = cvCreateMat( img_size.height, img_size.width, img_type );
cvZero( img );
img = Mat::zeros( img_size.height, img_size.width, img_type );
// use the straightforward algorithm: for every pixel check if it is inside the ellipse
for( y = 0; y < img_size.height; y++ )
{
uchar* ptr = img->data.ptr + img->step*y;
uchar* ptr = img.ptr(y);
float* fl = (float*)ptr;
double x_ = (y - cy)*b, y_ = (y - cy)*a;
......@@ -163,8 +163,7 @@ int CV_TrackBaseTest::prepare_test_case( int test_case_idx )
if( box0.size.width > box0.size.height )
{
float t;
CV_SWAP( box0.size.width, box0.size.height, t );
std::swap( box0.size.width, box0.size.height );
}
m = MAX( box0.size.width, box0.size.height );
......@@ -176,7 +175,7 @@ int CV_TrackBaseTest::prepare_test_case( int test_case_idx )
box0.center.x = (float)(img_size.width*0.5 + (cvtest::randReal(rng)-0.5)*(img_size.width - m));
box0.center.y = (float)(img_size.height*0.5 + (cvtest::randReal(rng)-0.5)*(img_size.height - m));
criteria = cvTermCriteria( CV_TERMCRIT_EPS + CV_TERMCRIT_ITER, 10, 0.1 );
criteria = TermCriteria( TermCriteria::EPS + TermCriteria::MAX_ITER, 10, 0.1 );
generate_object();
......@@ -209,9 +208,8 @@ protected:
int validate_test_results( int test_case_idx );
void generate_object();
CvBox2D box;
CvRect init_rect;
CvConnectedComp comp;
RotatedRect box;
Rect init_rect;
int area0;
};
......@@ -231,12 +229,10 @@ int CV_CamShiftTest::prepare_test_case( int test_case_idx )
if( code <= 0 )
return code;
area0 = cvCountNonZero(img);
area0 = countNonZero(img);
for(i = 0; i < 100; i++)
{
CvMat temp;
m = MAX(box0.size.width,box0.size.height)*0.8;
init_rect.x = cvFloor(box0.center.x - m*(0.45 + cvtest::randReal(rng)*0.2));
init_rect.y = cvFloor(box0.center.y - m*(0.45 + cvtest::randReal(rng)*0.2));
......@@ -248,8 +244,8 @@ int CV_CamShiftTest::prepare_test_case( int test_case_idx )
init_rect.y + init_rect.height >= img_size.height )
continue;
cvGetSubRect( img, &temp, init_rect );
area = cvCountNonZero( &temp );
Mat temp = img(init_rect);
area = countNonZero( temp );
if( area >= 0.1*area0 )
break;
......@@ -261,7 +257,7 @@ int CV_CamShiftTest::prepare_test_case( int test_case_idx )
void CV_CamShiftTest::run_func(void)
{
cvCamShift( img, init_rect, criteria, &comp, &box );
box = CamShift( img, init_rect, criteria );
}
......@@ -269,15 +265,14 @@ int CV_CamShiftTest::validate_test_results( int /*test_case_idx*/ )
{
int code = cvtest::TS::OK;
double m = MAX(box0.size.width, box0.size.height), delta;
double m = MAX(box0.size.width, box0.size.height);
double diff_angle;
if( cvIsNaN(box.size.width) || cvIsInf(box.size.width) || box.size.width <= 0 ||
cvIsNaN(box.size.height) || cvIsInf(box.size.height) || box.size.height <= 0 ||
cvIsNaN(box.center.x) || cvIsInf(box.center.x) ||
cvIsNaN(box.center.y) || cvIsInf(box.center.y) ||
cvIsNaN(box.angle) || cvIsInf(box.angle) || box.angle < -180 || box.angle > 180 ||
cvIsNaN(comp.area) || cvIsInf(comp.area) || comp.area <= 0 )
cvIsNaN(box.angle) || cvIsInf(box.angle) || box.angle < -180 || box.angle > 180 )
{
ts->printf( cvtest::TS::LOG, "Invalid CvBox2D or CvConnectedComp was returned by cvCamShift\n" );
code = cvtest::TS::FAIL_INVALID_OUTPUT;
......@@ -318,29 +313,6 @@ int CV_CamShiftTest::validate_test_results( int /*test_case_idx*/ )
goto _exit_;
}
delta = m*0.7;
if( comp.rect.x < box0.center.x - delta ||
comp.rect.y < box0.center.y - delta ||
comp.rect.x + comp.rect.width > box0.center.x + delta ||
comp.rect.y + comp.rect.height > box0.center.y + delta )
{
ts->printf( cvtest::TS::LOG,
"Incorrect CvConnectedComp ((%d,%d,%d,%d) is not within (%.1f,%.1f,%.1f,%.1f))\n",
comp.rect.x, comp.rect.y, comp.rect.x + comp.rect.width, comp.rect.y + comp.rect.height,
box0.center.x - delta, box0.center.y - delta, box0.center.x + delta, box0.center.y + delta );
code = cvtest::TS::FAIL_BAD_ACCURACY;
goto _exit_;
}
if( fabs(comp.area - area0) > area0*0.15 )
{
ts->printf( cvtest::TS::LOG,
"Incorrect CvConnectedComp area (=%.1f, should be %d)\n", comp.area, area0 );
code = cvtest::TS::FAIL_BAD_ACCURACY;
goto _exit_;
}
_exit_:
if( code < 0 )
......@@ -377,8 +349,7 @@ protected:
int validate_test_results( int test_case_idx );
void generate_object();
CvRect init_rect;
CvConnectedComp comp;
Rect init_rect, rect;
int area0, area;
};
......@@ -398,12 +369,10 @@ int CV_MeanShiftTest::prepare_test_case( int test_case_idx )
if( code <= 0 )
return code;
area0 = cvCountNonZero(img);
area0 = countNonZero(img);
for(i = 0; i < 100; i++)
{
CvMat temp;
m = (box0.size.width + box0.size.height)*0.5;
init_rect.x = cvFloor(box0.center.x - m*(0.4 + cvtest::randReal(rng)*0.2));
init_rect.y = cvFloor(box0.center.y - m*(0.4 + cvtest::randReal(rng)*0.2));
......@@ -415,8 +384,8 @@ int CV_MeanShiftTest::prepare_test_case( int test_case_idx )
init_rect.y + init_rect.height >= img_size.height )
continue;
cvGetSubRect( img, &temp, init_rect );
area = cvCountNonZero( &temp );
Mat temp = img(init_rect);
area = countNonZero( temp );
if( area >= 0.5*area0 )
break;
......@@ -428,7 +397,8 @@ int CV_MeanShiftTest::prepare_test_case( int test_case_idx )
void CV_MeanShiftTest::run_func(void)
{
cvMeanShift( img, init_rect, criteria, &comp );
rect = init_rect;
meanShift( img, rect, criteria );
}
......@@ -438,15 +408,8 @@ int CV_MeanShiftTest::validate_test_results( int /*test_case_idx*/ )
Point2f c;
double m = MAX(box0.size.width, box0.size.height), delta;
if( cvIsNaN(comp.area) || cvIsInf(comp.area) || comp.area <= 0 )
{
ts->printf( cvtest::TS::LOG, "Invalid CvConnectedComp was returned by cvMeanShift\n" );
code = cvtest::TS::FAIL_INVALID_OUTPUT;
goto _exit_;
}
c.x = (float)(comp.rect.x + comp.rect.width*0.5);
c.y = (float)(comp.rect.y + comp.rect.height*0.5);
c.x = (float)(rect.x + rect.width*0.5);
c.y = (float)(rect.y + rect.height*0.5);
if( fabs(c.x - box0.center.x) > m*0.1 ||
fabs(c.y - box0.center.y) > m*0.1 )
......@@ -459,25 +422,16 @@ int CV_MeanShiftTest::validate_test_results( int /*test_case_idx*/ )
delta = m*0.7;
if( comp.rect.x < box0.center.x - delta ||
comp.rect.y < box0.center.y - delta ||
comp.rect.x + comp.rect.width > box0.center.x + delta ||
comp.rect.y + comp.rect.height > box0.center.y + delta )
if( rect.x < box0.center.x - delta ||
rect.y < box0.center.y - delta ||
rect.x + rect.width > box0.center.x + delta ||
rect.y + rect.height > box0.center.y + delta )
{
ts->printf( cvtest::TS::LOG,
"Incorrect CvConnectedComp ((%d,%d,%d,%d) is not within (%.1f,%.1f,%.1f,%.1f))\n",
comp.rect.x, comp.rect.y, comp.rect.x + comp.rect.width, comp.rect.y + comp.rect.height,
rect.x, rect.y, rect.x + rect.width, rect.y + rect.height,
box0.center.x - delta, box0.center.y - delta, box0.center.x + delta, box0.center.y + delta );
code = cvtest::TS::FAIL_BAD_ACCURACY;
goto _exit_;
}
if( fabs((double)(comp.area - area0)) > fabs((double)(area - area0)) + area0*0.05 )
{
ts->printf( cvtest::TS::LOG,
"Incorrect CvConnectedComp area (=%.1f, should be %d)\n", comp.area, area0 );
code = cvtest::TS::FAIL_BAD_ACCURACY;
goto _exit_;
}
_exit_:
......
......@@ -40,7 +40,7 @@
//M*/
#include "test_precomp.hpp"
#include "opencv2/video/tracking_c.h"
#include "opencv2/video/tracking.hpp"
namespace opencv_test { namespace {
......@@ -67,54 +67,41 @@ void CV_KalmanTest::run( int )
const double EPSILON = 1.000;
RNG& rng = ts->get_rng();
CvKalman* Kalm;
int i, j;
CvMat* Sample = cvCreateMat(Dim,1,CV_32F);
CvMat* Temp = cvCreateMat(Dim,1,CV_32F);
cv::Mat Sample(Dim,1,CV_32F);
cv::Mat Temp(Dim,1,CV_32F);
Kalm = cvCreateKalman(Dim, Dim);
CvMat Dyn = cvMat(Dim,Dim,CV_32F,Kalm->DynamMatr);
CvMat Mes = cvMat(Dim,Dim,CV_32F,Kalm->MeasurementMatr);
CvMat PNC = cvMat(Dim,Dim,CV_32F,Kalm->PNCovariance);
CvMat MNC = cvMat(Dim,Dim,CV_32F,Kalm->MNCovariance);
CvMat PriErr = cvMat(Dim,Dim,CV_32F,Kalm->PriorErrorCovariance);
CvMat PostErr = cvMat(Dim,Dim,CV_32F,Kalm->PosterErrorCovariance);
CvMat PriState = cvMat(Dim,1,CV_32F,Kalm->PriorState);
CvMat PostState = cvMat(Dim,1,CV_32F,Kalm->PosterState);
cvSetIdentity(&PNC);
cvSetIdentity(&PriErr);
cvSetIdentity(&PostErr);
cvSetZero(&MNC);
cvSetZero(&PriState);
cvSetZero(&PostState);
cvSetIdentity(&Mes);
cvSetIdentity(&Dyn);
Mat _Sample = cvarrToMat(Sample);
cvtest::randUni(rng, _Sample, cvScalarAll(-max_init), cvScalarAll(max_init));
cvKalmanCorrect(Kalm, Sample);
cv::KalmanFilter Kalm(Dim, Dim);
Kalm.transitionMatrix = cv::Mat::eye(Dim, Dim, CV_32F);
Kalm.measurementMatrix = cv::Mat::eye(Dim, Dim, CV_32F);
Kalm.processNoiseCov = cv::Mat::eye(Dim, Dim, CV_32F);
Kalm.errorCovPre = cv::Mat::eye(Dim, Dim, CV_32F);
Kalm.errorCovPost = cv::Mat::eye(Dim, Dim, CV_32F);
Kalm.measurementNoiseCov = cv::Mat::zeros(Dim, Dim, CV_32F);
Kalm.statePre = cv::Mat::zeros(Dim, 1, CV_32F);
Kalm.statePost = cv::Mat::zeros(Dim, 1, CV_32F);
cvtest::randUni(rng, Sample, Scalar::all(-max_init), Scalar::all(max_init));
Kalm.correct(Sample);
for(i = 0; i<Steps; i++)
{
cvKalmanPredict(Kalm);
Kalm.predict();
const Mat& Dyn = Kalm.transitionMatrix;
for(j = 0; j<Dim; j++)
{
float t = 0;
for(int k=0; k<Dim; k++)
{
t += Dyn.data.fl[j*Dim+k]*Sample->data.fl[k];
t += Dyn.at<float>(j,k)*Sample.at<float>(k);
}
Temp->data.fl[j]= (float)(t+(cvtest::randReal(rng)*2-1)*max_noise);
Temp.at<float>(j) = (float)(t+(cvtest::randReal(rng)*2-1)*max_noise);
}
cvCopy( Temp, Sample );
cvKalmanCorrect(Kalm,Temp);
Temp.copyTo(Sample);
Kalm.correct(Temp);
}
Mat _state_post = cvarrToMat(Kalm->state_post);
code = cvtest::cmpEps2( ts, _Sample, _state_post, EPSILON, false, "The final estimated state" );
cvReleaseMat(&Sample);
cvReleaseMat(&Temp);
cvReleaseKalman(&Kalm);
Mat _state_post = Kalm.statePost;
code = cvtest::cmpEps2( ts, Sample, _state_post, EPSILON, false, "The final estimated state" );
if( code < 0 )
ts->set_failed_test_info( code );
......
......@@ -40,7 +40,6 @@
//M*/
#include "test_precomp.hpp"
#include "opencv2/video/tracking_c.h"
namespace opencv_test { namespace {
......@@ -71,7 +70,7 @@ void CV_OptFlowPyrLKTest::run( int )
int merr_i = 0, merr_j = 0, merr_k = 0, merr_nan = 0;
char filename[1000];
CvPoint2D32f *v = 0, *v2 = 0;
cv::Point2f *v = 0, *v2 = 0;
cv::Mat _u, _v, _v2;
cv::Mat imgI, imgJ;
......@@ -145,8 +144,8 @@ void CV_OptFlowPyrLKTest::run( int )
calcOpticalFlowPyrLK(imgI, imgJ, _u, _v2, status, cv::noArray(), Size( 41, 41 ), 4,
TermCriteria( TermCriteria::MAX_ITER + TermCriteria::EPS, 30, 0.01f ), 0 );
v = (CvPoint2D32f*)_v.ptr();
v2 = (CvPoint2D32f*)_v2.ptr();
v = (cv::Point2f*)_v.ptr();
v2 = (cv::Point2f*)_v2.ptr();
/* compare results */
for( i = 0; i < n; i++ )
......
......@@ -578,7 +578,10 @@ bool CvCaptureCAM_DC1394_v2_CPP::grabFrame()
// Swap R&B channels:
if (nch==3)
cvConvertImage(&fhdr,&fhdr,CV_CVTIMG_SWAP_RB);
{
cv::Mat tmp = cv::cvarrToMat(&fhdr);
cv::cvtColor(tmp, tmp, cv::COLOR_RGB2BGR, tmp.channels());
}
cvCopy(&fhdr, img[i]);
}
......
......@@ -50,6 +50,7 @@
//
#include "precomp.hpp"
#include "opencv2/imgcodecs.hpp"
#include <sys/stat.h>
#ifdef NDEBUG
......@@ -62,81 +63,90 @@
#define _MAX_PATH 1024
#endif
class CvCapture_Images : public CvCapture
namespace cv
{
class CvCapture_Images: public IVideoCapture
{
public:
CvCapture_Images()
void init()
{
filename = NULL;
filename.clear();
frame.release();
currentframe = firstframe = 0;
length = 0;
frame = NULL;
grabbedInOpen = false;
}
CvCapture_Images()
{
init();
}
CvCapture_Images(const String& _filename)
{
init();
open(_filename);
}
virtual ~CvCapture_Images() CV_OVERRIDE
{
close();
}
virtual bool open(const char* _filename);
virtual void close();
virtual double getProperty(int) const CV_OVERRIDE;
virtual bool setProperty(int, double) CV_OVERRIDE;
virtual bool grabFrame() CV_OVERRIDE;
virtual IplImage* retrieveFrame(int) CV_OVERRIDE;
virtual bool retrieveFrame(int, OutputArray) CV_OVERRIDE;
virtual bool isOpened() const CV_OVERRIDE;
virtual int getCaptureDomain() /*const*/ CV_OVERRIDE { return cv::CAP_IMAGES; }
int getCaptureDomain() /*const*/ CV_OVERRIDE { return cv::CAP_IMAGES; }
bool open(const String&);
void close();
protected:
char* filename; // actually a printf-pattern
std::string filename; // actually a printf-pattern
unsigned currentframe;
unsigned firstframe; // number of first frame
unsigned length; // length of sequence
IplImage* frame;
Mat frame;
bool grabbedInOpen;
};
void CvCapture_Images::close()
{
if( filename )
{
free(filename);
filename = NULL;
}
currentframe = firstframe = 0;
length = 0;
cvReleaseImage( &frame );
init();
}
bool CvCapture_Images::grabFrame()
{
char str[_MAX_PATH];
sprintf(str, filename, firstframe + currentframe);
if( filename.empty() )
return false;
sprintf(str, filename.c_str(), firstframe + currentframe);
if (grabbedInOpen)
{
grabbedInOpen = false;
++currentframe;
return frame != NULL;
return !frame.empty();
}
cvReleaseImage(&frame);
frame = cvLoadImage(str, CV_LOAD_IMAGE_UNCHANGED);
if( frame )
frame = imread(str, CV_LOAD_IMAGE_UNCHANGED);
if( !frame.empty() )
currentframe++;
return frame != NULL;
return !frame.empty();
}
IplImage* CvCapture_Images::retrieveFrame(int)
bool CvCapture_Images::retrieveFrame(int, OutputArray out)
{
return grabbedInOpen ? NULL : frame;
frame.copyTo(out);
return grabbedInOpen ? false : !frame.empty();
}
double CvCapture_Images::getProperty(int id) const
{
switch(id)
......@@ -151,9 +161,9 @@ double CvCapture_Images::getProperty(int id) const
case CV_CAP_PROP_POS_AVI_RATIO:
return (double)currentframe / (double)(length - 1);
case CV_CAP_PROP_FRAME_WIDTH:
return frame ? frame->width : 0;
return frame.cols;
case CV_CAP_PROP_FRAME_HEIGHT:
return frame ? frame->height : 0;
return frame.rows;
case CV_CAP_PROP_FPS:
CV_WARN("collections of images don't have framerates\n");
return 1;
......@@ -199,25 +209,25 @@ bool CvCapture_Images::setProperty(int id, double value)
return false;
}
static char* icvExtractPattern(const char *filename, unsigned *offset)
static std::string extractPattern(const std::string& filename, unsigned& offset)
{
char *name = (char *)filename;
std::string name;
if( !filename )
return 0;
if( filename.empty() )
return std::string();
// check whether this is a valid image sequence filename
char *at = strchr(name, '%');
char *at = strchr((char*)filename.c_str(), '%');
if(at)
{
unsigned int dummy;
if(sscanf(at + 1, "%ud", &dummy) != 1)
return 0;
name = strdup(filename);
return std::string();
name = filename;
}
else // no pattern filename was given - extract the pattern
{
at = name;
at = (char*)filename.c_str();
// ignore directory names
char *slash = strrchr(at, '/');
......@@ -231,17 +241,12 @@ static char* icvExtractPattern(const char *filename, unsigned *offset)
while (*at && !isdigit(*at)) at++;
if(!*at)
return 0;
return std::string();
sscanf(at, "%u", offset);
sscanf(at, "%u", &offset);
int size = (int)strlen(filename) + 20;
name = (char *)malloc(size);
CV_Assert(name != NULL);
strncpy(name, filename, at - filename);
name[at - filename] = 0;
strcat(name, "%0");
name = filename.substr(0, at - filename.c_str());
name += "%0";
int i;
char *extension;
......@@ -250,21 +255,21 @@ static char* icvExtractPattern(const char *filename, unsigned *offset)
char places[13] = {0};
sprintf(places, "%dd", i);
strcat(name, places);
strcat(name, extension);
name += places;
name += extension;
}
return name;
}
bool CvCapture_Images::open(const char * _filename)
bool CvCapture_Images::open(const std::string& _filename)
{
unsigned offset = 0;
close();
filename = icvExtractPattern(_filename, &offset);
if(!filename)
filename = extractPattern(_filename, offset);
if( filename.empty() )
return false;
// determine the length of the sequence
......@@ -272,7 +277,7 @@ bool CvCapture_Images::open(const char * _filename)
char str[_MAX_PATH];
for(;;)
{
sprintf(str, filename, offset + length);
sprintf(str, filename.c_str(), offset + length);
struct stat s;
if(stat(str, &s))
{
......@@ -283,7 +288,7 @@ bool CvCapture_Images::open(const char * _filename)
}
}
if(!cvHaveImageReader(str))
if(!haveImageReader(filename))
break;
length++;
......@@ -305,16 +310,19 @@ bool CvCapture_Images::open(const char * _filename)
return grabRes;
}
CvCapture* cvCreateFileCapture_Images(const char * filename)
bool CvCapture_Images::isOpened() const
{
CvCapture_Images* capture = new CvCapture_Images;
return !filename.empty();
}
if( capture->open(filename) )
Ptr<IVideoCapture> createFileCapture_Images(const String& filename)
{
Ptr<IVideoCapture> capture(new CvCapture_Images(filename));
if( capture->isOpened() )
return capture;
return Ptr<IVideoCapture>();
}
delete capture;
return NULL;
}
//
......@@ -327,7 +335,7 @@ class CvVideoWriter_Images CV_FINAL : public CvVideoWriter
public:
CvVideoWriter_Images()
{
filename = 0;
filename.clear();
currentframe = 0;
}
virtual ~CvVideoWriter_Images() { close(); }
......@@ -339,7 +347,7 @@ public:
int getCaptureDomain() const CV_OVERRIDE { return cv::CAP_IMAGES; }
protected:
char* filename;
std::string filename;
unsigned currentframe;
std::vector<int> params;
};
......@@ -347,24 +355,21 @@ protected:
bool CvVideoWriter_Images::writeFrame( const IplImage* image )
{
char str[_MAX_PATH];
sprintf(str, filename, currentframe);
sprintf(str, filename.c_str(), currentframe);
std::vector<int> image_params = params;
image_params.push_back(0); // append parameters 'stop' mark
image_params.push_back(0);
int ret = cvSaveImage(str, image, &image_params[0]);
cv::Mat img = cv::cvarrToMat(image);
bool ret = cv::imwrite(str, img, image_params);
currentframe++;
return ret > 0;
return ret;
}
void CvVideoWriter_Images::close()
{
if( filename )
{
free( filename );
filename = 0;
}
filename.clear();
currentframe = 0;
params.clear();
}
......@@ -376,13 +381,13 @@ bool CvVideoWriter_Images::open( const char* _filename )
close();
filename = icvExtractPattern(_filename, &offset);
if(!filename)
filename = cv::extractPattern(_filename, offset);
if(filename.empty())
return false;
char str[_MAX_PATH];
sprintf(str, filename, 0);
if(!cvHaveImageWriter(str))
sprintf(str, filename.c_str(), 0);
if(!cv::haveImageWriter(str))
{
close();
return false;
......
......@@ -54,7 +54,6 @@
#include "opencv2/imgproc.hpp"
#include "opencv2/imgproc/imgproc_c.h"
#include "opencv2/imgcodecs/imgcodecs_c.h"
#include "opencv2/videoio/videoio_c.h"
#include <stdlib.h>
......@@ -124,7 +123,6 @@ CvCapture* cvCreateCameraCapture_XIMEA( const char* serialNumber );
CvCapture* cvCreateCameraCapture_AVFoundation(int index);
CvCapture* cvCreateCameraCapture_Aravis( int index );
CvCapture* cvCreateFileCapture_Images(const char* filename);
CvVideoWriter* cvCreateVideoWriter_Images(const char* filename);
......@@ -176,6 +174,8 @@ namespace cv
virtual int getCaptureDomain() const { return cv::CAP_ANY; } // Return the type of the capture object: CAP_FFMPEG, etc...
};
Ptr<IVideoCapture> createFileCapture_Images(const String& filename);
Ptr<IVideoCapture> createMotionJpegCapture(const String& filename);
Ptr<IVideoWriter> createMotionJpegWriter(const String& filename, int fourcc, double fps, Size frameSize, bool iscolor);
......
......@@ -487,6 +487,7 @@ void VideoCapture_create(CvCapture*& capture, Ptr<IVideoCapture>& icap, VideoCap
void VideoCapture_create(CvCapture*& capture, Ptr<IVideoCapture>& icap, VideoCaptureAPIs api, const cv::String& filename)
{
CV_UNUSED(capture);
switch (api)
{
default:
......@@ -521,7 +522,7 @@ void VideoCapture_create(CvCapture*& capture, Ptr<IVideoCapture>& icap, VideoCap
break;
#endif
case CAP_IMAGES:
TRY_OPEN_LEGACY(cvCreateFileCapture_Images(filename.c_str()))
TRY_OPEN(createFileCapture_Images(filename))
break;
#ifdef HAVE_FFMPEG
case CAP_FFMPEG:
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment