Programming Articles - Page 2013 of 3366

Java example demonstrating canny edge detection in OpenCV.

Maruthi Krishna
Updated on 13-Apr-2020 09:28:20

2K+ Views

The canny edge detector is known as optimal detector since it detects only the existing edges, gives only one response per page and minimizes the distance between the edge pixels and detected pixels.The Canny() method of the Imgproc class applies the canny edge detection algorithm on the given image. this method accepts −Two Mat objects representing the source and destination images.Two double variables to hold the threshold values.To detect the edges of a given image using the canny edge detector −Read the contents of the source image using the imread() method of the Imgcodecs class.Convert it into a gray scale ... Read More

How to add text to an image using Java OpenCV library?

Maruthi Krishna
Updated on 13-Apr-2020 09:22:27

1K+ Views

You can add text to an image using the putText() method of the org.opencv.imgproc.Imgproc class. This method renders the specified text in the given image. It accepts −An empty mat object to store the source image.A string object to specify the desired text.A Point object specifying the position of the text.Integer constant specifying the font of the text.scale factor that is multiplied by the font-specific base size.A Scalar object specifying the color of the text.An integer value specifying the color of the textExampleimport org.opencv.core.Core; import org.opencv.core.Mat; import org.opencv.core.Point; import org.opencv.core.Scalar; import org.opencv.highgui.HighGui; import org.opencv.imgcodecs.Imgcodecs; import org.opencv.imgproc.Imgproc; public class AddingText { ... Read More

How to fit ellipses around possible objects in an image using OpenCV Java?

Maruthi Krishna
Updated on 13-Apr-2020 09:20:23

344 Views

You can fit an ellipse over a shape using the fitEllipse() method of the org.opencv.imgproc.Imgproc class. This method accepts an object of MatOfPoint2f class, calculates the ellipse that would fit the given set of points and returns a RotatedRect object.Using this you can draw ellipses around the possible objects in an image. To do so, Read an image using the imread() method of the Imgproc class.Convert it into a grayscale image using the cvtColor() method of the Imgproc class.Convert the gray image to binary using the threshold() method of the Imgproc class.Find the contours in the image using the findContours() method ... Read More

How to modify the default editor of JShell in Java 9?

raja
Updated on 13-Apr-2020 09:12:48

498 Views

JShell implements REPL (Read-Evaluate-Print Loop) that reads the code from the command-line, evaluates the given snippet, and prints the result back to us.In JShell, it's possible to edit code from the default JShell editor by using JShell Editor Pad. We can also use the "/set" command to modify the default editor in order to define another one. When launching the "/edit" command, this editor can be used. In order to perform this operation, we can simply launch the "/set editor [editor]" command.Suppose we want to set the Notepad application as the default program for editing code, then just type the command: "/set editor ... Read More

Longest Repeating Substring in C++

Arnab Chakraborty
Updated on 30-Apr-2020 15:28:46

2K+ Views

Suppose we have a string S, we have to find the length of the longest repeating substring(s). We will return 0 if no repeating substring is present. So if the string is like “abbaba”, then the output will be 2. As the longest repeating substring is “ab” or “ba”.Return all words that can be formed in this manner, in lexicographical order.To solve this, we will follow these steps −n := size of Sset S := one blank space concatenated with Sset ret := 0create one matrix dp of size (n + 1) x (n + 1)for i in range 1 ... Read More

Lexicographically Smallest Equivalent String in C++

Arnab Chakraborty
Updated on 30-Apr-2020 15:29:20

773 Views

Suppose we have strings A and B of the same length, now we can say A[i] and B[i] are equivalent characters. So for example, if A = "abc" and B = "cde", then we have 'a' = 'c', 'b' = 'd' and 'c' = 'e'. The equivalent characters follow the usual rules of any equivalence relation:Reflexivity: 'a' = 'a'Symmetry: 'a' = 'b' implies 'b' = 'a'Transitivity: 'a' = 'b' and 'b' = 'c' implies 'a' = 'c'Now for example, given the equivalency information from A and B above, S = "eed", "acd", and "aab" are equivalent strings, and "aab" is ... Read More

Missing Element in Sorted Array in C++

Arnab Chakraborty
Updated on 30-Apr-2020 15:18:32

455 Views

Suppose we have a sorted array A of unique numbers, we have to find the K-th missing number starting from the leftmost number of the array. So if the array is like [4, 7, 9, 10], and k = 1, then the element will be 5.To solve this, we will follow these steps −n := size of the array, set low := 0 and high := n – 1if nums[n - 1] – nums[0] + 1 – n < k, thenreturn nums[n - 1] + (k – (nums[n - 1] – nums[0] + 1 – n))while low < high – ... Read More

Minimize Rounding Error to Meet Target in C++

Arnab Chakraborty
Updated on 30-Apr-2020 15:09:51

452 Views

Suppose we have an array of prices P [p1, p2..., pn] and a target value, we have to round each price Pi to Roundi(Pi) so that the rounded array [Round1(P1), Round2(P2)..., Roundn(Pn)] sums to the given target value. Here each operation Roundi(pi) could be either Floor(Pi) or Ceil(Pi).We have to return the string "-1" if the rounded array is impossible to sum to target. Otherwise, return the smallest rounding error, which will be (as a string with three places after the decimal) defined as −$\displaystyle\sum\limits_{i-1}^n |Round_{i} (???? ) - ????$So if the input is like [“0.700”, “2.800”, “4.900”], and the ... Read More

Shortest Way to Form String in C++

Arnab Chakraborty
Updated on 30-Apr-2020 15:04:56

337 Views

Suppose we have a string, we can form a subsequence of that string by deleting some number of characters (possibly no deletions). So if there is two strings source and target, we have to find the minimum number of subsequences of source such that their concatenation equals target. If the task is impossible, then return -1. So if source is “abc” and target is “abcbc”, then the output will be 2.To solve this, we will follow these steps −Define a string called possible, this will take s and t as inputcreate a map mfor each character c in s mark ... Read More

Last Stone Weight II in C++

Arnab Chakraborty
Updated on 30-Apr-2020 15:01:51

1K+ Views

Suppose we have a collection of rocks, now each rock has a positive integer weight. In each turn, we choose any two rocks and smash them together. If the stones have weights x and y with x = 0, decrease j by 1dp[j] := false when (dp[j] and dp[j – stones[i]]) both are false, otherwise trueif dp[j] is true, then reach := max of reach and jreturn total – (2 * reach)Let us see the following implementation to get better understanding −Example Live Demo#include using namespace std; class Solution {    public:    int lastStoneWeightII(vector& stones) {       ... Read More

Advertisements