Skip to content

Commit de24570

Browse files
committed
Fixed README.md
Signed-off-by: Laentir Valetov <[email protected]>
1 parent 0a3db66 commit de24570

6 files changed

+85
-62
lines changed

.gitignore

+1-2
Original file line numberDiff line numberDiff line change
@@ -75,5 +75,4 @@ modules/
7575
*.pb
7676
x64/
7777
.vs/
78-
opencv_delphi.tlog/
79-
bin/
78+
opencv_delphi.tlog/

README.md

+11-11
Original file line numberDiff line numberDiff line change
@@ -2,24 +2,22 @@
22
* Experimental Delphi binding for OpenCV 4.10.0
33
* Development environment - Delphi 10.4, 11, 12
44
* x64 platform only
5-
6-
![](https://tokei.rs/b1/github/Laex/Delphi-OpenCV-Class)
75
##### Contributors:
8-
+ Laentir Valetov (email: [email protected])
6+
* Laentir Valetov (email: [email protected])
97
## Usage:
108
1. Download the current state of the project as [zip][1] or as [git][2]
119
2. Download [OpenCV 4.10.0][3], run and unpack to the selected directory.<br>
1210
The following DLLs are required to work properly<br>
13-
__From `<opencv>\build\x64\vc16\bin\` or from `redist\OpenCV_4.8.DLL.zip`__
11+
__From `<opencv>\build\x64\vc16\bin\` or from `redist\opencv_delphi4100.zip`__
1412
* opencv_videoio_ffmpeg4100_64.dll - `release`<br>
1513
* opencv_videoio_msmf4100_64.dll - `release`<br>
1614
* opencv_world4100.dll - `release`<br>
1715
* opencv_videoio_msmf4100_64d.dll - `debug`<br>
1816
* opencv_world4100d.dll - `debug`<br>
19-
**From `<project>\bin\`**
17+
**From `redist\opencv_delphi4100.zip`**
2018
* opencv_delphi4100.dll - `release`<br>
2119
* opencv_delphi4100d.dll - `debug`<br>
22-
20+
2321
__For the library to work properly, you need__
2422
- place next to the executable file of your program. To run examples - in `<project>\bin\`<br>
2523
**or**
@@ -35,13 +33,15 @@ __For the library to work properly, you need__
3533
1. For components, install the packages from<br>
3634
`<project>\packages\<Delphi Version>\CVClassGroup.groupproj`
3735
2. Run demo from `<project>\samples\Component\`
36+
#### If VCRUNTIME is missing ####
37+
Use the [advice](https://answers.microsoft.com/en-us/windows/forum/all/vcruntime140dll-and-msvcp140dll-missing-in-windows/caf454d1-49f4-4d2b-b74a-c83fb7c38625) ([Source](https://docs.microsoft.com/en-us/cpp/windows/latest-supported-vc-redist))
38+
The lack of these DLLs can be fixed by installing "Microsoft Visual C++ 2015 - 2022 Redistributable"
39+
Probably the application that is showing this error depends on it installed
40+
Download and install both the [x86](https://aka.ms/vs/17/release/vc_redist.x86.exe) and [x64](https://aka.ms/vs/17/release/vc_redist.x64.exe) versions
3841
---------------------------
3942
**Donate**<br>
40-
[PayPal USD](https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=5Z5JQ7C9JCJQN)<br>
41-
[PayPal EUR](https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=WQYST8J8PR4K2)<br>
42-
[PayPal RUB](https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=XN8D6TJMSXPFL)<br>
43-
[Yandex Money](https://money.yandex.ru/to/410011600173245)<br>
44-
[![Donatecoins](http://donatecoins.org/btc/3MTXVtRgQnA22EtBxP97Nws6GS8autp38s.svg)](http://donatecoins.org/btc/3MTXVtRgQnA22EtBxP97Nws6GS8autp38s)
43+
[Patreon](https://patreon.com/laentir)
44+
BTC: 3MTXVtRgQnA22EtBxP97Nws6GS8autp38s
4545

4646
[1]: https://github.com/Laex/Delphi-OpenCV-Class/archive/refs/heads/main.zip
4747
[2]: https://github.com/Laex/Delphi-OpenCV-Class.git

bin/opencv_delphi4100.dll

87.5 KB
Binary file not shown.

bin/opencv_delphi4100d.dll

479 KB
Binary file not shown.

packages/CVClass.pas

+73-49
Original file line numberDiff line numberDiff line change
@@ -453,13 +453,43 @@ TRegisteredCaptureSource = class(TStringList)
453453
end;
454454

455455
function GetRegisteredCaptureSource: TRegisteredCaptureSource;
456-
function CV_FOURCC(const c1, c2, c3, c4: AnsiChar): Integer; overload;
457-
{$IFDEF USE_INLINE}inline; {$ENDIF}
458-
function CV_FOURCC(const c: AnsiString): Integer; overload;
459-
{$IFDEF USE_INLINE}inline; {$ENDIF}
456+
function CV_FOURCC(const c1, c2, c3, c4: AnsiChar): Integer; overload; {$IFDEF USE_INLINE}inline; {$ENDIF}
457+
function CV_FOURCC(const c: AnsiString): Integer; overload; {$IFDEF USE_INLINE}inline; {$ENDIF}
460458

461459
implementation
462460

461+
Uses
462+
System.UITypes;
463+
464+
(*
465+
function ipDraw1(dc: HDC; img: TMat; const rect: System.Types.TRect; const Stretch: Boolean = True): Boolean;
466+
Var
467+
B: TBitmap;
468+
begin
469+
B := TBitmap.Create;
470+
Result := False;
471+
try
472+
case img.channels of
473+
1:
474+
B.PixelFormat := pf8bit;
475+
3:
476+
B.PixelFormat := pf24bit;
477+
4:
478+
B.PixelFormat := pf32bit;
479+
end;
480+
B.SetSize(img.cols, img.rows);
481+
for Var i := 0 to img.rows - 1 do
482+
Move(pbyte(img.Data)[i * img.cols * img.channels], B.ScanLine[i]^, img.cols * img.channels);
483+
// B.SaveToFile('1.bmp');
484+
// StretchBlt(
485+
BitBlt(dc, 0, 0, img.cols, img.rows, B.Canvas.Handle, 0, 0, SRCCOPY);
486+
Result := True;
487+
finally
488+
B.Free;
489+
end;
490+
end;
491+
*)
492+
463493
function ipDraw(dc: HDC; img: TMat; const rect: System.Types.TRect; const Stretch: Boolean = True): Boolean;
464494

465495
(*
@@ -469,94 +499,88 @@ function ipDraw(dc: HDC; img: TMat; const rect: System.Types.TRect; const Stretc
469499
LuminanceMultG = 184;
470500
LuminanceMultB = 18;
471501
472-
function Desaturate(Color: TColor): TColor;
502+
function Desaturate(Color: UInt32): UInt32;
473503
var
474504
Luminance: byte;
475505
begin
476-
Luminance := (((Color and $00FF0000) shr 16 * LuminanceMultR) + ((Color and $0000FF00) shr 8 * LuminanceMultG) +
506+
Luminance := //
507+
(((Color and $00FF0000) shr 16 * LuminanceMultR) + //
508+
((Color and $0000FF00) shr 8 * LuminanceMultG) + //
477509
((Color and $000000FF) * LuminanceMultB)) shr 8;
478510
Result := (Color and $FF000000) or (Luminance shl 16) or (Luminance shl 8) or Luminance;
479511
end;
480512
*)
481513

482514
Type
483-
pCOLORREF = ^COLORREF;
484-
pBITMAPINFOHEADER = ^BITMAPINFOHEADER;
515+
pColorRef = ^TColorRef;
516+
pBitmapInfoHeader = ^TBitmapInfoHeader;
485517

486518
Var
487519
// isrgb: Boolean;
488-
isgray: Boolean;
489-
buf: array [1 .. SizeOf(BITMAPINFOHEADER) + SizeOf(RGBQUAD) * 256] of byte;
490-
dibhdr: pBITMAPINFOHEADER;
491-
_dibhdr: TBitmapInfo ABSOLUTE buf;
492-
_rgb: pCOLORREF;
493-
i: Integer;
494-
iResult: Integer;
520+
// isgray: Boolean;
521+
buf: array [1 .. SizeOf(TBitmapInfoHeader) + SizeOf(TRGBQuad) * 256] of byte;
522+
BitmapInfo: TBitmapInfo ABSOLUTE buf;
523+
pDIBHdr: pBitmapInfoHeader;
524+
pCR: pColorRef;
525+
i: UInt32;
495526
begin
496527
if img.empty then
497528
Exit(False);
498529

499-
// isrgb := ('R' = upcase(img^.colorModel[0])) and ('G' = upcase(img^.colorModel[1])) and ('B' = upcase(img^.colorModel[2]));
500-
// isgray := 'G' = upcase(img^.colorModel[0]);
501-
isgray := img.channels = 1;
502-
// if (not isgray) and (not isrgb) then
503-
// Exit(false);
504-
// if (1 = img^.nChannels) and (not isgray) then
505-
// Exit(false);
506-
507-
dibhdr := pBITMAPINFOHEADER(@buf);
508-
_rgb := pCOLORREF(@buf[SizeOf(BITMAPINFOHEADER)]);
530+
FillChar(buf, SizeOf(buf), 0);
531+
pDIBHdr := pBitmapInfoHeader(@buf);
532+
pCR := pColorRef(@buf[SizeOf(TBitmapInfoHeader)]);
509533

510-
if (isgray) then
534+
if img.channels = 1 then
511535
begin
536+
{ .$DEFINE ONE }
512537
{$IFDEF ONE}
513538
const
514539
_NumColors = 256;
515540
for i := 0 to 255 do
516541
begin
517542
Var
518-
Grey := i * 255 div (_NumColors - 1);
519-
_rgb[i] := Rgb(Grey, Grey, Grey); // rgb(i, i, i);
543+
Grey := (i * 255) div (_NumColors - 1);
544+
pCR[i] := Rgb(Grey, Grey, Grey); // rgb(i, i, i);
520545
end;
521546
{$ELSE}
522547
for i := 0 to 255 do
523-
_rgb[i] :=
548+
begin
549+
pCR[i] :=
524550
// Desaturate(Rgb(i, i, i));
525551
// Trunc(0.2126 * i + 0.7152 * i + 0.0722 * i);
526-
Rgb(i, i, i);
552+
// R,G,B
553+
// Rgb(Trunc(0.2126 * i), Trunc(0.7152 * i), Trunc(0.0722 * i));
554+
Rgb(0, i, i);
555+
// i or (i shl 8) or (i shl 16) or (i shl 32);
556+
end;
527557
{$ENDIF}
528558
end;
529559

530-
dibhdr^.biSize := SizeOf(BITMAPINFOHEADER);
531-
dibhdr^.biWidth := img.cols;
532-
// Check origin for display
533-
// if img^.Origin = 0 then
534-
dibhdr^.biHeight := -img.rows;
535-
// else
536-
// dibhdr^.biHeight := img^.Height;
537-
538-
dibhdr^.biPlanes := 1;
539-
dibhdr^.biBitCount := 8 * img.channels;
540-
dibhdr^.biCompression := BI_RGB;
541-
dibhdr^.biSizeImage := 0; // img^.imageSize;
542-
dibhdr^.biXPelsPerMeter := 0;
543-
dibhdr^.biYPelsPerMeter := 0;
544-
dibhdr^.biClrUsed := 0;
545-
dibhdr^.biClrImportant := 0;
560+
pDIBHdr^.biSize := SizeOf(TBitmapInfoHeader);
561+
pDIBHdr^.biWidth := img.cols;
562+
pDIBHdr^.biHeight := -img.rows;
563+
pDIBHdr^.biPlanes := 1;
564+
pDIBHdr^.biBitCount := 8 * img.channels;
565+
pDIBHdr^.biCompression := BI_RGB;
566+
// pDIBHdr^.biClrUsed := 256;
546567

547568
if Stretch then
548569
begin
549570
SetStretchBltMode(dc, COLORONCOLOR);
550571
SetMapMode(dc, MM_TEXT);
551572
// Stretch the image to fit the rectangle
552-
iResult := StretchDIBits(dc, rect.Left, rect.Top, rect.Width, rect.Height, 0, 0, img.cols, img.rows, img.Data, _dibhdr,
553-
DIB_RGB_COLORS, SRCCOPY);
573+
Var
574+
iResult: Integer := StretchDIBits( //
575+
dc, rect.Left, rect.Top, rect.Width, rect.Height, 0, 0, img.cols, img.rows, img.Data, BitmapInfo, DIB_RGB_COLORS, SRCCOPY);
554576
Result := (iResult > 0); // and (iResult <> GDI_ERROR);
555577
end
556578
else
557579
begin
558580
// Draw without scaling
559-
iResult := SetDIBitsToDevice(dc, rect.Left, rect.Top, img.cols, img.rows, 0, 0, 0, img.rows, img.Data, _dibhdr, DIB_RGB_COLORS);
581+
Var
582+
iResult: Integer := SetDIBitsToDevice( //
583+
dc, rect.Left, rect.Top, img.cols, img.rows, 0, 0, 0, img.rows, img.Data, BitmapInfo, DIB_RGB_COLORS);
560584
Result := (iResult > 0); // and (iResult <> GDI_ERROR);
561585
end;
562586
end;

redist/opencv_delphi480.zip

-38.7 MB
Binary file not shown.

0 commit comments

Comments
 (0)