Skip to content

Commit 11eafca

Browse files
authored
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
1 parent 5087ff0 commit 11eafca

34 files changed

Lines changed: 389 additions & 1403 deletions

modules/highgui/include/opencv2/highgui/highgui_c.h

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -44,12 +44,6 @@
4444

4545
#include "opencv2/core/core_c.h"
4646
#include "opencv2/imgproc/imgproc_c.h"
47-
#ifdef HAVE_OPENCV_IMGCODECS
48-
#include "opencv2/imgcodecs/imgcodecs_c.h"
49-
#endif
50-
#ifdef HAVE_OPENCV_VIDEOIO
51-
#include "opencv2/videoio/videoio_c.h"
52-
#endif
5347

5448
#ifdef __cplusplus
5549
extern "C" {

modules/highgui/src/precomp.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,11 +47,11 @@
4747
#include "opencv2/core/utility.hpp"
4848
#include "opencv2/core/private.hpp"
4949

50+
#include "opencv2/imgproc.hpp"
5051
#include "opencv2/imgproc/imgproc_c.h"
5152
#include "opencv2/highgui/highgui_c.h"
5253

5354
#include "opencv2/imgcodecs.hpp"
54-
#include "opencv2/imgcodecs/imgcodecs_c.h"
5555

5656
#include <stdlib.h>
5757
#include <stdio.h>

modules/highgui/src/window_QT.cpp

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2555,8 +2555,10 @@ void DefaultViewPort::updateImage(const CvArr* arr)
25552555
}
25562556

25572557
nbChannelOriginImage = cvGetElemType(mat);
2558-
2559-
cvConvertImage(mat, image2Draw_mat, (origin != 0 ? CV_CVTIMG_FLIP : 0) + CV_CVTIMG_SWAP_RB);
2558+
CV_Assert(origin == 0);
2559+
cv::Mat src = cv::cvarrToMat(mat), dst = cv::cvarrToMat(image2Draw_mat);
2560+
cv::cvtColor(src, dst, cv::COLOR_BGR2RGB, dst.channels());
2561+
CV_Assert(dst.data == image2Draw_mat->data.ptr);
25602562

25612563
viewport()->update();
25622564
}
@@ -3002,7 +3004,7 @@ void DefaultViewPort::drawStatusBar()
30023004

