Skip to main content

Posts

Imwrite function in OpenCV

The cv2.imwrite() function in the Python binding of OpenCV is used to save an image to a specified file. Here is the basic syntax for using cv2.imwrite(): cv2.imwrite(filename, image) filename is a string that specifies the name and path of the file to which the image should be saved. image is the image to be saved. It should be a NumPy array with dimensions [height, width, channels], where height and width are the dimensions of the image, and channels is the number of color channels (e.g., 3 for a color image and 1 for a grayscale image). Here is an example of how to use cv2.imwrite() to save an image: import cv2 # Load the image image = cv2.imread( 'image.jpg' ) # Save the image to a file cv2.imwrite( 'saved_image.jpg' , image) By default, cv2.imwrite() will save the image in JPEG format. If you want to save the image in a different format, you can specify the format using the ext parameter, like this: cv2.imwrite( 'saved_image.png' , image, ext=[cv2.IMW...

Imread function in OpenCV with example

The cv2.imread() function in OpenCV is used to read an image from a file and store it in a NumPy array. This function takes two arguments: the file path of the image and a flag that specifies how the image should be read. Here is an example of how to use the cv2.imread() function to read an image and display it using OpenCV: import cv2 import numpy as np # Read the image image = cv2.imread( 'image.jpg' ) # Check that the image was successfully read if image is None : print ( "Error reading image" ) exit() # Display the image cv2.imshow( 'image' , image) cv2.waitKey( 0 ) cv2.destroyAllWindows() The flag parameter is optional and can be one of the following values: cv2.IMREAD_COLOR: Loads the image in color (RGB) mode. This is the default value. cv2.IMREAD_GRAYSCALE: Loads the image in grayscale mode. cv2.IMREAD_UNCHANGED: Loads the image as is, including the alpha channel. For example, to read an image in grayscale mode, you can use the foll...

SQL SERVER – Find Missing Identity Values

To find missing identity values in a table in SQL Server, you can use a query like the following: WITH cte AS ( SELECT MIN(id) AS min_id, MAX(id) AS max_id FROM your_table ) SELECT a.id FROM cte CROSS JOIN (SELECT a.id + 1 AS id FROM (SELECT MIN(id) AS id FROM your_table) a UNION ALL SELECT b.id - 1 FROM (SELECT MAX(id) AS id FROM your_table) b ) a LEFT JOIN your_table t ON a.id = t.id WHERE t.id IS NULL This query uses a common table expression (CTE) to determine the minimum and maximum identity values in the table, and then generates a list of all the values between those two values using a cross join and a union all. Finally, it uses a left join to find any values that are not present in the table. Note that this query will only work if the identity column is contiguous, meaning there are no gaps between the values. If there are gaps, this query will not be able to find them. You can also use this query to find missin...

SQL SERVER – Sample Script for Compressed and Uncompressed Backup

Here is a sample script that demonstrates how to create a compressed and uncompressed backup of a database in SQL Server: -- Compressed backup BACKUP DATABASE YourDatabaseName TO DISK = 'C:\Backups\YourDatabaseName.bak' WITH COMPRESSION; -- Uncompressed backup BACKUP DATABASE YourDatabaseName TO DISK = 'C:\Backups\YourDatabaseName.bak' WITH NO_COMPRESSION; In the first statement, the WITH COMPRESSION option is used to create a compressed backup of the YourDatabaseName database. In the second statement, the WITH NO_COMPRESSION option is used to create an uncompressed backup. Replace YourDatabaseName with the actual name of your database and modify the path and file name of the backup file as needed. It's also a good idea to specify the CHECKSUM option in the BACKUP statement to verify the integrity of the backup. For example: BACKUP DATABASE YourDatabaseName TO DISK = 'C:\Backups\YourDatabaseName.bak' WITH COMPRESSION, CHECKSUM; This will ensure that the ba...

SQL SERVER – Find Owner of Database – Change Owner of Database

To find the owner of a database in SQL Server, you can use the sys.databases system view. This view contains a row for each database in the instance of SQL Server and includes a column named owner_sid which specifies the security identifier (SID) of the database owner. Here is an example of how to use the sys.databases view to find the owner of a database: Copy code SELECT name, owner_sid FROM sys.databases WHERE name = 'YourDatabaseName' To change the owner of a database in SQL Server, you can use the ALTER AUTHORIZATION statement. Here is an example of how to use this statement to change the owner of a database: USE YourDatabaseName; GO ALTER AUTHORIZATION ON DATABASE::YourDatabaseName TO NewOwner; GO Replace YourDatabaseName with the actual name of your database and NewOwner with the login name or user name of the new owner. It's important to note that to execute the ALTER AUTHORIZATION statement, you must be a member of the sysadmin fixed server role or have the ALTER ...

C# 11 features – check what is new!

C# 11 is the latest version of the C# programming language, released as part of .NET 6.0 in November 2021. Some of the new features and improvements in C# 11 include: Nullable reference types: C# 11 introduces nullable reference types, which allow you to specify that a reference type may be null. This can help you avoid null reference exceptions and improve the reliability of your code. Async streams: C# 11 introduces async streams, which allow you to use the await keyword to iterate over an asynchronous sequence of values. This makes it easier to work with asynchronous data streams and to consume asynchronous APIs. Pattern matching improvements: C# 11 introduces several improvements to pattern matching, including property patterns, record patterns, and positional patterns. These enhancements make it easier to write concise and expressive code that uses pattern matching to extract data from objects. Improved support for functional programming: C# 11 introduces several features that ma...

Extended property patterns in c#

In C#, extended property patterns allow you to use the is operator to check if an object has a particular property and access the value of that property. This can be useful when working with objects that have many properties and you only need to access a specific property. Here's an example of how to use extended property patterns in C#: public class Person { public string FirstName { get; set; } public string LastName { get; set; } } Person person = new Person { FirstName = "John", LastName = "Doe" }; if (person is { FirstName: string firstName }) { Console.WriteLine($"First name: {firstName}"); } In this example, the if statement uses an extended property pattern to check if the person object has a FirstName property of type string. If the person object has a FirstName property, the value of the property is assigned to the firstName variable, which is then used to print the first name to the console. You can also use extended property patterns ...