From the blog

Learn To Build A Python GUI For Solving Complex Tasks With Powerful OpenCV Library In A Delphi Windows App

Are you looking for a powerful machine learning library? Try OpenCV library for Python. You can run it with Python for Delphi (P4D). P4D is a free and simple with which you can run Python scripts as well as create new Python modules and types in Delphi. Use Delphi and C++Builder and Python4Delphi to run Python scripts in  Python GUI apps for Windows. First, run Demo1 project for executing Python script in Python for Delphi. Then load script in text field and press Execute button to see the result. Go to GitHub to download Demo1 source. procedure TForm1.Button1Click(Sender: TObject); begin PythonEngine1.ExecStrings( Memo1.Lines ); end; procedure TForm1.Button1Click(Sender: TObject); begin PythonEngine1.ExecStrings( Memo1.Lines ); end; OpenCV is an open-source library for computer vision and machine learning that supports various programming languages including Python. With this library, you can do a lot of difficult operations, such as image processing, video analysis, feature detection, machine learning, computational photography, object detection. K-Nearest Neighbour In this example, we will consider solving the problem of finding nearest neighbors using OpenCV library. First, let’s randomly create 20 red points (family 0) and 20 green points (family 1). Then add 5 blue points. Using function train(), we will train the neural network. Function findNearest() returns k nearest neighbours (in our example k=3) for each blue point. It also calculates the distance to each found neighbor and determines the family of points from which more neighbors are found. import cv2 import numpy as np import matplotlib.pyplot as plt # Feature set containing (x,y) values of 20 training data trainData = np.random.randint(0,100,(20,2)).astype(np.float32) # Labels each one either Red or Green with numbers 0 and 1 responses = np.random.randint(0,2,(20,1)).astype(np.float32) # Take Red points and plot them red = trainData[responses.ravel()==0] plt.scatter(red[:,0],red[:,1],50,’r’,’s’) # Take Green points and plot them green = trainData[responses.ravel()==1] plt.scatter(green[:,0],green[:,1],50,’g’,’^’) # 5 new points newpoints = np.random.randint(0,100,(5,2)).astype(np.float32) plt.scatter(newpoints[:,0],newpoints[:,1],50,’b’,’o’) knn = cv2.ml.KNearest_create() knn.train(trainData,cv2.ml.ROW_SAMPLE,responses) ret, results,neighbours,dist = knn.findNearest(newpoints, 3) print(“result: “, results,”n”) print(“neighbours: “, neighbours,”n”) plt.show() 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 import cv2 import numpy as np import matplotlib.pyplot as plt   # Feature set containing (x,y) values of 20 training data trainData = np.random.randint(0,100,(20,2)).astype(np.float32)   # Labels each one either Red or Green with numbers 0 and 1 responses = np.random.randint(0,2,(20,1)).astype(np.float32)   # Take Red points and plot them red = trainData[responses.ravel()==0] plt.scatter(red[:,0],red[:,1],50,‘r’,‘s’)   # Take Green points and plot them green = trainData[responses.ravel()==1] plt.scatter(green[:,0],green[:,1],50,‘g’,‘^’)   # 5 new points newpoints = np.random.randint(0,100,(5,2)).astype(np.float32) plt.scatter(newpoints[:,0],newpoints[:,1],50,‘b’,‘o’) knn = cv2.ml.KNearest_create() knn.train(trainData,cv2.ml.ROW_SAMPLE,responses) ret, results,neighbours,dist = knn.findNearest(newpoints, 3)   print(“result: “, results,“n”) print(“neighbours: “, neighbours,“n”)   plt.show() Perspective Transformation of an Image To perform perspective transformation with an image use warpPerspective() function. The parameters of this function are the original image, the transformation matrix, and the size of the output image. Use getPerspectiveTransform() function to get the transformation matrix. You need to pass four points of the input image and the corresponding four points of the output image to this function. It is important, that three of the four points should not be on the same straight line. import cv2 import numpy as np import matplotlib.pyplot as plt image_path = “E:faces.JPEG” img = cv2.imread(image_path) pts1 = np.float32([[900,100],[1200,100],[900,400],[1200,400]]) pts2 = np.float32([[0,0],[400,0],[0,400],[400,400]]) M = cv2.getPerspectiveTransform(pts1,pts2) dst = […]

Read More

Powerful Optical Barcode Recognition Component For Delphi Firemonkey By Winsoft