30033005
if (nbChannelOriginImage==CV_8UC1)
30043006
{
3005-
//all the channel have the same value (because of cvconvertimage), so only the r channel is dsplayed
3007+
//all the channel have the same value (because of cv::cvtColor(GRAY=>RGB)), so only the r channel is dsplayed
30063008
centralWidget->myStatusBar_msg->setText(tr("<font color='black'>(x=%1, y=%2) ~ </font>")
30073009
.arg(mouseCoordinate.x())
30083010
.arg(mouseCoordinate.y())+

modules/highgui/src/window_cocoa.mm

Lines changed: 12 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@
4141
//
4242
//M*/
4343
#include "precomp.hpp"
44+
#include "opencv2/imgproc.hpp"
4445

4546
#import <TargetConditionals.h>
4647

@@ -910,9 +911,8 @@ - (id)init {
910911
- (void)setImageData:(CvArr *)arr {
911912
//cout << "setImageData" << endl;
912913
NSAutoreleasePool* localpool = [[NSAutoreleasePool alloc] init];
913-
CvMat *arrMat, dst, stub;
914914

915-
arrMat = cvGetMat(arr, &stub);
915+
cv::Mat arrMat = cv::cvarrToMat(arr);
916916
/*CGColorSpaceRef colorspace = NULL;
917917
CGDataProviderRef provider = NULL;
918918
int width = cvimage->width;
@@ -933,40 +933,35 @@ - (void)setImageData:(CvArr *)arr {
933933
}*/
934934

935935
NSBitmapImageRep *bitmap = [[NSBitmapImageRep alloc] initWithBitmapDataPlanes:NULL
936-
pixelsWide:arrMat->cols
937-
pixelsHigh:arrMat->rows
936+
pixelsWide:arrMat.cols
937+
pixelsHigh:arrMat.rows
938938
bitsPerSample:8
939939
samplesPerPixel:3
940940
hasAlpha:NO
941941
isPlanar:NO
942942
colorSpaceName:NSDeviceRGBColorSpace
943943
bitmapFormat: kCGImageAlphaNone
944-
bytesPerRow:((arrMat->cols * 3 + 3) & -4)
944+
bytesPerRow:((arrMat.cols * 3 + 3) & -4)
945945
bitsPerPixel:24];
946946

947947
if (bitmap) {
948-
cvInitMatHeader(&dst, arrMat->rows, arrMat->cols, CV_8UC3, [bitmap bitmapData], [bitmap bytesPerRow]);
949-
cvConvertImage(arrMat, &dst, CV_CVTIMG_SWAP_RB);
948+
cv::Mat dst(arrMat.rows, arrMat.cols, CV_8UC3, [bitmap bitmapData], [bitmap bytesPerRow]);
949+
cv::cvtColor(arrMat, dst, cv::COLOR_BGR2RGB);
950950
}
951951
else {
952952
// It's not guaranteed to like the bitsPerPixel:24, but this is a lot slower so we'd rather not do it
953953
bitmap = [[NSBitmapImageRep alloc] initWithBitmapDataPlanes:NULL
954-
pixelsWide:arrMat->cols
955-
pixelsHigh:arrMat->rows
954+
pixelsWide:arrMat.cols
955+
pixelsHigh:arrMat.rows
956956
bitsPerSample:8
957957
samplesPerPixel:3
958958
hasAlpha:NO
959959
isPlanar:NO
960960
colorSpaceName:NSDeviceRGBColorSpace
961-
bytesPerRow:(arrMat->cols * 4)
961+
bytesPerRow:(arrMat.cols * 4)
962962
bitsPerPixel:32];
963-
uint8_t *data = [bitmap bitmapData];
964-
cvInitMatHeader(&dst, arrMat->rows, arrMat->cols, CV_8UC3, data, (arrMat->cols * 3));
965-
cvConvertImage(arrMat, &dst, CV_CVTIMG_SWAP_RB);
966-
for (int i = (arrMat->rows * arrMat->cols) - 1; i >= 0; i--) {
967-
memmove(data + i * 4, data + i * 3, 3);
968-
data[i * 4 + 3] = 0;
969-
}
963+
cv::Mat dst(arrMat.rows, arrMat.cols, CV_8UC3, [bitmap bitmapData], [bitmap bytesPerRow]);
964+
cv::cvtColor(arrMat, dst, cv::COLOR_BGR2RGBA);
970965
}
971966

972967
if( image ) {

modules/highgui/src/window_gtk.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -140,8 +140,10 @@ void cvImageWidgetSetImage(CvImageWidget * widget, const CvArr *arr){
140140
widget->original_image = cvCreateMat( mat->rows, mat->cols, CV_8UC3 );
141141
gtk_widget_queue_resize( GTK_WIDGET( widget ) );
142142
}
143-
cvConvertImage( mat, widget->original_image,
144-
(origin != 0 ? CV_CVTIMG_FLIP : 0) + CV_CVTIMG_SWAP_RB );
143+
CV_Assert(origin == 0);
144+
cv::Mat src = cv::cvarrToMat(arr), dst = cv::cvarrToMat(widget->original_image);
145+
cv::cvtColor(src, dst, cv::COLOR_BGR2RGB, dst.channels());
146+
CV_Assert(dst.data == widget->original_image->data.ptr);
145147
if(widget->scaled_image){
146148
cvResize( widget->original_image, widget->scaled_image, CV_INTER_AREA );
147149
}

modules/highgui/src/window_w32.cpp

Lines changed: 21 additions & 84 deletions
Original file line numberDiff line numberDiff line change
@@ -1155,7 +1155,7 @@ cvShowImage( const char* name, const CvArr* arr )
11551155
void* dst_ptr = 0;
11561156
const int channels0 = 3;
11571157
int origin = 0;
1158-
CvMat stub, dst, *image;
1158+
CvMat stub, *image;
11591159
bool changed_size = false; // philipg
11601160

11611161
if( !name )
@@ -1209,9 +1209,26 @@ cvShowImage( const char* name, const CvArr* arr )
12091209
DIB_RGB_COLORS, &dst_ptr, 0, 0));
12101210
}
12111211

1212-
cvInitMatHeader( &dst, size.cy, size.cx, CV_8UC3,
1213-
dst_ptr, (size.cx * channels + 3) & -4 );
1214-
cvConvertImage( image, &dst, origin == 0 ? CV_CVTIMG_FLIP : 0 );
1212+
{
1213+
cv::Mat src = cv::cvarrToMat(image);
1214+
cv::Mat dst(size.cy, size.cx, CV_8UC3, dst_ptr, (size.cx * channels + 3) & -4);
1215+
if (src.channels() == 1)
1216+
{
1217+
cv::cvtColor(src, dst, cv::COLOR_GRAY2BGR);
1218+
cv::flip(dst, dst, 0);
1219+
}
1220+
else if (src.channels() == 4)
1221+
{
1222+
cv::cvtColor(src, dst, cv::COLOR_BGRA2BGR);
1223+
cv::flip(dst, dst, 0);
1224+
}
1225+
else
1226+
{
1227+
CV_Assert(src.channels() == 3);
1228+
cv::flip(src, dst, 0);
1229+
}
1230+
CV_Assert(dst.data == (uchar*)dst_ptr);
1231+
}
12151232

12161233
// ony resize window if needed
12171234
if (changed_size)
@@ -1223,86 +1240,6 @@ cvShowImage( const char* name, const CvArr* arr )
12231240
__END__;
12241241
}
12251242

1226-
#if 0
1227-
CV_IMPL void
1228-
cvShowImageHWND(HWND w_hWnd, const CvArr* arr)
1229-
{
1230-
CV_FUNCNAME( "cvShowImageHWND" );
1231-
1232-
__BEGIN__;
1233-
1234-
SIZE size = { 0, 0 };
1235-
int channels = 0;
1236-
void* dst_ptr = 0;
1237-
const int channels0 = 3;
1238-
int origin = 0;
1239-
CvMat stub, dst, *image;
1240-
bool changed_size = false;
1241-
BITMAPINFO tempbinfo;
1242-
HDC hdc = NULL;
1243-
1244-
if( !arr )
1245-
EXIT;
1246-
if( !w_hWnd )
1247-
EXIT;
1248-
1249-
hdc = GetDC(w_hWnd);
1250-
1251-
if( CV_IS_IMAGE_HDR( arr ) )
1252-
origin = ((IplImage*)arr)->origin;
1253-
1254-
CV_CALL( image = cvGetMat( arr, &stub ) );
1255-
1256-
if ( hdc )
1257-
{
1258-
//GetBitmapData
1259-
BITMAP bmp;
1260-
GdiFlush();
1261-
HGDIOBJ h = GetCurrentObject( hdc, OBJ_BITMAP );
1262-
1263-
if (h == NULL)
1264-
EXIT;
1265-
if (GetObject(h, sizeof(bmp), &bmp) == 0) //GetObject(): returns size of object, 0 if error
1266-
EXIT;
1267-
1268-
channels = bmp.bmBitsPixel/8;
1269-
dst_ptr = bmp.bmBits;
1270-
}
1271-
1272-
if( size.cx != image->width || size.cy != image->height || channels != channels0 )
1273-
{
1274-
changed_size = true;
1275-
1276-
uchar buffer[sizeof(BITMAPINFO) + 255*sizeof(RGBQUAD)];
1277-
BITMAPINFO* binfo = (BITMAPINFO*)buffer;
1278-
1279-
BOOL bDeleteObj = DeleteObject(GetCurrentObject(hdc, OBJ_BITMAP));
1280-
CV_Assert( FALSE != bDeleteObj );
1281-
1282-
size.cx = image->width;
1283-
size.cy = image->height;
1284-
channels = channels0;
1285-
1286-
FillBitmapInfo( binfo, size.cx, size.cy, channels*8, 1 );
1287-
1288-
SelectObject( hdc, CreateDIBSection( hdc, binfo, DIB_RGB_COLORS, &dst_ptr, 0, 0));
1289-
}
1290-
1291-
cvInitMatHeader( &dst, size.cy, size.cx, CV_8UC3, dst_ptr, (size.cx * channels + 3) & -4 );
1292-
cvConvertImage( image, &dst, origin == 0 ? CV_CVTIMG_FLIP : 0 );
1293-
1294-
// Image stretching to fit the window
1295-
RECT rect;
1296-
GetClientRect(w_hWnd, &rect);
1297-
StretchDIBits( hdc, 0, 0, rect.right, rect.bottom, 0, 0, image->width, image->height, dst_ptr, &tempbinfo, DIB_RGB_COLORS, SRCCOPY );
1298-
1299-
// ony resize window if needed
1300-
InvalidateRect(w_hWnd, 0, 0);
1301-
1302-
__END__;
1303-
}
1304-
#endif
1305-
13061243
CV_IMPL void cvResizeWindow(const char* name, int width, int height )
13071244
{
13081245
CV_FUNCNAME( "cvResizeWindow" );

modules/imgcodecs/include/opencv2/imgcodecs.hpp

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,52 @@
5353
@}
5454
*/
5555

56+
/* duplicate of "ImreadModes" enumeration for better compatibility with OpenCV 3.x */
57+
enum
58+
{
59+
/* 8bit, color or not */
60+
CV_LOAD_IMAGE_UNCHANGED =-1,
61+
/* 8bit, gray */
62+
CV_LOAD_IMAGE_GRAYSCALE =0,
63+
/* ?, color */
64+
CV_LOAD_IMAGE_COLOR =1,
65+
/* any depth, ? */
66+
CV_LOAD_IMAGE_ANYDEPTH =2,
67+
/* ?, any color */
68+
CV_LOAD_IMAGE_ANYCOLOR =4,
69+
/* ?, no rotate */
70+
CV_LOAD_IMAGE_IGNORE_ORIENTATION =128
71+
};
72+
73+
/* duplicate of "ImwriteFlags" enumeration for better compatibility with OpenCV 3.x */
74+
enum
75+
{
76+
CV_IMWRITE_JPEG_QUALITY =1,
77+
CV_IMWRITE_JPEG_PROGRESSIVE =2,
78+
CV_IMWRITE_JPEG_OPTIMIZE =3,
79+
CV_IMWRITE_JPEG_RST_INTERVAL =4,
80+
CV_IMWRITE_JPEG_LUMA_QUALITY =5,
81+
CV_IMWRITE_JPEG_CHROMA_QUALITY =6,
82+
CV_IMWRITE_PNG_COMPRESSION =16,
83+
CV_IMWRITE_PNG_STRATEGY =17,
84+
CV_IMWRITE_PNG_BILEVEL =18,
85+
CV_IMWRITE_PNG_STRATEGY_DEFAULT =0,
86+
CV_IMWRITE_PNG_STRATEGY_FILTERED =1,
87+
CV_IMWRITE_PNG_STRATEGY_HUFFMAN_ONLY =2,
88+
CV_IMWRITE_PNG_STRATEGY_RLE =3,
89+
CV_IMWRITE_PNG_STRATEGY_FIXED =4,
90+
CV_IMWRITE_PXM_BINARY =32,
91+
CV_IMWRITE_EXR_TYPE = 48,
92+
CV_IMWRITE_WEBP_QUALITY =64,
93+
CV_IMWRITE_PAM_TUPLETYPE = 128,
94+
CV_IMWRITE_PAM_FORMAT_NULL = 0,
95+
CV_IMWRITE_PAM_FORMAT_BLACKANDWHITE = 1,
96+
CV_IMWRITE_PAM_FORMAT_GRAYSCALE = 2,
97+
CV_IMWRITE_PAM_FORMAT_GRAYSCALE_ALPHA = 3,
98+
CV_IMWRITE_PAM_FORMAT_RGB = 4,
99+
CV_IMWRITE_PAM_FORMAT_RGB_ALPHA = 5,
100+
};
101+
56102
//////////////////////////////// image codec ////////////////////////////////
57103
namespace cv
58104
{
@@ -250,6 +296,19 @@ CV_EXPORTS_W bool imencode( const String& ext, InputArray img,
250296
CV_OUT std::vector<uchar>& buf,
251297
const std::vector<int>& params = std::vector<int>());
252298

299+
/** @brief Returns true if the specified image can be decoded by OpenCV
300+
301+
@param filename File name of the image
302+
*/
303+
CV_EXPORTS_W bool haveImageReader( const String& filename );
304+
305+
/** @brief Returns true if an image with the specified filename can be encoded by OpenCV
306+
307+
@param filename File name of the image
308+
*/
309+
CV_EXPORTS_W bool haveImageWriter( const String& filename );
310+
311+
253312
//! @} imgcodecs
254313

255314
} // cv

0 commit comments

Comments
 (0)