Introduction OBR (Optical Barcode recognition) component for Firemonkey supports Windows, macOS, iOS and Android. Its main purpose is to decode QR code and Barcode images. In the below video you can check the steps to install the firemonkey component for OBR. The installation steps differs to the one for the OBR firemonkey library, it is actually easier. 2. Components in the Demo and what they do There are two panels. One is at the top, containing the button for the picture choise. In the middle there is a Scroll box component (for scrolling) and a Timage component inside it for the chosen picture. At the bottom there is another panel again, containing the TMemo component . All combined they create the windows that shows up with button, image and text at the bottom.     Clicking on the button executes the TOpenPictureDialog component which opens a dialog for selecting a picture. The selected picture is loaded in an TImage component and shown on the main empty window. Clicking on the button executes the TOpenPictureDialog component which opens a dialog for selecting a picture. The selected picture is loaded in an TImage component and shown on the main empty window. with OpenDialog do if Execute then begin Memo.Lines.Clear; ImageControl.Bitmap.LoadFromFile(FileName); with OpenDialog do     if Execute then     begin       Memo.Lines.Clear;       ImageControl.Bitmap.LoadFromFile(FileName); Then the selected picture is decoded using the TBarcodeDecoder  object (the ‘scanner’) and the results is filled into the TDecodeResults list as it follows: with TBarcodeDecoder.Create do try Barcodes := Decode(ImageControl.Bitmap); with TBarcodeDecoder.Create do       try         Barcodes := Decode(ImageControl.Bitmap); If code is detected by the TBarcodeDecoder  object, the result is stored in the TDecodeResults list, named as Barcodes. With FOR cycle we check the list and its items of what they have stored before. The item of the TDecodeResults list contains FormatName and Text (which is the doceded text). You can see in the below code: for I := 0 to Length(Barcodes) – 1 do Memo.Lines.Append(Barcodes[I].FormatName + ‘: ‘ + Barcodes[I].Text); for I := 0 to Length(Barcodes) – 1 do             Memo.Lines.Append(Barcodes[I].FormatName + ‘: ‘ + Barcodes[I].Text); You can download the Demo with the component from the link below: https://winsoft.sk/fobr.htm

Read More

Wildly Popular Inno Setup Is A Free Installer For Windows Built In Delphi

Inno Setup is a free installer for Windows that is fast, free, and built in Delphi. Introduced in 1997, Inno Setup is brought you by Jordan Russell and Martijn Laan. Full source code is available over on GitHub but copyright of the software is maintained by the authors. Inno Setup is used world wide by a huge number of software developers and companies including powerhouses like Microsoft for their Visual Studio Code IDE on Windows. There are a number of third party add-ons for Inno Setup which really take it to the next level like Inno Script Studio by Kymoto Solutions and VCL styled installers by Rodrigo Ruz. The built in Inno Setup Compiler application supports a light and dark mode. The Inno Script Studio third party companion solution has an install script wizard which makes it super simple to create an installer file for Inno Setup with all the professional features you need. Website https://jrsoftware.org/isinfo.php GitHub https://github.com/jrsoftware/issrc Screenshot Gallery Reduce development time and get to market faster with RAD Studio, Delphi, or C++Builder. Design. Code. Compile. Deploy.Start Free Trial   Learn More About Upgrading

Read More

Learn To Build A Python GUI For Working With The Numpy Library In A Delphi Windows App

If you need to perform complex transformations or mathematical calculations with matrices or arrays, then Python Numpy library is exactly what you need. You can easy run this library with Python4Delphi (P4D). Python4Delphi is a free tool with which you can work with Python scripts and objects in the Windows GUI. In this post, we will look at how to run Numpy library with P4D. Now you can build Python GUI apps for Windows using a lot of Python libraries with Delphi and C++Builder and Python4Delphi. Just open and run Demo1 project. Then paste the Python script into the text field, press Execute button and get the result. Go to GitHub to download Demo1. procedure TForm1.Button1Click(Sender: TObject); begin PythonEngine1.ExecStrings( Memo1.Lines ); end; procedure TForm1.Button1Click(Sender: TObject); begin PythonEngine1.ExecStrings( Memo1.Lines ); end; Numpy library allows you to create multidimensional arrays and matrices and work with their properties. It also contains various functions for processing arrays and matrices. Let’s look at some simple examples of working with Numpy. If you have trouble compiling the Python you may need to have Numpy 1.19.3 installed. Create a matrix and get some properties This example shows how to create a 3-dimensional array and fill it with numbers from 0 to 29. Then, using the properties of this array, we can find out its shape, dimension, data type, number of elements. import numpy as np a = np.arange(30).reshape(2, 3, 5) print(a) print(a.shape) print(a.ndim) print(a.dtype.name) print(a.itemsize) print(a.size) import numpy as np a = np.arange(30).reshape(2, 3, 5) print(a) print(a.shape) print(a.ndim) print(a.dtype.name) print(a.itemsize) print(a.size) Basic operations with arrays Let’s take a look at the simplest conversions you can perform on arrays. Using concatenate() function, you can combine the values of two arrays into one. With function sort() you can sort ascending the values in an array. Function reshape() allows you to change the dimension of the array. import numpy as np arr = np.array([7, 10, 3, 11, 29, 15, 18]) print(np.sort(arr)) a = np.array([1, 2, 3, 4, 5, 6]) b = np.array([7, 8, 9, 10, 11, 12]) print(np.concatenate((a, b))) c = a.reshape(3, 2) print(c) import numpy as np arr = np.array([7, 10, 3, 11, 29, 15, 18]) print(np.sort(arr)) a = np.array([1, 2, 3, 4, 5, 6]) b = np.array([7, 8, 9, 10, 11, 12]) print(np.concatenate((a, b))) c = a.reshape(3, 2) print(c) Mathematical operations with matrix Function default_rng()  allows you to fill a matrix with random values. You can use integer or real numbers. In this example, we fill the matrix with integer values. Then we find the maximum and minimum element, the sum of all the elements in the matrix. It is also shown how you can multiply a matrix by a number and sum two matrices with the same dimension. import numpy as np from numpy.random import default_rng rng = default_rng() arr=rng.integers(20, size=(2, 4)) print(arr) print(arr.max()) print(arr.min()) print(arr.sum()) print(arr*2) arr2=rng.integers(5, size=(2, 4)) print(arr2) print(arr+arr2) import numpy as np from numpy.random import default_rng rng = default_rng() arr=rng.integers(20, size=(2, 4)) print(arr) print(arr.max()) print(arr.min()) print(arr.sum()) print(arr*2) arr2=rng.integers(5, size=(2, 4)) print(arr2) print(arr+arr2) And this is only a small part of what Numpy library allows you to do. Download Numpy and check how many possibilities it opens for your applications. Install Python4Delphi for building Python GUIs for Windows using Delphi easily.

Read More

Learn About Using Right Angle Brackets In This C++11 Feature For Windows Development

In the Clang-enhanced C++ compilers, two consecutive right angle brackets no longer generate an error, and these constructions are treated according to the C++11 standard. C++03’s parser defines “>>” as the right shift operator or stream extraction operator in all cases. However, with nested template declarations, there is a tendency for the programmer to neglect to place a space between the two right angle brackets, thus causing a compiler syntax error. C++11 improves the specification of the parser so that multiple right angle brackets will be interpreted as closing the template argument list where it is reasonable. Right angle brackets example #pragma hdrstop #pragma argsused #include #include #include typedef std::vector > Table; // OK typedef std::vector> Flags; // OK int _tmain(int argc, _TCHAR* argv[]) { return 0; } #pragma hdrstop #pragma argsused   #include #include   #include typedef std::vector<std::vector<int> > Table;  // OK typedef std::vector<std::vector<bool>> Flags;  // OK   int _tmain(int argc, _TCHAR* argv[]) {           return 0; } Head over and find all of the different C++ language features now available in C++Builder. 

Read More

Speed Up FireMonkey Layout Construction And Painting Performance With These Tips

In this CodeRage session, you can learn how to speed up FireMonkey layout construction and improve the painting performance of FireMonkey applications. With Delphi Visual Designer you can design any user interface by easily dragging and dropping the components. If you need some customizations you can alter the properties of the components or just change the style. But complex layouts tend to contain more controls than necessary. TFmxObject – Base Class for FireMonkey Components Heavyweight class Several lazily initialized lists on top of TComponent ones Complex layouts need a substantial amount of time to construct, align and paint Performance penalties can be significant on mobile platforms So, how we can optimize our layouts then? Here are the possible layout optimization options that you can implement: Simplify layout designs Optimize images for screen size and density Avoid shadows, effects, or any unnecessary effects Implement Lazy loading Optimize layout hierarchies without changing the visual appearance of the layout Be sure to watch the session to learn and grasp real-world experience in optimizing FireMonkey applications!

Read More

Get Started Building Cross-Platform Games In Delphi FireMonkey With Alien Invasion Sample

Alien Invasion is a classic arcade-style game which features a grid of aliens that move in sync back and forth across the screen. They fire projectiles at the player who is at the bottom of the screen. On each trip back and forth across the screen, they start moving faster and faster. There are four shields near the bottom of the screen that the player can hide behind but they have a limited number of hits they can take before each shield is exhausted. The player can only move back and forth at the bottom of the screen and fire projectiles upward. What you can learn from this complete Alien Invasion game sample: Game Design Basics Game Development App Tethering Collision Detection Building Game Loops Working With Sounds/Music Cross-Platform Development Patterns TMotionSensor TBitmapListAnimation You can download this game sample from GetIt easily With RAD Studio, game development is absolutely easy to start. Moreover, with the components, your development process goes smoothly.  Furthermore, there are several game engines built with Delphi that you can create many different games from 2D to 3D! Be sure to check out these game engines and the games built with that engine!

Read More

Powerful Easy To Use Build Automation Tool For Developers Made In Delphi

FinalBuilder is a build automation tool used by thousands of developers to simplify their build process and it is built in Delphi. Some of the FinalBuilder features include integrated debugging, email, MSN, FTP & SFTP support, version control integration, detailed logging, variables, scripting support, and an action studio for writing custom FinalBuilder actions. Build scripts can be scheduled with windows scheduler, or integrate them with Continua CI, Jenkins or any other CI Server according to the FinalBuilder site. FinalBuilder lists companies such as Intel, Samsung, Symantec, Cisco, and HP among their customers. There is a massive amount of features with this product and they have a feature matrix that outlines it all. Website https://www.finalbuilder.com/finalbuilder Screenshot Gallery

Read More

Learn How To Use WinRT In Your Native Windows Delphi And C++ Builder Apps

WinRT is the latest application architecture from Microsoft for Windows 10 and components development. This webinar will show you how to take advantage of the new WinRT APIs and components in your Delphi and C++Builder applications. WinRT is a modern C++17 language projection for WinRT and it’s implemented entirely in header files. This leads to great performance, both in time and space, typically performing better and producing smaller binaries than any other language option for the Windows Runtime. In one sentence, WinRT is for the new world. Agenda The Windows architecture strategy What is WinRT? Why should we care about it? WinRT/UWP vs Win32 vs COM vs .NET The Ever Moving Strategy with Windows WinRT Components in RAD Studio Q&A Windows Runtime  Combine what’s great in COM and .NET Binary interface for language interoperability Metadata management is similar to .NET New COM as a natural part of all languages/platforms .NET, C++, JavaScript, Delphi and C++ Builder Build a new class library on the new runtime Cleanup the library compared to .NET Do not enforce managed code

Read More

Hit The Ground Running With Windows Native MongoDB Database Sample Apps For Delphi

MongoDB is a document database, which means it stores data in JSON-like documents, the most natural way to think about data, and is much more expressive and powerful than the traditional row/column model. How about connecting with MongoDB and exploring the available databases and data using FireDAC components in your Application. Don’t know where to start? This post will guide you to do that. MongoDB.Explore Sample App shows how to connect to available MongoDB Databases, access to its ListCollections, and populate to the grid using MongoDB API wrapper class. You can find Delphi and C++ code samples in GitHub Repositories. Search by name into the samples repositories according to your RAD Studio version. Components used in MangoDB.Explore Sample App: TFDPhysMongoDriverLink: To link the MongoDB driver to an application and set it up. In general, it is enough to only include the FireDAC.Phys.MongoDB unit into your application uses a clause. The TFDPhysMongoDriverLink component can be used to specify: The VendorHome – the MongoDB installation root folder. The VendorLib – the name and the optional path to the MongoDB client library. TFDConnection: To establish a connection to a DBMS and to manage associated datasets. TFDMongoDataset: Used to attach a dataset to an existing MongoDB cursor. This class allows you to attach the dataset to an existing MongoDB cursor. You can get the cursor from various MongoDB API wrapping class methods, such as TMongoDatabase.ListCollections.To open a dataset, assign a cursor to the Cursor property and call the Open method. TFDMongoQuery: The TFDMongoQuery class is used to execute a MongoDB query. You can specify a query in one of the following ways: Using the QProject, QMatch, and QSort properties at design-time or run-time. Using the Query Builder provided by the Query property at run-time. Use TDataSource to populate the fetched data to TDBGrid. Implementation Details: You can find the MongoDB Explore Demo sample project at: Object PascalDatabaseFireDACSamplesDBMS SpecificMongoDBMongo_Explore.dproj. Before running this, as a preliminary step, we need to have a MongoDB Server is running and accessible from your host. For Details, See Connect to MongoDB Database. Check the below screen for listing the databases in the MongoDB server. Upon changing the database, its list collections changes. This screen Demonstrates the “restaurants” collection of the “test” database is provisioned with test data. To provision this collection, run the MongoDB Restaurants Demo, and click the Load Data button: You can find the MongoDB Restaurants Demo sample project at: Object PascalDatabaseFireDACSamplesDBMS SpecificMongoDBRestaurants Check out the full article in the DocWiki about the MongoDB.Explore Sample. Check out the full source code for the MongoDB.Explore projects for Delphi over on GitHub. Check out the full source code for MondoDB samples in C++ over on GitHub.

Read More