<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Siddhesh Shivdikar on Medium]]></title>
        <description><![CDATA[Stories by Siddhesh Shivdikar on Medium]]></description>
        <link>https://medium.com/@siddheshshivdikar?source=rss-c32d69521c27------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*DmY3QafjkZIO6guBdO6tTA.png</url>
            <title>Stories by Siddhesh Shivdikar on Medium</title>
            <link>https://medium.com/@siddheshshivdikar?source=rss-c32d69521c27------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Wed, 02 Dec 2026 02:56:22 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@siddheshshivdikar/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Docker Desktop App not opening MacOS quick fix]]></title>
            <link>https://siddheshshivdikar.medium.com/docker-desktop-app-not-opening-macos-quick-fix-a66cf6b7f611?source=rss-c32d69521c27------2</link>
            <guid isPermaLink="false">https://medium.com/p/a66cf6b7f611</guid>
            <category><![CDATA[mac]]></category>
            <category><![CDATA[docker-desktop]]></category>
            <category><![CDATA[docker]]></category>
            <category><![CDATA[macos]]></category>
            <dc:creator><![CDATA[Siddhesh Shivdikar]]></dc:creator>
            <pubDate>Wed, 05 Feb 2025 07:17:35 GMT</pubDate>
            <atom:updated>2025-11-15T17:09:58.313Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*wrw2th2qDxskse5k" /><figcaption>Photo by <a href="https://unsplash.com/@rubaitulazad?utm_source=medium&amp;utm_medium=referral">Rubaitul Azad</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><p>This quick guide explains how to troubleshoot the Docker Desktop app when it frequently crashes after macOS updates.</p><p>You might wonder why I didn’t just post this on Stack Overflow. Well, there are 22 pages of suggested solutions, none of which worked for me. After going through them, I realized that most were just workarounds rather than a proper fix that applies to a wide range of cases.</p><p><strong>So, what’s the solution?</strong></p><p>Docker often breaks on macOS after a major system update, refusing to start — even when launching it directly from the binaries.</p><p>Uninstalling doesn’t help either, as Docker leaves behind numerous undeleted files that cause issues. I came across a YouTube video demonstrating how to remove these files manually, but that method didn’t work in my case. Here’s the video:</p><p><a href="https://youtu.be/maQJSnRdy10">https://youtu.be/maQJSnRdy10</a></p><p>My approach is similar but more streamlined, using Homebrew. If you’re unfamiliar with Homebrew, I recommend installing it first.</p><p><strong>Step 1: Uninstall Docker Desktop</strong></p><p>If you have Docker Desktop installed, first uninstall it properly:</p><ol><li>Open <strong>Docker Desktop</strong>.</li><li>Go to <strong>Settings</strong> &gt; <strong>Troubleshoot</strong>.</li><li>Click <strong>Uninstall</strong>.</li><li>Quit Docker after uninstalling.</li></ol><blockquote>MacOS userswould know that the Finder has Title bar which has app properties even when App fails to open even when Docker window is not showing up. Moreover docker services are running in BG as MacOS fails to remove it completely. (Thats how you can quit docker and its services after uninstalling )</blockquote><blockquote>Activity Monitor -&gt; Close all related services. Thanks for peoples in comment who have helped for mentioning instructions which could be misleading for some folks always way to improve !</blockquote><p><strong>Step 2: Remove Docker Binaries</strong></p><p>Run the following command to delete Docker-related binaries:</p><pre>sudo rm -rf /usr/local/bin/docker<br>sudo rm -rf /usr/local/bin/docker-credential-desktop<br>sudo rm -rf /usr/local/bin/docker-credential-osxkeychain<br>sudo rm -rf /usr/local/bin/hub-tool<br>sudo rm -rf /usr/local/bin/kubectl.docker<br>sudo rm -rf /opt/homebrew/etc/bash_completion.d/docker<br>sudo rm -rf /opt/homebrew/share/zsh/site-functions/_docker<br>sudo rm -rf /opt/homebrew/share/fish/vendor_completions.d/docker.fish<br>sudo rm -rf /usr/local/bin/kubectl.docker /usr/local/bin/docker-index /usr/local/bin/docker-compose<br>sudo rm -rf /opt/homebrew/bin/docker /opt/homebrew/var/homebrew/linked/docker /opt/homebrew/opt/docker<br>sudo rm -rf /System/Volumes/Data/usr/local/bin/kubectl.docker /System/Volumes/Data/usr/local/bin/docker-index /System/Volumes/Data/usr/local/bin/docker-compose</pre><p><strong>Step 3: Remove Docker Configuration &amp; Logs</strong></p><pre>sudo rm -rf /Library/LaunchDaemons/com.docker.*<br>sudo rm -rf ~/Library/Containers/com.docker.*<br>sudo rm -rf ~/Library/Application\ Scripts/group.com.docker<br>sudo rm -rf ~/Library/Group\ Containers/group.com.docker<br>sudo rm -rf ~/Library/Caches/com.docker.*<br>sudo rm -rf ~/Library/Preferences/com.docker.*<br>sudo rm -rf /private/var/run/com.docker.*</pre><p><strong>Step 4: Remove Docker from Homebrew</strong></p><p>If you installed Docker via Homebrew, run:</p><pre>brew uninstall - cask docker<br>brew uninstall docker<br>brew cleanup</pre><p><strong>Step 5: Remove VS Code Docker Extensions (If Installed)</strong></p><pre>rm -rf ~/.vscode/extensions/ms-azuretools.vscode-docker-*</pre><p><strong>Step 6: Remove Docker from Node.js Projects (Optional)</strong></p><p>If you have Docker-related dependencies in your projects, remove them manually using:</p><pre>rm -rf node_modules<br>npm install</pre><p><strong>Step 7: Restart Your Mac</strong></p><p>After completing the steps, restart your Mac to ensure all services are stopped.</p><p>After rebooting, run:</p><pre>brew install docker<br>which docker<br>docker - version</pre><p>Docker has been installed successfully. Happy Coding 🚀</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=a66cf6b7f611" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Monorepos, Design Systems, and Scalable Apps: A Love Story (with Flutter Workspaces)]]></title>
            <link>https://www.designsystemscollective.com/monorepos-design-systems-and-scalable-apps-a-love-story-with-flutter-workspaces-0b0ff134e79a?source=rss-c32d69521c27------2</link>
            <guid isPermaLink="false">https://medium.com/p/0b0ff134e79a</guid>
            <category><![CDATA[software-engineering]]></category>
            <category><![CDATA[software-architecture]]></category>
            <category><![CDATA[application-development]]></category>
            <category><![CDATA[monorepo]]></category>
            <category><![CDATA[production]]></category>
            <dc:creator><![CDATA[Siddhesh Shivdikar]]></dc:creator>
            <pubDate>Wed, 29 Jan 2025 11:37:56 GMT</pubDate>
            <atom:updated>2025-02-07T16:20:40.239Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*xvVgMcSQoYQIdsrRqZJS5Q.png" /></figure><p>Hey there! If you’re like me, you’ve probably found yourself drowning in a sea of duplicated code while working on multiple Flutter apps. One day, you’re copy-pasting a button into `App1`, and the next, you’re doing the same thing for `App2`. It’s like trying to keep track of all your browser tabs — chaotic and exhausting. But guess what? There’s a better way. Enter <strong>monorepos</strong> and Dart 3.6’s <strong><em>workspaces</em></strong>. Trust me, they’re game-changers.</p><p>I’ll walk you through how I use monorepos and workspaces to build scalable apps, share a design system, and keeping my sanity intact. A lil humor cause coding without laughter is like pizza without cheese — just sad.</p><h4>What’s a Monorepo, and Why Should I Care?</h4><p>A <strong>monorepo</strong> is basically a single repository that houses multiple projects or packages. Think of it as a shared workspace for your code. Instead of having separate repos for your design system, app, and utilities, you keep everything under one roof. Here’s why I love it:</p><p>1.<strong> Code Reusability</strong>: I can share my design system, utilities, and other goodies across apps.</p><p>2. <strong>Consistency</strong>: No more wondering if `App1` is using the same button style as `App2`.</p><p>3. <strong>Simplified CI/CD</strong>: One pipeline to rule them all.</p><p>4. <strong>Easier Collaboration</strong>: My team can work on multiple projects without juggling repos.</p><p>But wait, there’s more! With Flutter 3.6, I can use <strong><em>workspaces</em></strong> to make my monorepo even more efficient. Let me show you how.</p><h4>The Problem with Traditional Monorepos</h4><p>Before Flutter 3.6, managing a monorepo felt like herding cats. I had to:</p><p>- Run `dart pub get` for every package.</p><p>- Deal with different dependency versions.</p><p>- Suffer from memory-hogging IDE analysis contexts.</p><p>It was a mess. But with <strong><em>workspaces</em></strong>, Flutter has given us a shiny new tool to tame the chaos.</p><h4>How do I Set Up a Monorepo with Flutter Workspaces</h4><p>Let’s say I’m building two apps (`App1` and `App2`) and a shared design system. Here’s how I set up my monorepo:</p><h4><strong><em>Step 1: Create the Monorepo Structure</em></strong></h4><p>I start by organising my projects like this:</p><pre>my_monorepo/<br>├── packages/<br>│ ├── design_system/ // My shared design system<br>│ ├── app_1/ // My first app<br>│ ├── app_2/ // My second app<br>├── pubspec.yaml // Root pubspec for the workspace</pre><h4><strong><em>Step 2: Add the Root `pubspec.yaml`</em></strong></h4><p>At the root of my monorepo, I create a `pubspec.yaml` file with a `workspace` entry:</p><pre>name: _<br>publish_to: none<br>environment:<br>sdk: ^3.6.0<br>workspace:<br>- packages/design_system<br>- packages/app_1<br>- packages/app_2</pre><p>This tells Flutter, “Hey, these are my packages. Treat them as one big happy family.”</p><h4><strong><em>Step 3: Update My Package `pubspec.yaml` Files</em></strong></h4><p>For each package in my workspace, I update the `pubspec.yaml` to include:</p><pre>yaml<br>environment:<br>sdk: ^3.6.0<br>resolution: workspace</pre><p>This ensures all packages use the same dependency resolution.</p><h4><strong><em>Step 4: Run `dart pub get`</em></strong></h4><p>I run `dart pub get` from the root of my monorepo. Flutter will:</p><p>1. Create a single `pubspec.lock` file at the root.</p><p>2. Generate a shared `.dart_tool/package_config.json`.</p><p>3. Delete any stray `pubspec.lock` and `.dart_tool/package_config.json` files in my packages.</p><p>Now my file structure looks like this:</p><pre>my_monorepo/<br>├── packages/<br>│ ├── design_system/<br>│ │ └── pubspec.yaml<br>│ ├── app_1/<br>│ │ └── pubspec.yaml<br>│ ├── app_2/<br>│ │ └── pubspec.yaml<br>├── pubspec.yaml<br>├── pubspec.lock<br>└── .dart_tool/package_config.json</pre><h4>The Magic of Workspaces</h4><p>With workspaces, I get:</p><p>1. <strong><em>Single Dependency Resolution</em></strong>: No more version conflicts between packages.</p><p>2. <strong><em>Shared Analysis Context</em></strong>: My IDE won’t eat up all my RAM.</p><p>3. <strong><em>Simplified Commands</em></strong>: I run `dart pub get` once, and I’m done.</p><p>It’s like having a personal assistant for my codebase.</p><p><strong><em>Building a Scalable Design System</em></strong></p><p>Now that my monorepo is set up, let’s talk about the **design system**. This is where I define my app’s look and feel — colors, typography, buttons, and more. Here’s how I make it shine:</p><p><strong>1. Define Design Tokens</strong></p><p>I create a `tokens.dart` file in my `design_system` package:</p><pre>class DesignTokens {<br>  static const Color primaryColor = Color(0xFF6200EE);<br>  static const TextStyle heading1 = TextStyle(fontSize: 32, fontWeight: FontWeight.bold);<br>}</pre><p><strong>2. Create Reusable Components</strong></p><p>I build components like buttons and cards in my `design_system` package (I’m just using simple examples here design systems are much more complex):</p><pre>class YourButton extends StatelessWidget {<br>  final String text;<br>  final VoidCallback onPressed;<br>  const PrimaryButton({required this.text, required this.onPressed});<br>  @override<br>  Widget build(BuildContext context) {<br>     return ElevatedButton(<br>     onPressed: onPressed,<br>     child: Text(text),<br>    );<br>  }<br>}</pre><p><strong>3. Use the Design System in My Apps</strong></p><p>In `app_1` and `app_2`, I import the design system and use its components:</p><pre>import &#39;package:design_system/design_system.dart&#39;;<br>class HomeScreen extends StatelessWidget {<br>  @override<br>  Widget build(BuildContext context) {<br>    return Scaffold(<br>    appBar: AppBar(title: Text(&#39;App 1&#39;)),<br>    body: Center(<br>      child: PrimaryButton(<br>        text: &#39;Click Me&#39;,<br>        onPressed: () {},<br>        ),<br>      ),<br>    );<br>  }<br>}</pre><h4>Tips for a Happy Monorepo</h4><p>Here are some tips I’ve learned along the way:</p><p>1. <strong><em>Keep It Organized</em></strong>: I use clear folder structures and naming conventions.</p><p>2. <strong><em>Document Everything</em></strong>: I write a `<strong><em>README.md</em></strong>` for each package. (For an Organisation based project please use Confluence or a proper doco / At the time of writing we have @Previews for flutter components but you can still use story books if team capacity permits)</p><p>3. <strong><em>Test Thoroughly</em></strong>: I write unit and widget tests for my design system and apps.</p><p>4. <strong><em>Use CI/CD</em></strong>: I set up a pipeline to test and deploy my apps automatically.</p><h4>When Things Go Wrong</h4><p><strong><em>Dependency Conflicts</em></strong>: Workspaces force me to resolve conflicts early. It’s annoying but worth it.</p><p><strong><em>Stray Files</em></strong>: If `pub get` complains about stray `pubspec.lock` files, I delete them manually.</p><p><strong><em>IDE Issues</em></strong>: If my IDE acts up, I restart it or run `flutter clean`.</p><p><strong><em>Conclusion<br></em></strong>Monorepos and workspaces are like peanut butter and jelly — they just work together. By organizing my code into a monorepo and using Flutter’s workspace feature, I can build scalable apps, share a design system, and keep my codebase clean and maintainable.</p><p>So go forth, fellow developer, and conquer the world of scalable apps. And remember: if your codebase feels like a jungle, just grab a machete (or a monorepo) and start hacking.</p><p><strong>Got questions</strong>? Drop them in the comments below. And if you found this tutorial helpful, share it with your fellow developers. After all, sharing is caring (unless it’s your Pizza Slice — then it’s every person for themselves).</p><p>Happy coding! 🚀</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=0b0ff134e79a" width="1" height="1" alt=""><hr><p><a href="https://www.designsystemscollective.com/monorepos-design-systems-and-scalable-apps-a-love-story-with-flutter-workspaces-0b0ff134e79a">Monorepos, Design Systems, and Scalable Apps: A Love Story (with Flutter Workspaces)</a> was originally published in <a href="https://www.designsystemscollective.com/">Design Systems Collective</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[MVVM Architecture with Sealed Classes in Flutter Building Scalable Apps]]></title>
            <link>https://www.designsystemscollective.com/mvvm-architecture-with-sealed-classes-in-flutter-building-scalable-apps-077ecf7811d7?source=rss-c32d69521c27------2</link>
            <guid isPermaLink="false">https://medium.com/p/077ecf7811d7</guid>
            <category><![CDATA[software-architecture]]></category>
            <category><![CDATA[flutter-app-development]]></category>
            <category><![CDATA[software-development]]></category>
            <category><![CDATA[software-engineering]]></category>
            <category><![CDATA[flutter]]></category>
            <dc:creator><![CDATA[Siddhesh Shivdikar]]></dc:creator>
            <pubDate>Mon, 27 Jan 2025 08:17:14 GMT</pubDate>
            <atom:updated>2025-02-09T18:34:23.700Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*ta-SnbO-896XbjLE" /><figcaption>Photo by <a href="https://unsplash.com/@swimstaralex?utm_source=medium&amp;utm_medium=referral">Alexander Sinn</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><p>Hey there, fellow developers! Today, we’re going to talk about MVVM Architecture, a design pattern that’s been gaining traction in the app development community. It’s all about separating concerns and making your codebase more maintainable, scalable, and — dare I say it? — clean.</p><blockquote>Writing code is an art and you are the artist 🧑‍🎨</blockquote><h3>What is MVVM Architecture?</h3><p>MVVM is an abbreviation for the Model-View-ViewModel (MVVM) pattern, but with a twist. Instead of using the traditional View-Model approach, where the view is tightly coupled to the model, we’re going to separate these concerns into three distinct layers: Model, ViewModel, and View.</p><h4>The Three Layers of MVVM Architecture</h4><p>1. <strong><em>Model</em></strong>: This layer represents a single source of truth that carries real-time fetch data or database-related queries. Think of it as your app’s “brain” — where the data lives.</p><p>2. <strong><em>ViewModel</em></strong>: The mediator between View and Model, the ViewModel accepts user events and requests data from the Model. It then notifies the View when new data is available.</p><p>3. <strong><em>View</em></strong>: This layer is responsible for rendering the UI, handling user interactions, and displaying data provided by the ViewModel.</p><h4>A Simple Example: Cart Feature in an Ecommerce App</h4><p>Let’s take a simple cart app as an example. Our goal is to demonstrate how MVVM Architecture can be applied in practice.</p><p>First, we define our `Product` class:</p><pre>class Product {<br>  final String name;<br>  final double price;<br><br>  Product({required this.name, required this.price});<br>}</pre><p>Next, we create a simple repository to store products and the cart:</p><pre>abstract class CartRepository {<br>  void addToCart(Product product);<br>  List&lt;Product&gt; getCart();<br>}<br><br>class SimpleCartRepository extends ChangeNotifier implements CartRepository {<br>  final List&lt;Product&gt; _cart = [];<br><br>  @override<br>  void addToCart(Product product) {<br>    _cart.add(product);<br>    notifyListeners();<br>  }<br><br>  @override<br>  List&lt;Product&gt; getCart() =&gt; _cart;<br>}</pre><p>Now, let’s introduce a sealed class to manage different UI states:</p><pre>sealed class CartState {<br>  const CartState();<br><br>  factory CartState.initial() = Initial;<br>  factory CartState.loading() = Loading;<br>  factory CartState.success(List&lt;Product&gt; cart) = Success;<br>  factory CartState.error(String message) = Error;<br>}<br><br>class Initial extends CartState {}<br>class Loading extends CartState {}<br>class Success extends CartState {<br>  final List&lt;Product&gt; cart;<br><br>  Success(this.cart);<br>}<br>class Error extends CartState {<br>  final String message;<br><br>  Error(this.message);<br>}</pre><p>Our ViewModel is now responsible for managing these states and notifying the View:</p><pre>import &#39;package:flutter/material.dart&#39;;<br><br>class CartViewModel extends ChangeNotifier {<br>  final CartRepository _repository;<br>  CartState _state = const CartState.initial();<br><br>  CartViewModel(this._repository);<br><br>  CartState get state =&gt; _state;<br><br>  void addToCart(Product product) async {<br>    _setState(const CartState.loading());<br>    try {<br>      _repository.addToCart(product);<br>      _setState(CartState.success(_repository.getCart()));<br>    } catch (e) {<br>      _setState(CartState.error(e.toString()));<br>    }<br>  }<br><br>  void _setState(CartState newState) {<br>    if (_state != newState) {<br>      _state = newState;<br>      notifyListeners();<br>    }<br>  }<br>}</pre><p>Finally, our View is where the magic happens:</p><pre>import &#39;package:flutter/material.dart&#39;;<br><br>void main() =&gt; runApp(MyApp());<br><br>class MyApp extends StatelessWidget {<br>  @override<br>  Widget build(BuildContext context) {<br>    return MaterialApp(<br>      home: Scaffold(<br>        appBar: AppBar(title: Text(&quot;MVVM Architecture Example&quot;)),<br>        body: CartScreen(),<br>      ),<br>    );<br>  }<br>}<br><br>class CartScreen extends StatefulWidget {<br>  @override<br>  _CartScreenState createState() =&gt; _CartScreenState();<br>}<br><br>class _CartScreenState extends State&lt;CartScreen&gt; {<br>  final CartRepository _repository = SimpleCartRepository();<br>  late final CartViewModel _viewModel;<br><br>  @override<br>  void initState() {<br>    super.initState();<br>    _viewModel = CartViewModel(_repository);<br>    _viewModel.addListener(_updateUI);<br>  }<br><br>  @override<br>  void dispose() {<br>    _viewModel.removeListener(_updateUI);<br>    super.dispose();<br>  }<br><br>  void _updateUI() =&gt; setState(() {});<br><br>  @override<br>  Widget build(BuildContext context) {<br>    return Column(<br>      children: [<br>        ElevatedButton(<br>          onPressed: () =&gt; _viewModel.addToCart(Product(name: &#39;Product&#39;, price: 10.0)),<br>          child: Text(&quot;Add Product to Cart&quot;),<br>        ),<br>        Expanded(child: _buildStateWidget(_viewModel.state)),<br>      ],<br>    );<br>  }<br><br>  Widget _buildStateWidget(CartState state) {<br>    if (state is Initial) {<br>      return Center(child: Text(&#39;No items in cart&#39;));<br>    } else if (state is Loading) {<br>      return const Center(child: CircularProgressIndicator());<br>    } else if (state is Success) {<br>      return ListView.builder(<br>        itemCount: state.cart.length,<br>        itemBuilder: (context, index) {<br>          final product = state.cart[index];<br>          return ListTile(title: Text(product.name), subtitle: Text(&#39;\$${product.price}&#39;));<br>        },<br>      );<br>    } else if (state is Error) {<br>      return Center(child: Text(&#39;Error: ${state.message}&#39;));<br>    } else {<br>      return Container();<br>    }<br>  }<br>}</pre><h4>The Result</h4><p>By separating concerns into distinct layers, we’ve achieved a more maintainable and scalable app architecture. Our code is now cleaner, easier to understand, and — dare I say it? — less prone to errors.</p><p>In conclusion, MVVM Architecture is all about creating a solid foundation for your app by separating concerns into three clear layers: Model, ViewModel, and View. By doing so, you’ll be able to build scalable, maintainable apps with ease.</p><p>So, there you have it! I hope this example has demonstrated the power of MVVM Architecture coupled with Sealed Class in practice. Happy coding, everyone!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=077ecf7811d7" width="1" height="1" alt=""><hr><p><a href="https://www.designsystemscollective.com/mvvm-architecture-with-sealed-classes-in-flutter-building-scalable-apps-077ecf7811d7">MVVM Architecture with Sealed Classes in Flutter Building Scalable Apps</a> was originally published in <a href="https://www.designsystemscollective.com/">Design Systems Collective</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[The Double-Edged Sword of LLMs: Can We Harness Their Power Without Destroying the Planet?]]></title>
            <link>https://medium.com/geekculture/the-double-edged-sword-of-llms-can-we-harness-their-power-without-destroying-the-planet-f4409d1c2319?source=rss-c32d69521c27------2</link>
            <guid isPermaLink="false">https://medium.com/p/f4409d1c2319</guid>
            <category><![CDATA[enviornment]]></category>
            <category><![CDATA[myths]]></category>
            <category><![CDATA[ai]]></category>
            <dc:creator><![CDATA[Siddhesh Shivdikar]]></dc:creator>
            <pubDate>Sat, 25 Jan 2025 08:56:47 GMT</pubDate>
            <atom:updated>2025-01-25T08:56:47.328Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*EY-NgcqJ31QaOnlC" /><figcaption>Photo by <a href="https://unsplash.com/@mwrona?utm_source=medium&amp;utm_medium=referral">m wrona</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><p>As we continue to dive deeper into the world of Artificial Intelligence (AI) and Large Language Models (LLMs), one pressing question remains: are we using these incredible tools responsibly, or are we simply creating more problems than solutions?</p><p>Take a step back, and let’s consider the elephant in the room — energy consumption. Training LLMs requires massive computational power, which is nothing short of electricity-intensive. We’re talking about the kind of energy that can power entire cities, folks! In fact, studies have shown that training a single large language model can generate as much CO2 as hundreds of round-trip flights between major cities.</p><h3>The Dark Side of LLMs</h3><p>So, what’s behind this alarming carbon footprint? Well, it all comes down to the way we’re building these massive models. The electricity used to power them often comes from sources that generate greenhouse gases, contributing to climate change. And let’s not forget about hardware production — the manufacturing of specialized hardware (GPUs, servers, etc.) needed for LLMs also has an environmental impact, including resource depletion and pollution.</p><h3>LLMs: More Than Just a Fast Automated Encyclopedia</h3><p>But here’s the thing — LLMs aren’t just information retrieval engines. They can generate new text, translate languages, summarize information, and even engage in conversations. However, this raises some crucial questions about their limitations:</p><blockquote>Can they truly “create” new concepts or ideas?</blockquote><blockquote>Are they simply recombining existing information in novel ways?</blockquote><p>The answer is… sort of. LLMs don’t create genuinely new concepts in the way a human innovator or scientist does. They generate novel combinations of existing concepts and information, much like a remix of existing music.</p><h3>A Nuanced Look at LLMs</h3><p>So, why use LLMs for summarisation and nuance? Here are some compelling reasons:</p><p>Scale and speed: LLMs can process and summarize vast amounts of information far faster than any human.</p><p>Consistency: LLMs can apply consistent criteria for summarization and analysis, reducing human bias.</p><p>Accessibility: LLMs can make complex information more accessible to a wider audience by providing simplified summaries or translations.</p><p>However, this brings us back to the question of true understanding. LLMs operate primarily through inference, identifying statistical patterns in data. They don’t have true understanding, reasoning, or common sense. This means they can generate incorrect or misleading information if:</p><p>The training data contains biases or inaccuracies.</p><p>The context of a query is ambiguous.</p><p>They encounter a situation outside the scope of their training data.</p><h3>The Bottom Line</h3><p>LLMs are powerful tools for processing and manipulating information, but they’re not a substitute for human intelligence, critical thinking, or creativity. We need to use them as aids to human endeavors, not replacements.</p><p>So, how can we harness the power of LLMs without destroying the planet? Here are some potential solutions:</p><p>Renewable energy: Invest in renewable energy sources to power our AI infrastructure.</p><p>Energy-efficient design: Design hardware and software that’s more energy-efficient and requires less computational power.</p><p>Transparency and accountability: Develop transparent models that explain their decision-making processes, reducing the risk of biases and inaccuracies.</p><p>In conclusion, LLMs are a double-edged sword. They have the potential to revolutionise the way we process information, but we need to use them responsibly. As we continue to explore the possibilities of AI, let’s remember that with great power comes great responsibility.</p><p>So, what do you think? Are you ready to join the conversation and help shape the future of LLMs? Share your thoughts in the comments below! Happy Coding</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=f4409d1c2319" width="1" height="1" alt=""><hr><p><a href="https://medium.com/geekculture/the-double-edged-sword-of-llms-can-we-harness-their-power-without-destroying-the-planet-f4409d1c2319">The Double-Edged Sword of LLMs: Can We Harness Their Power Without Destroying the Planet?</a> was originally published in <a href="https://medium.com/geekculture">Geek Culture</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Debunk AI : Separating Fact from Fiction]]></title>
            <link>https://siddheshshivdikar.medium.com/debunk-ai-separating-fact-from-fiction-20e282d5cc8b?source=rss-c32d69521c27------2</link>
            <guid isPermaLink="false">https://medium.com/p/20e282d5cc8b</guid>
            <category><![CDATA[enviornment]]></category>
            <category><![CDATA[ai]]></category>
            <category><![CDATA[facts]]></category>
            <dc:creator><![CDATA[Siddhesh Shivdikar]]></dc:creator>
            <pubDate>Wed, 22 Jan 2025 07:38:48 GMT</pubDate>
            <atom:updated>2025-01-22T07:38:48.580Z</atom:updated>
            <content:encoded><![CDATA[<h3><strong>Debunk AI : Separating Fact from Fiction</strong></h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*pD59UmoPWIkcM1kf" /><figcaption>Photo by <a href="https://unsplash.com/@emilianovittoriosi?utm_source=medium&amp;utm_medium=referral">Emiliano Vittoriosi</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><p>We live in an age of unprecedented technological advancement, where the whispers of artificial intelligence have grown into a roar. Headlines scream of sentient machines, job-stealing algorithms, and a future shaped by silicon minds. But behind the dazzling spectacle lies a complex reality, often obscured by hype and misunderstanding. This book seeks to cut through the noise, offering a grounded perspective on the true nature of AI, its capabilities, its limitations, and, most importantly, its potential dangers. Inspired by the insightful work of computer scientists like Arvind Narayanan and Sayash Kapoor, we aim to debunk the myths surrounding AI and foster a more informed and responsible approach to its development and deployment.</p><p><strong>Chapter 1: The Hype Machine</strong></p><p>The narrative around AI is often one of breathless excitement, fueled by media sensationalism and marketing campaigns. We are presented with images of robots with human-like intelligence, capable of solving all our problems and ushering in a new era of prosperity. This chapter examines the origins of this hype, tracing it back to early visions of AI and exploring how it has been amplified by recent advancements in machine learning. We discuss the dangers of this overblown rhetoric, which can lead to unrealistic expectations, misplaced trust, and a failure to address genuine concerns.</p><p><strong>Chapter 2: What AI Actually Is (and Isn’t)</strong></p><p>This chapter delves into the technical realities of AI, explaining the underlying principles of machine learning, deep learning, and other core concepts. We demystify the “black box” of AI, explaining how algorithms learn from data and make predictions. Crucially, we emphasize the distinction between <em>narrow</em> or <em>weak</em> AI, which is designed for specific tasks, and <em>general</em> or <em>strong</em> AI, which would possess human-level intelligence. We argue that current AI systems are firmly in the realm of narrow AI, excelling at tasks like image recognition and language processing but lacking true understanding, consciousness, or common sense.</p><p><strong>Chapter 3: The Bias in the Machine</strong></p><p>One of the most pressing concerns surrounding AI is the issue of bias. AI systems are trained on data, and if that data reflects existing societal biases, the AI will inevitably perpetuate and even amplify them. This chapter explores the various ways bias can creep into AI systems, from biased training data to flawed algorithms. We examine real-world examples, such as biased facial recognition systems and algorithms that perpetuate discriminatory lending practices, highlighting the real-world consequences of these biases.</p><p><strong>Chapter 4: The Misinformation Factory</strong></p><p>The ability of AI to generate realistic text, images, and videos has raised serious concerns about its potential for misuse in creating and spreading misinformation. This chapter explores the dangers of AI-generated fake news, deepfakes, and other forms of synthetic media. We discuss how these technologies can be used to manipulate public opinion, sow discord, and undermine trust in legitimate sources of information. We also explore potential solutions, such as watermarking and detection algorithms, but emphasize the need for a multi-faceted approach that includes media literacy and critical thinking.</p><p><strong>Chapter 5: The Automation Paradox</strong></p><p>The increasing automation of tasks by AI raises important questions about the future of work. While AI has the potential to increase efficiency and productivity, it also poses a threat to jobs in various sectors. This chapter examines the potential impact of AI on the labor market, discussing the types of jobs that are most at risk and the potential for job displacement. We also explore the possibility of creating new jobs and industries related to AI, but emphasize the need for proactive policies to mitigate the negative impacts of automation.</p><p><strong>Chapter 6: Responsible AI: A Path Forward</strong></p><p>This concluding chapter outlines a path towards responsible AI development and deployment. We argue for the need for greater transparency and accountability in AI systems, as well as the importance of ethical guidelines and regulations. We emphasize the need for interdisciplinary collaboration between computer scientists, ethicists, policymakers, and the public to ensure that AI is used for the benefit of humanity. We call for a shift away from the hype-driven narrative towards a more grounded and realistic understanding of AI, one that acknowledges its limitations and addresses its potential dangers.</p><p><strong>Conclusion:</strong></p><p>AI is a powerful technology with the potential to transform our world in profound ways. However, it is essential to approach it with a clear understanding of its capabilities and limitations. By debunking the myths and addressing the real concerns, we can pave the way for a future where AI is used responsibly and ethically, for the betterment of society.</p><p>This is a basic outline. Each chapter could be expanded significantly with further research, examples, and analysis. This framework, however, directly addresses the core themes presented in the video you referenced.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=20e282d5cc8b" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Getting ready for developing iOS apps in Kotlin Multiplatform on MacOS.]]></title>
            <link>https://medium.com/geekculture/getting-ready-for-developing-ios-apps-in-kotlin-multiplatform-on-macos-fa7307b6467a?source=rss-c32d69521c27------2</link>
            <guid isPermaLink="false">https://medium.com/p/fa7307b6467a</guid>
            <category><![CDATA[mobile-app-development]]></category>
            <category><![CDATA[kotlin]]></category>
            <category><![CDATA[xcode]]></category>
            <dc:creator><![CDATA[Siddhesh Shivdikar]]></dc:creator>
            <pubDate>Fri, 09 Aug 2024 00:19:38 GMT</pubDate>
            <atom:updated>2024-08-09T00:19:38.829Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*w-Cs5ttiOm364yRSw2N5oA.png" /></figure><h3>Before starting lets make sure that we have the KMP plugin Installed in Android Studio.</h3><p>https://plugins.jetbrains.com/plugin/14936-kotlin-multiplatform/versions/dev</p><h3>Installing Xcode</h3><ol><li><strong>Download Xcode</strong>:</li></ol><ul><li>Xcode can be downloaded from the Mac App Store. Simply search for “Xcode” and click “Get” to install. Make sure you select to develop on iOS devices at the start.</li></ul><ol><li><strong>Install Xcode</strong>:</li></ol><ul><li>After downloading, Xcode will automatically install. You can find it in your /Applications directory.</li></ul><h3>Configuring Command Line Tools (Can’t find Xcode installed error)</h3><p>Once Xcode is installed, you need to configure the command line tools to ensure that build scripts and terminal commands can utilize Xcode’s build tools, compilers, and other utilities.</p><ol><li><strong>Open Xcode</strong>:</li></ol><ul><li>Navigate to your Applications folder and double-click on Xcode to open it.</li></ul><p><strong>2. Access Preferences</strong>:</p><ul><li>In Xcode, go to the menu bar at the top of the screen, select “Xcode,” and then choose “Preferences” from the dropdown menu.</li></ul><p><strong>3. Navigate to the Locations Tab</strong>:</p><ul><li>In the Preferences window, click on the “Locations” tab to view various settings related to Xcode installations and locations of supporting files.</li></ul><p><strong>4. Set the Command Line Tools</strong>:</p><ul><li>In the “Locations” panel, you’ll see an option for “Command Line Tools” (as shown in your screenshot). Use the dropdown menu to select the version of Xcode you wish to use for command line tools. This should typically be the latest version installed, such as Xcode 15.4.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*uCPTqMp8PegEi-xRkYtoCQ.png" /></figure><p>Developing with Kotlin Multiplatform applications often requires switching between different Java versions to ensure compatibility across new and existing projects. With macOS, you can manage multiple Java versions efficiently using Homebrew and set up your environment to switch between them seamlessly. This guide will walk you through the process of installing and configuring multiple Java versions for your Kotlin Multiplatform projects.</p><p>Before you begin, ensure you have Homebrew installed on your macOS. If not, you can install it by running the following command in your terminal:</p><pre>`/bin/bash -c &quot;$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)&quot;</pre><h3>Installing Multiple Java Versions</h3><p>To manage Java versions efficiently, we’ll use the <a href="https://adoptium.net/">Adoptium Temurin</a> OpenJDK builds, which are available through Homebrew.</p><p>1. <strong>Remove any previous AdoptOpenJDK taps</strong> (if applicable):</p><pre>brew untap AdoptOpenJDK/openjdk</pre><p>2. <strong>Install the Temurin versions</strong>:</p><pre>brew install --cask temurin    # This installs the latest LTS version<br>brew tap homebrew/cask-versions<br>brew install --cask temurin@8<br>brew install --cask temurin@11<br>brew install --cask temurin@17<br>brew install --cask temurin@18<br>brew install --cask temurin@19<br>brew install --cask temurin@21</pre><h3>Configuring Your Shell for Java Version Switching</h3><p>To switch between different Java versions, you need to configure your shell’s profile file (.bash_profile for Bash or .zshrc for Zsh). This setup involves defining environment variables and aliases for each Java version.</p><ol><li><strong>Open your profile file</strong>:</li></ol><pre># For Bash<br>nano ~/.bash_profile<br><br># For Zsh<br>nano ~/.zshrc</pre><p>2. <strong>Add the following configuration to your profile file</strong>:</p><pre># Java Home Paths<br>export JAVA_8_HOME=$(/usr/libexec/java_home -v1.8)<br>export JAVA_11_HOME=$(/usr/libexec/java_home -v11)<br>export JAVA_17_HOME=$(/usr/libexec/java_home -v17)<br>export JAVA_18_HOME=$(/usr/libexec/java_home -v18)<br>export JAVA_19_HOME=$(/usr/libexec/java_home -v19)<br>export JAVA_21_HOME=$(/usr/libexec/java_home -v21)<br># Aliases for switching Java versions<br>alias java8=&#39;export JAVA_HOME=$JAVA_8_HOME&#39;<br>alias java11=&#39;export JAVA_HOME=$JAVA_11_HOME&#39;<br>alias java17=&#39;export JAVA_HOME=$JAVA_17_HOME&#39;<br>alias java18=&#39;export JAVA_HOME=$JAVA_18_HOME&#39;<br>alias java19=&#39;export JAVA_HOME=$JAVA_19_HOME&#39;<br>alias java21=&#39;export JAVA_HOME=$JAVA_21_HOME&#39;<br><br># Set default Java version I am setting mine to use java 11 to build my KMM App<br>java11</pre><p>3. <strong>Apply the changes</strong>:</p><pre># For Bash<br>source ~/.bash_profile<br><br># For Zsh<br>source ~/.zshrc</pre><h3>Switching Between Java Versions</h3><p>With the configuration above, you can easily switch between different Java versions by using the aliases defined. For example:</p><pre>java18</pre><h3>Running the iOS application on the Apple simulator.</h3><p>1. Open android studio select your build your iOS app your configuration should look something like this.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*kOoZJM_yNpNP3kHQ8UrOdA.png" /></figure><h3>Conclusion</h3><p>For Kotlin Multiplatform development, having the correct setup ensures that your build scripts can execute without issues, particularly when dealing with iOS targets or when you need to perform tasks that require native macOS compatibility.</p><p>This setup not only streamlines your development process but also ensures that all components of your project can be built using a consistent environment, reducing the likelihood of encountering build-related errors. By following this guide, you can streamline your development workflow and focus on building great applications.</p><p>Feel free to share your thoughts and experiences in the comments below, and happy coding!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=fa7307b6467a" width="1" height="1" alt=""><hr><p><a href="https://medium.com/geekculture/getting-ready-for-developing-ios-apps-in-kotlin-multiplatform-on-macos-fa7307b6467a">Getting ready for developing iOS apps in Kotlin Multiplatform on MacOS.</a> was originally published in <a href="https://medium.com/geekculture">Geek Culture</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Dynamic web scraping using selenium : scrape protected websites]]></title>
            <link>https://medium.com/geekculture/dynamic-web-scraping-using-selenium-scrape-protected-websites-401de3497939?source=rss-c32d69521c27------2</link>
            <guid isPermaLink="false">https://medium.com/p/401de3497939</guid>
            <category><![CDATA[data-science]]></category>
            <category><![CDATA[python]]></category>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[web-development]]></category>
            <category><![CDATA[automation]]></category>
            <dc:creator><![CDATA[Siddhesh Shivdikar]]></dc:creator>
            <pubDate>Wed, 22 Jun 2022 20:17:27 GMT</pubDate>
            <atom:updated>2022-07-14T07:03:04.780Z</atom:updated>
            <content:encoded><![CDATA[<h3>Dynamic web scraping using selenium : scrape protected websites</h3><figure><img alt="&lt;a href=”http://www.freepik.com&quot;&gt;Designed by upklyak / Freepik&lt;/a&gt;" src="https://cdn-images-1.medium.com/max/1024/1*v7z2ER4MOcqaJJGDy6DhQg.png" /><figcaption>Designed by upklyak</figcaption></figure><h4>But ! we already covered everything last time ! 😤</h4><p>In my last article we used beautiful soup to scrape the information from webpages we might have covered up almost every important aspects and methodologies including including all the different types, crawling, bot protection, Automation, Scraping through NLP but ! Beautiful Soup can only Handel static webpages not dynamic *Mic Drop* 🎤</p><blockquote>If you are new to scraping or need to get through advance concepts here is the article to check out</blockquote><p><a href="https://medium.com/geekculture/getting-started-with-web-scraping-for-data-analysis-fe55cc0b8d61">https://medium.com/geekculture/getting-started-with-web-scraping-for-data-analysis-fe55cc0b8d61</a></p><h4>What’s the difference between static and dynamic webpages then 🥲</h4><p>Awesome question you’ve asked ! static webpages uses the content which is directly embedded in your code where as in dynamic webpages <strong>generates </strong>the data from javascript and places them in DOM elements instead. keeping it simple</p><h4>Okay Scenario time 🫣</h4><p>Consider you are scraping website with elements who uses pagination but you guessed it right when we click on the link the url is not updated. Which means we cant use crawling ! 😣 Which means we try to do every possible thing with beautiful-soup but it dosent work ! 😖 Which means you found no HTML Fragments which loads data on request to scrape ! 😫 Which means no more Nutella 😩 … wait Nutella is love</p><h4>Why Selenium though 🤔</h4><p>Well glad you asked 🤗 not just Selenium but Selenium + beautiful Soup *old love still got some kick in it* Selenium in simple terms mimics an user interacting with browser. In broader terms though Selenium is a framework which can run and execute the scripts and control your web browser by sending and receiving methods calls and data to or from the Web Driver which bridges your browser with selenium. So yea I had to install Chrome but yea if you dont have Chrome or Firefox just install them at this point. Fun fact various Automation apps that you know use selenium.</p><h4>Quiz time before we start 😌</h4><p>If you’ve visited planet Earth you probably know Australia where there’s a chemists who has a warehouse. Congratulation you know the website we are scraping ! 🥳</p><h4>Installing the pre requisits 🛠</h4><pre># Run the commands below once <br>!pip install beautifulsoup4<br>!pip install requests<br>!pip install selenium<br>!pip install webdriver-manager</pre><h4>Getting our Imports 😌</h4><pre>import requests<br>from bs4 import BeautifulSoup<br>import pandas<br>import time<br>from selenium import webdriver<br>#dynamic scraping using selenium and beautiful soup<br>options = webdriver.ChromeOptions()<br>options.add_argument(&#39;--ignore-certificate-errors&#39;)<br>options.add_argument(&#39;--incognito&#39;)<br>options.add_argument(&#39;--headless&#39;)<br>driver = webdriver.Chrome(&quot;*insert_your_directory*/chromedriver&quot;, chrome_options=options)<br>from selenium import webdriver<br>from webdriver_manager.chrome import ChromeDriverManager<br>from selenium.webdriver.common.by import By<br>driver = webdriver.Chrome(ChromeDriverManager().install())</pre><p>Make sure that you have correct path of webdriver. I prefer downloading web driver manually from the web and keep it in pwd.</p><h4>Conjuring 3 Selenium made me do it 👻</h4><p>We are going to make the browser click the next button through selenium fetch the source from <strong>Selenium instead of requests</strong> like we did last time. This should work because we are simulating the browser like if there are 63 pages for each page we’ll click next button Scrape ! *java script loads the content* Scrape ! java script loads the content again Scrape ! repeat well selenium will start using your browser and now it’s possessed</p><pre>driver.get(&quot;The_link_that_you_found_via_quiz&quot;)<br>src = driver.page_source<br>soup = BeautifulSoup(src, &#39;lxml&#39;)<br>final_list = []<br>df = []<br>for i in range(62):<br>    src = driver.page_source<br>    soup = BeautifulSoup(src, &#39;lxml&#39;)<br>    product = soup.find_all(&#39;div&#39;, class_=&#39;product&#39;)<br>    l = []<br>    for item in product:<br>        d={}<br>        d[&quot;Name&quot;] = (item.find(&#39;div&#39;, class_ =&#39;product__title&#39;).text.replace(&quot;[&quot;,&quot;&quot;).replace(&quot;]&quot;,&quot;&quot;))<br>        d[&quot;Price&quot;] = (item.find(&#39;span&#39;, class_ =&#39;product__price-current&#39;).text.replace(&quot;[&quot;,&quot;&quot;).replace(&quot;]&quot;,&quot;&quot;))<br>        d[&quot;Discount&quot;] = (item.find(&#39;em&#39;, class_ =&#39;product__price-discount&#39;))<br>        l.append(d)<br>        <br>    final_list.extend(l)<br>    <br>    next_button = driver.find_elements(by=By.CLASS_NAME, value=&quot;pager__button--next&quot;)</pre><pre>try:<br>        if next_button[0].is_displayed():<br>            driver.execute_script(&quot;arguments[0].click();&quot;,next_button[0])<br>            time.sleep(1)<br>    except:<br>        pass<br>    <br>df = pandas.DataFrame(final_list)</pre><pre>df.to_csv(&quot;xoxo.csv&quot;)<br>df.to_excel(&quot;xoxo.xlsx&quot;)</pre><h4>See ya 👋</h4><p>Concluding this there is not much left to explain but its just a start to dive deeper into selenium since selenium is not only limited to web scraping but remember Every time the GPU gets sold out in 1 sec ? Even the NFT’s ?Selenium did you dirty my friend. But everyday it’s a chance to learn new stuff and happy coding 🫡</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=401de3497939" width="1" height="1" alt=""><hr><p><a href="https://medium.com/geekculture/dynamic-web-scraping-using-selenium-scrape-protected-websites-401de3497939">Dynamic web scraping using selenium : scrape protected websites</a> was originally published in <a href="https://medium.com/geekculture">Geek Culture</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[The overpowered open-cv cheat sheet for AI and M ]]></title>
            <link>https://medium.com/geekculture/the-overpowered-open-cv-cheat-sheet-c1825bd02bf6?source=rss-c32d69521c27------2</link>
            <guid isPermaLink="false">https://medium.com/p/c1825bd02bf6</guid>
            <category><![CDATA[machine-learning]]></category>
            <category><![CDATA[python]]></category>
            <category><![CDATA[computer-vision]]></category>
            <category><![CDATA[artificial-intelligence]]></category>
            <category><![CDATA[data-science]]></category>
            <dc:creator><![CDATA[Siddhesh Shivdikar]]></dc:creator>
            <pubDate>Sun, 01 May 2022 01:15:49 GMT</pubDate>
            <atom:updated>2022-05-13T07:23:13.156Z</atom:updated>
            <content:encoded><![CDATA[<h4>from zero to master</h4><p>The world of image processing and computer vision is a sweet spot for starting machine learning and artificial intelligence projects. Through this post I will be mentioning various image processing techniques and computer vision techniques which will help you to complete your vision-based machine learning and artificial intelligence projects with ease.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*GOA8EQMEg1rjum6y" /><figcaption>Photo by <a href="https://unsplash.com/@paman0744?utm_source=medium&amp;utm_medium=referral">Aman Pal</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><p>Let me tell you a little more about this cheatsheet. This notebook will contain all the Important and effective methods of image processing starting from the basics to the advance you can bookmark this sheet for your quick insights and codes snippets. My aim for creating this cheat sheet is to have all the important image processing and manipulation methods at one source which would make even newcomers understand the flow and implementation.</p><p>we’ll have the code snippets the output and the understanding of the program block throughout this article I will also provide a link to a python notebook where you can run everything that We’ll go through in this article</p><p>For running the code snippet I’m gonna use python 3.8 with open CV which is a computer vision library in python which will help us to carry out our image processing and manipulation techniques. You are new to any of these things I will recommend you to search about anaconda, Jupiter notebook or in case if you are using Google Colaboratory you’ll require to mount your Google Drive as well.</p><p>There are three important terms that we need to acquaint ourselves with before getting our hands dirty. Computer vision, image processing and image manipulation.</p><p>let’s define computer vision in simple terms, Computer vision is artificial intelligence technique in which computers can interpret, understand and extract knowledge from an image or video. which means it helps a computer to see. Image processing can be simplified as methods or operation performed on images to enhance or extract useful information. So called as features from an image. Image manipulation can be referred as altering the properties of digital image to achieve desire results. I’ll provide the examples of all the three terms as we proceed.</p><blockquote>Warning if you use MacBook M1 like me i had some troubles while exiting the preview might be a beta OS but you can still use the in notebook preview.</blockquote><p>Start by installing the package open CV in python you can use the following command in your anaconda prompt or you can install it through your notebook</p><p>But this article is lengthy and many peoples might be on time crunch so I’m linking the notebook link prior</p><p><a href="https://github.com/siddheshshivdikar/open-cv-cheatbook">https://github.com/siddheshshivdikar/open-cv-cheatbook</a></p><pre>!pip install opencv-python<br>!pip install matplotlib<br>!pip install numpy</pre><p>Along with this include your favourite image which you would have fun with (Three years back i chose the image of my Favourite singer ❤️💁)</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/349/1*hhD7i853nFeTsoM6K0FH3Q.png" /><figcaption>Gonna use the same image throughout 😋</figcaption></figure><p>Now let’s import the packages in our notebook</p><pre>import sys<br>import os<br>import cv2<br>import numpy as np<br>from matplotlib import pyplot as plt</pre><p>Lets start by opening and displaying an image in our notebook I have created a folder named “images” in same directory</p><pre>input = cv2.imread(&quot;./images/image_name.jpg&quot;)<br>plt.axis(&quot;off&quot;)<br>plt.imshow(input) #replace this with later for full screen image<br>plt.show()</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/349/1*LKmLKOigkYoOf3Tug43CDA.png" /><figcaption>Wait whaaa ! 😕</figcaption></figure><h4>I thought RGB was my soulmate 😩 then why BGR ? 😵‍💫</h4><p>Important point to remember is by default opencv uses BGR as the colour format instead of RGB so when you try to preview an image in Matplotlib it might seem weird. If you ask why ? Then let me answer it for you. like metric and imperial systems, BGR colour space was a popular among the colour manufacturers and software providers which led early developers at open CV to choose it as their format. You’ll get habitual of it eventually …</p><p>Here is how you convert it just replace the line above and everything will look right !</p><pre><br>plt.imshow(cv2.cvtColor(input, cv2.COLOR_BGR2RGB))</pre><h4>Simple yet the most important ✨ Grayscale</h4><p>Even though converting colour image to greyscale results into losing information it&#39;s gonna be more useful in feature extraction like detecting features in face recognition tasks moreover improving the performance metrics. so Grayscale is a range of monochromatic shades from black to white without any color. I will mention both the formats of conversion below</p><pre>#plt.imshow(cv2.cvtColor(input, cv2.COLOR_BGR2GRAY)) # BGR TO GRAY</pre><pre>g_input = cv2.imread(&quot;./images/image_name.jpg&quot;, 0) # 0 converts into GS </pre><pre>plt.title(&quot;Grayscale&quot;)plt.axis(&quot;off&quot;)<br>plt.imshow(cv2.cvtColor(g_input, cv2.COLOR_BGR2RGB))<br>plt.show()</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/349/1*0CN-tyQ7v6E69L49zy5q-A.png" /></figure><h4>Lets take a look at bigger picture 🤭</h4><p>We can even display the images which are obtained from output in a window outside our notebook. This can be a confusing process as it&#39;s not as straightforward as it seems first you have to use cv2.imshow() followed by cv2.waitKey() which waits for a key after a delay that you specified . When that key is pressed the program resumes . Now for closing the windows we’ll use cv2.destroyAllWindows(). Give it a try</p><pre>#For windows <br>cv2.imshow(&#39;Chrissy Grey&#39;, g_input)<br>cv2.waitKey()<br>cv2.destroyAllWindows()</pre><pre>#If it dosen&#39;t run on Mac then<br>cv2.imshow(&#39;Chrissy Grey&#39;, g_input)<br>cv2.waitKey(1)<br>cv2.destroyAllWindows(&#39;frames&#39;)</pre><h4>Hue Saturation Value; three gems 💎</h4><p>HSV color space is consists of 3 matrices, ‘hue’, ‘saturation’ and ‘value’. In OpenCV, value range for ‘hue’, ‘saturation’ and ‘value’ are respectively 0–179, 0–255 and 0–255. ‘Hue’ represents the color, ‘saturation’ represents the amount to which that respective color is mixed with white and ‘value’ represents the amount to which that respective color is mixed with black.</p><blockquote>a wise man said Its better for object detection and tracking than rgb format</blockquote><p>wanna know why ? It’s because HSV is the most suitable color space for<strong> color based image segmentation </strong>a since R,G,B components of object are correlated with the amount of light captured by hitting the object make object discrimination difficult. In HSV we can separate the luminance. BTW did you know that we can also extract the individual components like H,S and V ? will show that as well</p><pre>plt.title(&quot;Converted to HSV&quot;)<br>plt.axis(&quot;off&quot;)<br>plt.imshow(cv2.cvtColor(h_input, cv2.COLOR_BGR2RGB))<br>plt.show()<br>plt.title(&quot;Hue Sepration&quot;)<br>plt.axis(&quot;off&quot;)<br>plt.imshow(cv2.cvtColor(h_input[:,:,0], cv2.COLOR_BGR2RGB))<br>plt.show()<br>plt.title(&quot;Saturation Sepration&quot;)<br>plt.axis(&quot;off&quot;)<br>plt.imshow(cv2.cvtColor(h_input[:,:,1], cv2.COLOR_BGR2RGB))<br>plt.show()<br>plt.title(&quot;Value Sepration&quot;)<br>plt.axis(&quot;off&quot;)<br>plt.imshow(cv2.cvtColor(h_input[:,:,2], cv2.COLOR_BGR2RGB))<br>plt.show()</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/349/1*Z2u2OF0erjt05nDNc0WubA.png" /><figcaption>This is HSV conversion of our image.</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/349/1*_5Q1Y_6Kc4EkEAakzhRaag.png" /><figcaption>Do you find any Background elements ?</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/349/1*zLojYHK7H5NVuIINFUIAOQ.png" /><figcaption>Better edges and facial features like boundaries ?</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/349/1*IeNgskj03oBDwMjoq89SqA.png" /><figcaption>Better Luminosity ?</figcaption></figure><p>Aren&#39;t this results fascinating and we haven&#39;t even started any complex methods. just to prove it to you lets separate the R,G,B components as well ; I’ve inserted three images above just because I had to show you the different features by separate different channels let&#39;s save some space by concatenating different colours channels images that we are going to seperate. Note that you have to separate it in the order of BGR.</p><pre>B, G, R = cv2.split(input) # used to split into respective channels</pre><pre>#cv2.imshow(&#39;Red&#39;, R)<br>#cv2.imshow(&#39;Green&#39;, G)<br>#cv2.imshow(&#39;Blue&#39;, B)<br>#plt.axis(&quot;off&quot;)<br>#plt.imshow(cv2.cvtColor(R, cv2.COLOR_BGR2RGB))<br>#plt.show()<br>#plt.axis(&quot;off&quot;)<br>#plt.imshow(cv2.cvtColor(G, cv2.COLOR_BGR2RGB))<br>#plt.show()<br>#plt.axis(&quot;off&quot;)<br>#plt.imshow(cv2.cvtColor(B, cv2.COLOR_BGR2RGB))<br>#plt.show()</pre><pre>concat = cv2.hconcat([R,G,B]) <br># or np.hstack([img,img]) use np.vstack and cv2.vconcat([img,img]) for vertical <br>plt.title(&quot;Red Green and Blue Channels&quot;)<br>plt.axis(&quot;off&quot;)<br>plt.imshow(cv2.cvtColor(concat, cv2.COLOR_BGR2RGB))<br>plt.show()</pre><pre>#cv2.waitKey()<br>#cv2.destroyAllWindows()</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/349/1*lQot6SmLvUDXjxmBd5OeVg.png" /><figcaption>Saw the difference ?</figcaption></figure><p>Likewise if you merge the channels you will get the original image back, give it a try.</p><pre>merged = cv2.merge([B,G,R])</pre><h4>I wish the sky looked deeper blue 🏙</h4><p>Nowadays many algorithms of image processing makes the sky look beautiful and bluer we can try to mimic it in a simple way by amplifying the channels and it obviously has to be the blue one. these are the simple things that would help us in the long run</p><pre>amplify = cv2.merge([B+50,G,R])<br>#cv2.imshow(&#39;Amplify&#39;, amplify)<br>plt.axis(&quot;off&quot;)<br>plt.imshow(cv2.cvtColor(amplify, cv2.COLOR_BGR2RGB))<br>plt.show()<br>#cv2.waitKey()<br>#cv2.destroyAllWindows()</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/349/1*x-IIaoCgZ8HOFumdpPXMfQ.png" /><figcaption>Way better than before ✨</figcaption></figure><p>similarly we can separate the channel components as well ❤️💚💙 Why though you’d ask ? could be as simple as just extracting red coloured shape or image segmentation using color mask</p><pre>zeros = np.zeros(input.shape[:2], dtype = &#39;uint8&#39;)<br># cv2.imshow(&quot;Red&quot;,cv2.merge([zeros,zeros,R]))<br># cv2.imshow(&quot;Green&quot;,cv2.merge([zeros,G,zeros]))<br># cv2.imshow(&quot;Blue&quot;,cv2.merge([B,zeros,zeros]))<br># cv2.waitKey()<br># cv2.destroyAllWindows()<br>plt.title(&quot;Red Channel&quot;)<br>plt.axis(&quot;off&quot;)<br>plt.imshow(cv2.cvtColor(cv2.merge([zeros,zeros,R]), cv2.COLOR_BGR2RGB))<br>plt.show()<br>plt.title(&quot;Blue Channel&quot;)<br>plt.axis(&quot;off&quot;)<br>plt.imshow(cv2.cvtColor(cv2.merge([zeros,G,zeros]), cv2.COLOR_BGR2RGB))<br>plt.show()<br>plt.title(&quot;Green Channel&quot;)<br>plt.axis(&quot;off&quot;)<br>plt.imshow(cv2.cvtColor(cv2.merge([B,zeros,zeros]), cv2.COLOR_BGR2RGB))<br>plt.show()</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/349/1*oFeZ0A99C3Wom39RTj8Y4Q.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/349/1*3W6D5u7InJo-VxhB3mwD4g.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/349/1*k9BgNYAodi9x6AenHGRD-A.png" /></figure><h4>Let me tell you that Histograms are underrated 😔</h4><p>The histogram basically shows you how many <strong>shadows</strong>, <strong>midtones</strong>, and <strong>highlights</strong> there are in the image with their location, for dataset image manipulation histograms can make an impact on your understanding as well.</p><pre>histogram = cv2.calcHist([input],[0], None,[256],[0,256])<br>plt.hist(input.ravel(), 256,[0,256])<br>plt.show()</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/387/1*UNy_8K7Fy0YH7ZaGYz7HLA.png" /></figure><pre>#lets look at colors through histogram as well<br>color = (&#39;b&#39;,&#39;g&#39;,&#39;r&#39;)<br>for i, col in enumerate(color):<br>    histogram = cv2.calcHist([input], [i], None, [256], [0, 256])<br>    plt.plot(histogram, color =  col)<br>    plt.xlim([0,256])<br>plt.show</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/389/1*R8TO45lNolbnn7eutTsL8w.png" /></figure><h4>Lets start from blank 😶</h4><p>We all know whats a bounding box, polygons in face recognition or every saw those lane in Lane detection now we are gonna implement the bases so next time you need to highlight them you know what exactly to do. Lets start by a blank canvas.</p><pre># mac users change the following destroy window function if you are directly jumping on this</pre><pre>image =  np.zeros((720,720,3), np.uint8)<br>gimage =  np.zeros((720,720), np.uint8)</pre><pre>cv2.imshow(&quot;BGR&quot;,image)<br>cv2.imshow(&quot;Grey Scale&quot;,gimage)</pre><pre>cv2.waitKey(0)<br>cv2.destroyAllWindows()</pre><p>Drawing a simple lines over the generated image I’ve explained the parameters in the comments pretty straight forward no pun intended 😂</p><pre>image =  np.zeros((720,720,3), np.uint8)<br>cv2.line(image, (0,0),(500,720), (157,229,16), 5)<br>cv2.line(image, (720,720),(500,0), (157,229,16), 5)<br>#here (0,0) is the origin <br>#(500,50) is the the end<br>#(157,229,16) is the BGR value of the line<br>#5 is the thickness in pixels<br>plt.axis(&quot;off&quot;)<br>plt.imshow(cv2.cvtColor(image, cv2.COLOR_BGR2RGB))<br>plt.show()<br>#cv2.imshow(&quot;line&quot;,image)<br>#cv2.waitKey(0)<br>#cv2.destroyAllWindows()</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/231/1*lw_HB64VKeVQNQCQpIYA0Q.png" /><figcaption>Line over an image</figcaption></figure><p>Drawing a rectangle follows the same convention as above here there are filled and unfilled variations of them.</p><pre>image =  np.zeros((720,720,3), np.uint8)<br>cv2.rectangle(image, (100,100), (300,200), (157,229,16), 5)<br>#use -1 to fill images<br>cv2.rectangle(image, (500,500), (600,600), (157,229,16), -1)<br>plt.axis(&quot;off&quot;)<br>plt.imshow(cv2.cvtColor(image, cv2.COLOR_BGR2RGB))<br>plt.show()<br>#cv2.imshow(&quot;rectangle&quot;,image)<br>#cv2.waitKey()<br>#cv2.destroyAllWindows()</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/231/1*6Zc3ZKlAaQ3N7bYwD-eWew.png" /><figcaption>Rectangle over an image</figcaption></figure><p>Ummm circles ?</p><pre>image =  np.zeros((720,720,3), np.uint8)<br>cv2.circle(image, (350,350), 100, (157,229,16), 5)<br># (350,350) coordinate<br># 100 is the radius <br># (157,229,16) is the color<br># 5 is the thickness of the circle<br>plt.axis(&quot;off&quot;)<br>plt.imshow(cv2.cvtColor(image, cv2.COLOR_BGR2RGB))<br>plt.show()<br>#cv2.imshow(&quot;circle&quot;,image)<br>#cv2.waitKey(0)<br>#cv2.destroyAllWindows()</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/231/1*CP44XxSrlJSJQLXL2A2dyw.png" /><figcaption>Circle over an image</figcaption></figure><p>Drawing a polygon over the image *Use this over rectangle in bounding boxes*</p><pre>image =  np.zeros((720,720,3), np.uint8)<br>pts = np.array([[10,50],[300,75],[100,200],[400,500],[10,500]], np.int32)<br>#straight away feed the cords<br>pts = pts.reshape((-1,1,2))<br>cv2.polylines(image, [pts], True, (157,229,16), 3)<br>plt.axis(&quot;off&quot;)<br>plt.imshow(cv2.cvtColor(image, cv2.COLOR_BGR2RGB))<br>plt.show()<br>#cv2.imshow(&quot;polygon&quot;,image)<br>#cv2.waitKey(0)<br>#cv2.destroyAllWindows()</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/231/1*UyVdMWYtf76zjZ6hzJy4UA.png" /><figcaption>Drawing a polygon over an image</figcaption></figure><p>Text on an image *Whoopse my cat rolled over my keyboard while writing the text, silly she* 🐱</p><pre>image =  np.zeros((720,720,3), np.uint8)<br>cv2.putText(image, &#39;Guddu is love&#39;, (80,300), cv2.FONT_HERSHEY_COMPLEX, 2, (100,170,0), 3)<br>plt.axis(&quot;off&quot;)<br>plt.imshow(cv2.cvtColor(image, cv2.COLOR_BGR2RGB))<br>plt.show()<br>#cv2.imshow(&#39;siddo&#39;, image)<br>#cv2.waitKey(0)<br>#cv2.destroyAllWindows()<br>#(80,300) is bottom left start point</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/231/1*QJczkzN3sgeg6eyYFyEI9Q.png" /><figcaption>Writing text on an image</figcaption></figure><blockquote>I mean we have learned so much that we can make our own photo editing app 😛</blockquote><p>So one step closer if you want to make a photo editing app you’ll need to crop, rotate, scale and resize or if you are a koala 🐨 we’ll stick with using them in image pre-processing …</p><p>Lets be quick 🤫 Image Translation.</p><blockquote>The moving of a picture along the x- and y-axes is known as translation. We may use translation to move an image up, down, left, or right, as well as any combination of the aforementioned. — paraphrased by quill bot for fun</blockquote><p>I’ve used comments for you all to understand it better its kinda mathematical</p><pre># Types of image transformations affine transformation and non affine transformation<br>#transformation matrix<br># T = | 1 0 Tx|<br>#     | 0 1 Ty|<br>height, width =  input.shape[:2]<br>s_height, s_width = height/3, width/3<br>#making transformation matrix using numpy<br>T = np.float32([[1, 0, s_width],[0, 1, s_height]])<br>#use Wrap affine function which is built into  cv<br>Translation = cv2.warpAffine(input, T,(width, height))<br>plt.axis(&quot;off&quot;)<br>plt.imshow(cv2.cvtColor(Translation, cv2.COLOR_BGR2RGB))<br>plt.show()</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/349/1*CGoSl6tZSuDqhxdc8xeI-A.png" /><figcaption>Translated image</figcaption></figure><blockquote>PS learningit in a go would be overwhelming you can take a break ! 🥺</blockquote><p>Rotating the image using rotation matrix 🙂 → 🙃</p><pre># T = |  cos0 -sin0|<br>#    | sin0 cos0|<br># 0 = is angle of rotation<br>#cv2.getRotationMatrix2D(rotation_center_x, rotation_center_y, angle_of_rotation, Scale)<br>#this will result in cropped image try scaling it<br>height, width =  input.shape[:2]<br>rotation_matrix = cv2.getRotationMatrix2D((width/2, height/2), 45, .55)</pre><pre>r_image = cv2.warpAffine(input, rotation_matrix, (width,height))</pre><pre>plt.axis(&quot;off&quot;)<br>plt.imshow(cv2.cvtColor(r_image, cv2.COLOR_BGR2RGB))<br>plt.show()</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/349/1*R59aUFhwzOfjYKn21naJNw.png" /><figcaption>Rotated image</figcaption></figure><p>We can rotate with transpose thats pretty easy</p><pre>#transpose only rotates img 90 at a time<br>r_img =  cv2.transpose(input)<br>plt.axis(&quot;off&quot;)<br>plt.imshow(cv2.cvtColor(r_img, cv2.COLOR_BGR2RGB))<br>plt.show()</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/136/1*77wVwfxUfrDnhAr0ki_uDg.png" /><figcaption>I bet I didn&#39;t rotate this manually you can check the code 💁‍♂️</figcaption></figure><p>Resizing the images : If you try to display the resized image in a notebook congratulations ! just use the windows instead okay ? open cv offers us few resizing techniques you can use the one that suits your purpose the best. I’ll explain their uses inside the code cell.</p><pre>#interpolation(concept of image resizing): construction/genration new pixels while expanding the image<br>#types<br>#cv2.INTER_AREA : good for shrinking down or sampling<br>#cv2.INTER_NEAREST : Fastest<br>#cv2.INTER_LINEAR : good for zooming or up sampling<br>#cv2.INTER_CUBIC : Better<br>#cv2.INTER_LANCZOS4 : Best<br>#uses cv2.resize function</pre><pre>shrink_img = cv2.resize(input, None, fx=0.75, fy=0.75)<br>plt.axis(&quot;off&quot;)<br>plt.imshow(cv2.cvtColor(shrink_img, cv2.COLOR_BGR2RGB))<br>plt.show()<br>cv2.imshow(&quot;shrink&quot;,shrink_img)<br>cv2.waitKey(0)</pre><pre>up_img = cv2.resize(input, None, fx=2, fy=2, interpolation = cv2.INTER_CUBIC)<br>plt.axis(&quot;off&quot;)<br>plt.imshow(cv2.cvtColor(up_img, cv2.COLOR_BGR2RGB))<br>plt.show()<br>cv2.imshow(&quot;up&quot;,up_img)<br>cv2.waitKey(0)</pre><pre>dsize_img = cv2.resize(input, (800,450), interpolation = cv2.INTER_AREA)<br>plt.axis(&quot;off&quot;)<br>plt.imshow(cv2.cvtColor(dsize_img, cv2.COLOR_BGR2RGB))<br>plt.show()<br>cv2.imshow(&quot;defined size&quot;,dsize_img)<br>cv2.waitKey(0)</pre><pre>cv2.destroyAllWindows()<br>#you cant distinguish their sizes in matplot so see them in window or use shape function</pre><blockquote>What do you want to see ? resized pictures ? seriously ?</blockquote><p>Additionally while image resizing they tend to loose quality so you might wanna check this out as well.</p><pre>#resizing images tends to loose quality<br>#mac users please change the window functions</pre><pre>small_img=cv2.pyrDown(input)<br>cv2.imshow(&quot;smalled&quot;,small_img)<br>cv2.waitKey(0)</pre><pre>large_img=cv2.pyrUp(small_img)<br>cv2.imshow(&quot;Larged&quot;,large_img)<br>cv2.waitKey(0)</pre><pre>cv2.destroyAllWindows()</pre><h4>Crop the unwanted peoples whoops didn&#39;t mean that 🌚</h4><p>At the time when i was making this cheatsheet Open Cv didn&#39;t have direct cropping functionality so its kinda tricky as we just get the centre points and save the frame but hey there might be better options and I find this one interesting</p><pre>#using numpy as cv dosent have direct cropping function<br>height, width =  input.shape[:2]<br>#25 and 75 gives the center point<br>#start points<br>s_r, s_c = int(height * .25), int(width * .25)<br>#end points<br>e_r, e_c = int(height * .75), int(width * .75)</pre><pre>crop = input[s_r:e_r , s_c:e_c]</pre><pre>plt.axis(&quot;off&quot;)<br>plt.imshow(cv2.cvtColor(crop, cv2.COLOR_BGR2RGB))<br>plt.show()</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/349/1*ms2YZZNe9-MtOukAleuwig.png" /><figcaption>Cropped image</figcaption></figure><blockquote>Are you still on photoshop train ? *choo* *choo* 🚄</blockquote><h4>Exposure or so interpreted as brightness but nah … exposure work on highlight tones 😬</h4><p>You may need to brighten or darken the image to fit it into your data preparation checklist and you can achieve the following by …</p><pre>M =np.ones(input.shape, dtype = &quot;uint8&quot;) *50<br>addexp = cv2.add(input, M)<br>plt.axis(&quot;off&quot;)<br>plt.imshow(cv2.cvtColor(addexp, cv2.COLOR_BGR2RGB))<br>plt.show()</pre><pre>subexp = cv2.subtract(input, M)<br>plt.axis(&quot;off&quot;)<br>plt.imshow(cv2.cvtColor(subexp, cv2.COLOR_BGR2RGB))<br>plt.show()</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/349/1*N_0YXPS-H2bKSP8osfFp7Q.png" /><figcaption>Increasing the exposure</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/349/1*SL2RtrfNol4DXxhD2K6B-A.png" /><figcaption>Decreasing the exposure</figcaption></figure><blockquote>Ever imagined how photoshop layer merging worked ? like selection and deleting and combining the selected area ? Are you excited as I am ! then hop in 🤯</blockquote><p>lets create two shapes for now, might be different than that we created earlier.</p><pre>#lets create two shapes like before but in grey scale<br>sheet_square =  np.zeros((300,300), np.uint8)<br>cv2.rectangle(sheet_square, (50, 50), (250, 250), 255, -2 )<br>plt.axis(&quot;off&quot;)<br>plt.imshow(cv2.cvtColor(sheet_square, cv2.COLOR_BGR2RGB))<br>plt.show()<br>sheet_semic =  np.zeros((300,300), np.uint8)<br>cv2.ellipse(sheet_semic, (145, 145), (145, 145), 30, 0, 180, 255, -1 )<br>plt.axis(&quot;off&quot;)<br>plt.imshow(cv2.cvtColor(sheet_semic, cv2.COLOR_BGR2RGB))<br>plt.show()</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/231/1*42-lKJxmLSXCE7Ej0g0hTw.png" /><figcaption>Lets call this Friend A</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/231/1*TFIweIKXbhtjdBTSm5C0bA.png" /><figcaption>Lets call this Arima San</figcaption></figure><p>Do you remember logic gate *Bitwise operations* ? we are gonna use the same for someone who’s new AND just combines the images ; OR just overlaps both of them together; EXOR just uses the common area more like union ; NOT not just subtracts the shape from another leaving you with the common area.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/231/1*Khmm4npSolKUOh_soik_qA.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/231/1*6Oh_0LDtw57X6WX84iKufA.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/231/1*7QW_Z8NpjgNaWdBl3baUbA.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/231/1*gKPFG6h6Fpe_AuS74s16Ug.png" /></figure><h4>Bluring : might be useful for improving edge detection performance</h4><p>Many types of imperfection can make their way into an image: blur, poor contrast, noise, JPEG compression, and more. Of these, blurring can soften the edges which often contain irregularities due to the rough surface of the marker. lets start by using normalisation matrix.</p><p>You can imagine kernel as 3x3 mask which goes over every pixel and apply the required transformation</p><pre>plt.title(&quot;Orignal&quot;)<br>plt.axis(&quot;off&quot;)<br>plt.imshow(cv2.cvtColor(input, cv2.COLOR_BGR2RGB))<br>plt.show()</pre><pre># using kernal 3 x 3  normalizing it by dividing by 9<br>kernel_3 =  np.ones((3,3), np.float32) / 9</pre><pre># using kernal 7 x 7  normalizing it by dividing by 49<br>kernel_7 =  np.ones((7,7), np.float32) / 49</pre><pre>blured_3 =  cv2.filter2D(input, -1, kernel_3)<br>plt.title(&quot;Blur using 3 x 3&quot;)<br>plt.axis(&quot;off&quot;)<br>plt.imshow(cv2.cvtColor(blured_3, cv2.COLOR_BGR2RGB))<br>plt.show()</pre><pre>blured_7 =  cv2.filter2D(input, -1, kernel_7)<br>plt.title(&quot;Blur using 7 x 7&quot;)<br>plt.axis(&quot;off&quot;)<br>plt.imshow(cv2.cvtColor(blured_7, cv2.COLOR_BGR2RGB))<br>plt.show()</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/349/1*iRCrhK4ic7aEBa1LIb17mQ.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/349/1*cZJrPm16M03waRZfQYJSUw.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/349/1*1Vum7vZ9RPB_GO-nzSBYZQ.png" /></figure><p>Inbuilt blurring and convolution using in built functions in open-cv are awesome so you should be good with them Have dropped them below. I’ll skip displaying them below but do run and implement them !</p><pre>#view using cv2.imshow to see the difference</pre><pre>plt.title(&quot;Orignal&quot;)<br>plt.axis(&quot;off&quot;)<br>plt.imshow(cv2.cvtColor(input, cv2.COLOR_BGR2RGB))<br>plt.show()</pre><pre>box = cv2.blur(input, (3,3))<br>plt.title(&quot;Box Blur&quot;)<br>plt.axis(&quot;off&quot;)<br>plt.imshow(cv2.cvtColor(box, cv2.COLOR_BGR2RGB))<br>plt.show()</pre><pre>gaussian = cv2.GaussianBlur(input, (7,7), 0)<br>plt.title(&quot;Gaussian Blur&quot;)<br>plt.axis(&quot;off&quot;)<br>plt.imshow(cv2.cvtColor(gaussian, cv2.COLOR_BGR2RGB))<br>plt.show()</pre><pre>#uses median values of pixels <br>median = cv2.medianBlur(input, 5)<br>plt.title(&quot;Median Blur&quot;)<br>plt.axis(&quot;off&quot;)<br>plt.imshow(cv2.cvtColor(median, cv2.COLOR_BGR2RGB))<br>plt.show()</pre><pre>#bilateral is used to remove noise and keep the edges sharp</pre><pre>bilateral = cv2.bilateralFilter(input, 9, 75, 75)<br>plt.title(&quot;Bilatral Blur&quot;)<br>plt.axis(&quot;off&quot;)<br>plt.imshow(cv2.cvtColor(bilateral, cv2.COLOR_BGR2RGB))<br>plt.show()</pre><h4>De-noising the images ☁️</h4><p>Yes blurring the image works but not everytime. Why you may ask as blurring the image would also blur the edges which would further affect, Yes you guessed it right the useful features in our images. Isnt cv2 beautiful we have everything inbuilt here is an example.</p><pre>noise_img = cv2.imread(&quot;./images/Noise.jpg&quot;)<br>#cv2.imshow(&#39;Noise&#39;, noise_img)<br>#cv2.waitKey()<br>plt.title(&quot;noise&quot;)<br>plt.axis(&quot;off&quot;)<br>plt.imshow(cv2.cvtColor(noise_img, cv2.COLOR_BGR2RGB))<br>plt.show()<br>den = cv2.fastNlMeansDenoisingColored(noise_img, None, 6, 6, 7, 21)<br>#parameter after None are filter strength use value in range (5-10)<br>#next is hForColorComponents use same value as h<br>#cv2.imshow(&#39;Denoised&#39;, den)<br>#cv2.waitKey()<br>#cv2.destroyAllWindows()<br>plt.title(&quot;Denoise&quot;)<br>plt.axis(&quot;off&quot;)<br>plt.imshow(cv2.cvtColor(den, cv2.COLOR_BGR2RGB))<br>plt.show()</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/231/1*9fTbW-UZNPG_CVjDzFEB1g.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/231/1*srsmYEeeHqEQWcIW6B6nsA.png" /></figure><h4>UNO REVERSE : similarly we can sharpen blurred images 🃏</h4><p>We are gonna user kernel to sharpen the images but yes there might be other awesome options which you can use to achieve your desire output at this point we should research a little more about kernel as a filter on images putting in on purpose so we could grasp as much knowledge as we can ….</p><pre>kernal_s = np.array([[-1, -1, -1], [-1, 9, -1], [-1, -1, -1]])<br>sharpened = cv2.filter2D(input, -1, kernal_s)<br>plt.title(&quot;sharpned&quot;)<br>plt.axis(&quot;off&quot;)<br>plt.imshow(cv2.cvtColor(sharpened, cv2.COLOR_BGR2RGB))<br>plt.show()</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/349/1*ipza5KcAOOiupa_P0PYIoQ.png" /></figure><h4>Thresholding : Getting back on the track of AI and ML 🛤</h4><p>In terms of applications hands down the best for image segmentation you can say it helps in seperating background and the subject in the images but before you jump on the wagon thresholding only works on greyscale Images. Let’s take a look at few different types. Using the correct threshold type will do the magic for you ✨</p><pre>#converting it into binary form<br>#cv2.threshold(input, Threshold value, max value, threshold type)<br>#Threshold types<br>#cv2.THRESH_BINARY - common<br>#cv2.THRESH_BINARY_INV - common<br>#cv2.THRESH_TRUNC<br>#cv2.THRESH_TOZERO<br>#cv2.THRESH_TOZERO_INV<br>#Threshold only works on greyscale image</pre><pre>ret, threshb = cv2.threshold(g_input, 127, 255, cv2.THRESH_BINARY)<br>plt.title(&quot;Thresh binary&quot;)<br>plt.axis(&quot;off&quot;)<br>plt.imshow(cv2.cvtColor(threshb, cv2.COLOR_BGR2RGB))<br>plt.show()</pre><pre>ret, threshbi = cv2.threshold(g_input, 127, 255, cv2.THRESH_BINARY_INV)<br>plt.title(&quot;Thresh binary inverse&quot;)<br>plt.axis(&quot;off&quot;)<br>plt.imshow(cv2.cvtColor(threshbi, cv2.COLOR_BGR2RGB))<br>plt.show()</pre><pre>ret, thresht = cv2.threshold(g_input, 127, 255, cv2.THRESH_TRUNC)<br>plt.title(&quot;Thresh trunc&quot;)<br>plt.axis(&quot;off&quot;)<br>plt.imshow(cv2.cvtColor(thresht, cv2.COLOR_BGR2RGB))<br>plt.show()</pre><pre>ret, threshz = cv2.threshold(g_input, 127, 255, cv2.THRESH_TOZERO)<br>plt.title(&quot;Thresh zero&quot;)<br>plt.axis(&quot;off&quot;)<br>plt.imshow(cv2.cvtColor(threshz, cv2.COLOR_BGR2RGB))<br>plt.show()</pre><pre>ret, threshzi = cv2.threshold(g_input, 127, 255, cv2.THRESH_TOZERO_INV)<br>plt.title(&quot;Thresh zero Inverse&quot;)<br>plt.axis(&quot;off&quot;)<br>plt.imshow(cv2.cvtColor(threshzi, cv2.COLOR_BGR2RGB))<br>plt.show()</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/349/1*XlARSbLnRRCIeYgF2-812w.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/349/1*W_sdWRS5HQobvuHTMIfuXQ.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/349/1*GBbcI_IGAQ-ltJI1H5vBGg.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/349/1*QUGMxcBrF50ExtJstYyPeQ.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/349/1*KHhPl2nAfa_v8MZ1RfLM6Q.png" /></figure><blockquote>Ever thought about how CamScanner works ? lets see 👀</blockquote><p>I just took a page out and now I’m gonna point and shoot at it even if its like outside the frame as we want to crop and skew it into a straight image. Okay but I’m gonna take a help of website to find the co-ordinates to get the corner endpoint co-ordinates but you can code that as well</p><p>lets go with this…</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/304/1*qyv07sUaoHbFnlk8-RwtGw.png" /></figure><pre>#1 163 65<br>#2 427 58<br>#3 127 402<br>#4 480 393<br>#the boundary of page is contours<br>#<a href="https://www.image-map.net/">https://www.image-map.net/</a><br>#non affine transform 4 points<br># affine transform 3 points<br>w_img = cv2.imread(&quot;./images/Warp.jpg&quot;)</pre><pre>#the coordinate of the object <br>p_a = np.float32(([274,110], [713,96], [216,616], [802,655]))</pre><pre>#coordinates of desired output<br>p_b = np.float32(([0,0], [420,0], [0,594], [420,594]))</pre><pre>#make cv2 perspective matrix<br>M = cv2.getPerspectiveTransform(p_a, p_b)</pre><pre>warped = cv2.warpPerspective(w_img, M, (420,594))</pre><pre>plt.title(&quot;Orignal&quot;)<br>plt.axis(&quot;off&quot;)<br>plt.imshow(cv2.cvtColor(w_img, cv2.COLOR_BGR2RGB))<br>plt.show()</pre><pre>plt.title(&quot;warped&quot;)<br>plt.axis(&quot;off&quot;)<br>plt.imshow(cv2.cvtColor(warped, cv2.COLOR_BGR2RGB))<br>plt.show()</pre><p>Left with this beauty 🤗</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/168/1*JTO7HBVNiH4wsx3BMtpcbQ.png" /></figure><p>Ummm okay but what about the text then ?</p><p>Let’s use threshold but wait ! we have to specify the value for thresholding right ? and the image conditions might not be the same for every scenario what if we have threshold to adapt automatically to our text 🤔</p><h4>Adaptive Thresholding to the rescue ⛑</h4><p>Considering the image that we captured with hand written text on it we might need to recognise it or at least improve it to make it readable we can leverage Adaptive thresholding. I’ll encourage you to try simple thresholding to see the difference on your own.Adaptive Thresholding evaluates pixels’ small neighbours and then chooses the best threshold value T for each neighbour. This strategy allows us to deal with scenarios where pixel intensities vary dramatically and the ideal value of T varies for different regions of the image.</p><pre>#Threshold is important for scanning text from materials here we can use adaptive threshold<br>#remember to change window destroy function mac users<br>#otsus thresholding is important for text recognition<br>text_img = cv2.imread(&quot;./images/Chrissy_text.jpg&quot;, 0)</pre><pre>#for adaptive thresholding<br>ret, thresha = cv2.threshold(text_img, 127, 255, cv2.THRESH_BINARY)<br>#for removing noise<br>text_img = cv2.GaussianBlur(text_img, (3,3), 0)</pre><pre>#adaptive thresholding<br>#cv2.adaptiveThresholding(image, max Value, adaptive type, threshold type, block size, constant that is substracted from mean)<br>#block size need to be odd number constant is optimally to be 5<br>thresh = cv2.adaptiveThreshold(text_img, 225, cv2.ADAPTIVE_THRESH_MEAN_C, cv2.THRESH_BINARY, 3, 5)<br>plt.title(&quot;Adaptive threshold&quot;)<br>plt.axis(&quot;off&quot;)<br>plt.imshow(cv2.cvtColor(thresh, cv2.COLOR_BGR2RGB))<br>plt.show()<br>cv2.imshow(&#39;Adaptive Threshold&#39;, thresh)<br>cv2.waitKey()<br>cv2.destroyAllWindows()</pre><pre>#adaptive <br>_,thresh_one= cv2.threshold(text_img, 0, 255, cv2.THRESH_BINARY + cv2.THRESH_OTSU)<br>plt.title(&quot;OTSU Adaptive threshold&quot;)<br>plt.axis(&quot;off&quot;)<br>plt.imshow(cv2.cvtColor(thresh, cv2.COLOR_BGR2RGB))<br>plt.show()<br>cv2.imshow(&#39;OTSUS Adaptive Threshold&#39;, thresh_one)<br>cv2.waitKey()<br>cv2.destroyAllWindows()</pre><pre>#adaptive thresholding with bluring<br>blur =  cv2.GaussianBlur(text_img, (5,5), 0)<br>_,thresh_two= cv2.threshold(blur, 0, 255, cv2.THRESH_BINARY + cv2.THRESH_OTSU)<br>plt.title(&quot;OTSU Adaptive threshold blur&quot;)<br>plt.axis(&quot;off&quot;)<br>plt.imshow(cv2.cvtColor(thresh, cv2.COLOR_BGR2RGB))<br>plt.show()<br>cv2.imshow(&#39;OTSUS Adaptive Threshold blur&#39;, thresh_two)<br>cv2.waitKey()<br>cv2.destroyAllWindows()</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/144/1*jN_UnHYUoBJfGaJqPwHapg.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/165/1*7n_HOZNVSkrFQFMG8D0-pQ.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/193/1*OyIGie1nV6L3iZl21B81Kg.png" /></figure><blockquote>Trust me these images look perfectly readable in full screen just give them a shot</blockquote><h4>Is it a pen 🖊 or a pencil ✏️ …</h4><p>If someone amongst us is making notes they might use a pen or pencil so the font weight *cant believe I’m calling it that* might be different in both the cases but in the optimal condition we can achieve a rational form by using dilation and erosion. in simple terms Dilation is growing out from the boundary and erosion is shrinking of the boundary. The example image and code block will help you illustrate better</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/349/1*WQr1ttTkmjlbTHpY_sc9_g.png" /></figure><pre>#Dilation add pixels to boundaries of the object in an image **make white bigger<br>#Erosion remove pixels from the boundaries **make black bigger<br>#Opening erosion followed by dilation<br>#closing dilation followed by erosion<br>t_img = cv2.imread(&quot;./images/siddo.png&quot;, 0)<br>plt.title(&quot;Orignal&quot;)<br>plt.axis(&quot;off&quot;)<br>plt.imshow(cv2.cvtColor(t_img, cv2.COLOR_BGR2RGB))<br>plt.show()</pre><pre>#kernal<br>kernel = np.ones((5,5), np.uint8)</pre><pre>#erosion<br>erosion = cv2.erode(t_img, kernel, iterations = 1)<br>plt.title(&quot;Erosion&quot;)<br>plt.axis(&quot;off&quot;)<br>plt.imshow(cv2.cvtColor(erosion, cv2.COLOR_BGR2RGB))<br>plt.show()</pre><pre>#dilation<br>dilation = cv2.dilate(t_img, kernel, iterations = 1)<br>plt.title(&quot;Dilation&quot;)<br>plt.axis(&quot;off&quot;)<br>plt.imshow(cv2.cvtColor(dilation, cv2.COLOR_BGR2RGB))<br>plt.show()</pre><pre>#opening <br>opening = cv2.morphologyEx(t_img, cv2.MORPH_OPEN, kernel)<br>plt.title(&quot;Opening&quot;)<br>plt.axis(&quot;off&quot;)<br>plt.imshow(cv2.cvtColor(opening, cv2.COLOR_BGR2RGB))<br>plt.show()</pre><pre>#closing is da best<br>closing = cv2.morphologyEx(t_img, cv2.MORPH_CLOSE, kernel)<br>plt.title(&quot;Closing&quot;)<br>plt.axis(&quot;off&quot;)<br>plt.imshow(cv2.cvtColor(closing, cv2.COLOR_BGR2RGB))<br>plt.show()</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/349/1*L8ylG_Ht2zuT-EZ_rhm_eA.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/349/1*NfYjYpMABJb5akAzqDBvlQ.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/349/1*hDkbt7fVfjf1cCNasOaTxg.png" /></figure><h4>The baby steps : lets start a little contours and segmentation on our starter image</h4><p>As we know before carrying out any segmentation in image our best bet is to convert it into the binary for then add a little blur to reduce minimal noise present in the image we’ll use findContours to detect the boundaries of the image. I’ve explained the required information in the code block 🐥</p><pre>g_input = cv2.imread(&quot;./images/Chrissy.jpg&quot;, 0)<br>blur =  cv2.GaussianBlur(g_input, (3,3), 0)<br>edged = cv2.Canny(blur, 100, 150)<br>contours, heirarchy = cv2.findContours(edged, cv2.RETR_EXTERNAL, cv2.CHAIN_APPROX_SIMPLE)<br>print(&quot;Number of contours found = &quot; + str(len(contours)))<br>#cv2.CHAIN_APPROX_NONE : gives all the points<br>#cv2.CHAIN_APPROX_SIMPLE : gives end points<br>#mode<br>#cv2.RETR_LIST : retrieves all contours<br>#cv2.RETR_EXTERNAL : retrieves external or outer contours only<br>#cv2.RETR_CCOMP : retrieves all in 2-level hierarchy<br>#cv2.RETR_TREE : retrieves all in full hierarchy<br>display = cv2.drawContours(input, contours, -1, (0,0,255), 2)<br>plt.title(&quot;Contours&quot;)<br>plt.axis(&quot;off&quot;)<br>plt.imshow(cv2.cvtColor(display, cv2.COLOR_BGR2RGB))<br>plt.show()<br>cv2.imshow(&#39;Contours&#39;, input)<br>cv2.waitKey(0)<br>cv2.destroyAllWindows()</pre><pre>#print(contours)<br>#Number of contours found = 236</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/349/1*J7N47AhDur67LkkENalFiQ.png" /></figure><p>And we can even sort the contours out with respect to their areas almost the same logic but we’ll learn to save the output image in our working directory through the notebook</p><pre>shape_img = cv2.imread(&quot;./images/shapes.jpg&quot;)<br>plt.title(&quot;Shape before&quot;)<br>plt.axis(&quot;off&quot;)<br>plt.imshow(cv2.cvtColor(shape_img, cv2.COLOR_BGR2RGB))<br>plt.show()<br>#cv2.imshow(&#39;Contours&#39;, shape_img)<br>#cv2.waitKey(0)<br>#cv2.destroyAllWindows()</pre><pre>blank_image = np.zeros((shape_img.shape[0], shape_img.shape[1], 3))<br>shape_g = cv2.imread(&quot;./images/shapes.jpg&quot;, 0)</pre><pre>edged = cv2.Canny(shape_g, 70, 100)</pre><pre>contours, hierarchy = cv2.findContours(edged.copy(), cv2.RETR_EXTERNAL, cv2.CHAIN_APPROX_NONE)<br>print(&quot;Number of contours found = &quot;, len(contours))</pre><pre>def areas(contours):<br>    areas = []<br>    for i in contours:<br>        #calculates the pixel area<br>        v = cv2.contourArea(i)<br>        areas.append(area)<br>    return areas<br>    <br>sort = sorted(contours, key=cv2.contourArea, reverse=True)</pre><pre>for j in sort:<br>    cv2.drawContours(shape_img, [j], -1, (255,0,0), 3)<br>    cv2.waitKey(0)<br>    cv2.imshow(&quot;contours with greater to lower area &quot;, shape_img)</pre><pre>cv2.waitKey(0)<br>cv2.destroyAllWindows()</pre><pre>for (i,k) in enumerate(sort):<br>    (x, y, w, h) = cv2.boundingRect(k)<br>    cropped = shape_img[y:y+h, x:x+w]<br>    name = &quot;out_&quot; + str(i + 1) + &quot;.jpg&quot;<br>    print(name)<br>    cv2.imwrite(name, cropped)</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/303/1*Be1Oc3Ued_d8JVdIG-e-Ww.png" /></figure><pre>Number of contours found =  6<br>out_1.jpg<br>out_2.jpg<br>out_3.jpg<br>out_4.jpg<br>out_5.jpg<br>out_6.jpg</pre><p>We can even match shapes with a bunch to find out the similar ones n this work for all the cases. Let me tell you a use case say I have to differentiate any other port like HDMI, USB A, USB C and lightning and given the image of their male pins from front as we know each of them have different shape now we can just threshold and match the shapes to find which port is which How the shape matching works is it find some features which define that shape we’ll study this in coming example which will clearly show you the features it extract but We can just resize the ports to the original image and compare the area under the shape of the port which will work as well you should surely try this one as an excercise, Challenge yourself 😎</p><pre>src = cv2.imread(&quot;./images/src.png&quot;, 0)<br>envv = cv2.imread(&quot;./images/env.png&quot;)<br>env = cv2.imread(&quot;./images/env.png&quot;, 0)</pre><pre>ret, thresha = cv2.threshold(src, 127, 255, 0)<br>ret, threshb = cv2.threshold(env, 127, 255, 0)</pre><pre>contours, hierarchy = cv2.findContours(thresha, cv2.RETR_CCOMP, cv2.CHAIN_APPROX_SIMPLE)</pre><pre>sorted_contours = sorted(contours, key=cv2.contourArea, reverse = True)</pre><pre>template_contour = contours[0]</pre><pre>contours, hierarchy = cv2.findContours(threshb, cv2.RETR_CCOMP, cv2.CHAIN_APPROX_SIMPLE)</pre><pre>for c in contours:<br>    match = cv2.matchShapes(template_contour, c, 1, 0.0)<br>    print(match)<br>    if match &lt; 0.15:<br>        closest_contour = c<br>        break<br>    else:<br>        closest_contour = []<br>cv2.drawContours(envv, closest_contour, -1, (0,255,0), 4)</pre><pre>plt.title(&quot;Source&quot;)<br>plt.axis(&quot;off&quot;)<br>plt.imshow(cv2.cvtColor(src, cv2.COLOR_BGR2RGB))<br>plt.show()</pre><pre>plt.title(&quot;Enviornment&quot;)<br>plt.axis(&quot;off&quot;)<br>plt.imshow(cv2.cvtColor(env, cv2.COLOR_BGR2RGB))<br>plt.show()</pre><pre>plt.title(&quot;Match found&quot;)<br>plt.axis(&quot;off&quot;)<br>plt.imshow(cv2.cvtColor(envv, cv2.COLOR_BGR2RGB))<br>plt.show()</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/209/1*nG_jP66DGCebmGG69rFdKA.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/349/1*RKGAoEfEAgr9T06Y6gYGVg.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/349/1*2V0o4VGgbvn1kWodb56ZoA.png" /></figure><p>Now we know to match shapes but lets roll back to old memories I wanna find pokemons from crap ton of pokemons just to test pixel matching How it works is it just matches pixel to pixel goes through the entire image by window scanning left to right then down</p><pre>#not even ideal :D<br>pokemon = cv2.imread(&quot;./images/Pokemon.jpg&quot;)<br>gray = cv2.cvtColor(pokemon, cv2.COLOR_BGR2GRAY)<br>pikachu = cv2.imread(&quot;./images/Pikachu.jpg&quot;,0)</pre><pre>result = cv2.matchTemplate(gray, pikachu, cv2.TM_CCOEFF)<br>min_val, max_val, min_loc, max_loc = cv2.minMaxLoc(result)</pre><pre>#marking<br>top_l = max_loc<br>bottom_r = (top_l[0]+50, top_l[1]+50)<br>cv2.rectangle(pokemon, top_l, bottom_r, (255,0,0), 5)</pre><pre>plt.title(&quot;Pika&quot;)<br>plt.axis(&quot;off&quot;)<br>plt.imshow(cv2.cvtColor(pikachu, cv2.COLOR_BGR2RGB))<br>plt.show()</pre><pre>plt.title(&quot;Pokemons&quot;)<br>plt.axis(&quot;off&quot;)<br>plt.imshow(cv2.cvtColor(gray, cv2.COLOR_BGR2RGB))<br>plt.show()</pre><pre>plt.title(&quot;Match found&quot;)<br>plt.axis(&quot;off&quot;)<br>plt.imshow(cv2.cvtColor(pokemon, cv2.COLOR_BGR2RGB))<br>plt.show()</pre><pre>cv2.imshow(&#39;Matchfound&#39;, pokemon)<br>cv2.waitKey()<br>cv2.destroyAllWindows()</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/247/1*D1P4CMT6gqsO07OdxEXDSg.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/340/1*LZ0lFn2qIt9L4C9nel-dRA.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/340/1*TqGc10XxgIv7R-LCprs0ug.png" /></figure><h4>Contours and features to track : Just one more … 😵‍💫</h4><blockquote>Im in love with the shape of you ~ open CV to every intersecting corner while selecting good features 😂</blockquote><p>while segmentation of images if you dont need a perfect boundary this my friend will save a lotta performance and improve speed drastically even will separate the different clusters on an image like consider the continents on world map 🗺 or even detection of hand ✋ lets use convex hull contoures</p><pre>pup = cv2.imread(&quot;./images/pup.png&quot;)<br>og = pup.copy()<br>gg = pup.copy()<br>gray = cv2.imread(&quot;./images/pup.png&quot;, 0)<br>plt.title(&quot;Orignal &quot;)<br>plt.axis(&quot;off&quot;)<br>plt.imshow(cv2.cvtColor(pup, cv2.COLOR_BGR2RGB))<br>plt.show()<br>ret, thresh = cv2.threshold(gray, 127, 255, cv2.THRESH_BINARY_INV)<br>contours, hierarchy = cv2.findContours(thresh.copy(), cv2.RETR_LIST, cv2.CHAIN_APPROX_NONE)<br>#bounding rectangle<br>for c in contours:<br>    x,y,w,h = cv2.boundingRect(c)<br>    cv2.rectangle(og, (x,x), (x+w,y+h),(0,0,255),2)<br>    cv2.imshow(&#39;Bounding rect&#39;, og)<br>cv2.waitKey(0)<br>#itreating through each contour<br>for c in contours:<br>    accuracy = 0.01 * cv2.arcLength(c,True)<br>    approx = cv2.approxPolyDP(c, accuracy, True)<br>    a = cv2.drawContours(pup, [approx], 0, (0,255,0), 2)<br>    cv2.imshow(&#39;Approx poly DP&#39;, a)<br>    <br>cv2.waitKey(0)<br>cv2.destroyAllWindows()</pre><pre>plt.title(&quot;contours&quot;)<br>plt.axis(&quot;off&quot;)<br>plt.imshow(cv2.cvtColor(a, cv2.COLOR_BGR2RGB))<br>plt.show()</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/304/1*8W5W82oEE_uKFdb7sG0clQ.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/304/1*c9_LL_Uvai5Q73MT18V98Q.png" /></figure><pre>ret, thresh = cv2.threshold(gray, 176,255,0)<br>contours, hierarchy = cv2.findContours(thresh.copy(), cv2.RETR_LIST, cv2.CHAIN_APPROX_NONE)<br>n = len(contours) - 1<br>contours = sorted(contours, key=cv2.contourArea, reverse = False)[:n]<br>for c in contours:<br>    hull =  cv2.convexHull(c)<br>    b = cv2.drawContours(gg, [hull], 0, (255,0,0), 2)<br>    cv2.imshow(&#39;conves Hull&#39;, b)</pre><pre>cv2.waitKey(0)<br>cv2.destroyAllWindows()</pre><pre>plt.title(&quot;convex hull&quot;)<br>plt.axis(&quot;off&quot;)<br>plt.imshow(cv2.cvtColor(b, cv2.COLOR_BGR2RGB))<br>plt.show()</pre><p>Tracking Features with harris corners and good features to track.</p><blockquote>A corner is an awesome feature! <strong>There’s variation all around a corner</strong>. So, the derivative changes in all directions. So the second derivative also changes in all directions! — someone</blockquote><p>In short it determines which sliding window also mentioned as kernal while using blur has the largest variation while moving in any direction 🥱</p><pre>#image features<br>img = cv2.imread(&quot;./images/pup.png&quot;)<br>gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)</pre><pre>#Harris corners require array datatype to be float<br>gray = np.float32(gray)</pre><pre>harris_corners = cv2.cornerHarris(gray, 3, 3, 0.05)</pre><pre>kernel = np.ones((7,7),np.uint8)</pre><pre>corners=cv2.dilate(harris_corners, kernel, iterations = 2)</pre><pre>img[corners &gt; 0.025 *  corners.max()] = [255, 127, 127]</pre><pre>plt.title(&quot;Corners&quot;)<br>plt.axis(&quot;off&quot;)<br>plt.imshow(cv2.cvtColor(img, cv2.COLOR_BGR2RGB))<br>plt.show()</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/304/1*SJ_dIrWxs45X7nWtCZTgLw.png" /></figure><h4>Good features to track : I love the naming connections of Open CV</h4><p>See how good features to track got the eyes 👀 eyes never lie so just use good features to track instead 😂</p><pre>img = cv2.imread(&quot;./images/pup.png&quot;)<br>gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)</pre><pre>corners = cv2.goodFeaturesToTrack(gray, 50, 0.01, 55)</pre><pre>for corners in corners:<br>    x , y = corners[0]<br>    x = int(x)<br>    y = int(y)<br>    cv2.rectangle(img, (x-10,y-10), (x+10,y+10), (0,255,0), 2)<br>    <br>plt.title(&quot;Corners&quot;)<br>plt.axis(&quot;off&quot;)<br>plt.imshow(cv2.cvtColor(img, cv2.COLOR_BGR2RGB))<br>plt.show()</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/304/1*8lvb2E50QEmcG_SZkNm8JQ.png" /></figure><h4>World is beautiful just don’t forget to embrace the beauty of it ! ✨</h4><p>The efforts you have made for learning will always take you to the places you want to be and peoples as well. I feel motivated to share the knowledge I acquire with everyone who wants to learn or give it a start and thats a big step you could comment if you have completely gone through and the usefulness of the cheatsheet. I’ll keep adding stuff into cheatsheet I’ve much more lined up just need to be delivered to you all. Happy coding and live it out with your heart . You can follow me on my socials I’d love to connect wish this helps and motivates someone signing out ❤️</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=c1825bd02bf6" width="1" height="1" alt=""><hr><p><a href="https://medium.com/geekculture/the-overpowered-open-cv-cheat-sheet-c1825bd02bf6">The overpowered open-cv cheat sheet for AI and M 📷</a> was originally published in <a href="https://medium.com/geekculture">Geek Culture</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[My flutter 2.0 migration story : Still better story than twilight ]]></title>
            <link>https://medium.com/geekculture/my-flutter-2-0-migration-story-still-better-story-than-twilight-5d3754bbf1a6?source=rss-c32d69521c27------2</link>
            <guid isPermaLink="false">https://medium.com/p/5d3754bbf1a6</guid>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[computer-science]]></category>
            <category><![CDATA[flutter]]></category>
            <category><![CDATA[dart]]></category>
            <category><![CDATA[development]]></category>
            <dc:creator><![CDATA[Siddhesh Shivdikar]]></dc:creator>
            <pubDate>Wed, 28 Jul 2021 09:55:08 GMT</pubDate>
            <atom:updated>2021-08-10T08:14:25.879Z</atom:updated>
            <content:encoded><![CDATA[<h3>My flutter 2.0 migration story : Still better story than twilight 🔮</h3><h4>Upgrade flutter and dart version to 2.0 and migrate the existing project to the new updated development environment</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*9k0AxjPWybKJPHe3tnkOeg.png" /></figure><p>Disclaimer: Always make a complete backup before starting the migration process. It’s recommended that you have at least above-average skills in flutter or programming in general 👍, and if you have any unresolved dependencies. I wouldn’t recommend migrating your development environment unless you need to incorporate the features of flutter 2.0. Let’s start with the story.</p><h4>The date was 27th July, The Flutter app… Needed an upgrade… 🤭</h4><p>What does flutter 2.0 bring new to the table for a developer who enjoys and loves building native applications? The most important feature is Null safety, which strengthens Dart further by distinguishing nullable types from non-nullable types, which help to prevent Null crashes, which are very common causes of app crashes 😵‍💫. Google mobile ads and new Cupertino material components for iOS that look beautiful are my favourites.</p><p>First, you must upgrade your flutter and dart versions. You may do this by running flutter — — upgrade in your terminal. If this command does not work, it implies that modifications have been made to your flutter SDK, therefore you can force the upgrade by using the following instructions. After that, you can run flutter a doctor to verify the to-do list for checking your flutter installation.</p><h4><strong>Everything was rainbows and unicorns at beginning 🦄</strong></h4><p>Let’s go on to moving our application to the latest SDK version, but first make a backup of your flutter a project, as not all flutter projects can be migrated. We can use the command below for resolvable packages.</p><pre>flutter pub outdated --mode=null-safety</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*dQv8z3ir4XDGVOyu1VLIkA.png" /><figcaption>Package checking</figcaption></figure><p>If you notice the dependencies with “x” at the extreme right, these are the ones that cannot be addressed, and if they give a functional possibility, you should wait until they are resolved. The ones with ticks are the jackpots; you may copy the versions and then paste them in your “pubspec.yml” file.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*8_kA9K7uAgbicF4OWEqFFg.png" /><figcaption>Find alternatives if packages are for Aesthetics</figcaption></figure><p>Now for the unsolved ones, because they did not provide functional prospects like state management, API processing, or session storage. I chose to drop a couple of them and look for alternatives on pub dev. Check pub dev for packages that do not resolve; you may still find many alternatives supporting null-safety. For example, instead of SplashScreen, I used flutter native splash: 1.2.0, which provides null safety. I’ll repeat the process for the remaining three packages, and we no longer have any package issues. Do not be alarmed if you notice a wave of errors; Everything will fall in place, hopefully 🥲.</p><p>Check that your dart version is at least 2.12 If not, use the command “dart- -version” to check your dart version. It is generally updated with your flutter package.</p><h4>Let’s do this for science 🚀</h4><p>You can skip to the next section no need fixing it manually. After upgrading, I changed the flutter SDK version to 2.12.0 3 in the pubspec file. The criteria for null safety are fairly straightforward. Let’s repair the null variables by adding late keywords and doing some manual labour for the purpose of science to observe what has changed. Example“@ from @required”</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*bf2p7RPSGDT2mQ9ZVJlmxA.png" /></figure><p>! to convert a nullable type to a non-nullable type, such as putting a null check in a snackbar, and many more rules Fortunately, I discovered a walkthrough, which I’ll provide in the resources section.</p><pre>_scaffoldKey.currentState!.showSnackBar(snackbar);</pre><pre>_formKey.currentState!.reset();</pre><pre>}</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*_h9WK0r00LLgb8v3tIfpvg.png" /><figcaption>Using the Late keyword for undefined placeholders</figcaption></figure><p>Now, after updating the variables and fixing 150+ nullable constraints, I still had a few problems, some of which are mentioned below, which I will manually correct because, you guessed it! FOR THE SAKE OF SCIENCE! 🧑‍🔬 How much time do you think it’ll take me to fix 23 errors? Update: It took an hour to fix them.</p><pre>error • A value of type &#39;Color?&#39; can&#39;t be assigned to a variable of type &#39;Color&#39; at lib/configuration.dart:3:21 • (invalid_assignment)<br>  error • The argument type &#39;Color?&#39; can&#39;t be assigned to the parameter type &#39;Color&#39; at lib/configuration.dart:6:13 • (argument_type_not_assignable)<br>  error • The argument type &#39;Null&#39; can&#39;t be assigned to the parameter type &#39;Key&#39; at lib/.dart:595:27 • (argument_type_not_assignable)<br>  error • The named parameter &#39;onInit&#39; is required, but there&#39;s no corresponding argument at lib/.dart:46:16 • (missing_required_argument)<br>  error • The named parameter &#39;key&#39; is required, but there&#39;s no corresponding argument at lib/pages/.dart:27:14 • (missing_required_argument)<br>  error • The argument type &#39;void Function(String)&#39; can&#39;t be assigned to the parameter type &#39;void Function(String?)?&#39; at lib/pages/cart.dart:324:15 • (argument_type_not_assignable)<br>  error • The named parameter &#39;user&#39; is required, but there&#39;s no corresponding argument at lib/pages/.dart:194:15 • (missing_required_argument)<br>  error • The named parameter &#39;key&#39; is required, but there&#39;s no corresponding argument at lib/pages/.dart:195:15 • <br>  error • The named parameter &#39;user&#39; is required, but there&#39;s no corresponding argument at lib/pages/.dart:216:15 • (missing_required_argument)<br>  error • Undefined name &#39;user&#39; at lib/redux/.dart:24:33 • (undefined_identifier)<br>  error • The default &#39;List&#39; constructor isn&#39;t available when null safety is enabled at lib/redux/.dart:156:42 • (default_list_constructor)<br>  error • The named parameter &#39;store&#39; is required, but there&#39;s no corresponding argument at test/widget_test.dart:16:29 • (missing_required_argument)</pre><p>*Drum role* 🥁 successfully changed to null safety, but let’s see whether the app works again because I wanted to learn all the coversions on my own. Fingers crossed. The app did launched, but a few features were broken. Let’s give the dart migration tool a go, Now that we have complete are done with our experimentation.</p><h4>You’ve lost your path… Your path start’s here. 🤗</h4><p>I rolled back to the start kept the pub file from the migration one, removed the instances of unmet dependencies and did <strong>dart migrate.</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*t81Oupdd8RmANfs2eGc2Lg.png" /><figcaption>Dart migrate success</figcaption></figure><p>At this time, I’d want to express my gratitude to the Flutter and Dart teams for their work in making the manual migration preview adequately informative 👏, with visual highlights that really show you the migration changes, which is awesome. I personally went over all of the proposed modifications and discovered them. I completed more than 85% of them successfully before clicking migrate. After clicking on migrate flutter does the changes automatically you dont have to worry 🤩.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*_0PhFU4UdrglxozOLQ7WyQ.png" /><figcaption>Null safety changes proposed by the migration tool</figcaption></figure><p>Then I attempted the flutter run command. Yes, that didn’t seem to work as well, so I tried both simulators just to be sure, but no, so I did flutter clean and flutter pub get instead. No luck still stuck on blank screen</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*f4Nllar9A2TaVknYBt2QOA.png" /><figcaption>Flutter Migration blank screen result</figcaption></figure><p>Let’s see, when I performed it manually, just a few functions were broken, but the others worked fine. I was able to go through all of the panels, and the state management appeared to be operational. Since I conducted the manual migration and understood where things would most likely go wrong, I made the necessary modifications, and *Drum roll* 🥁<strong> </strong>, it worked 🥳.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*pKQJLnUsZtPZQyTyeWtZdQ.png" /><figcaption>Worked 🥳</figcaption></figure><p>Everything from the functionality to the layouts may now take advantage of the new flutter V2 features. I’ll further be testing my app for any bugs and Once again Science saved us ! This was my flutter migration story. I’ll include a few resources that were really helpful to me and were pure bliss. Check out those great developers and give them your support. Happy coding ✨</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=5d3754bbf1a6" width="1" height="1" alt=""><hr><p><a href="https://medium.com/geekculture/my-flutter-2-0-migration-story-still-better-story-than-twilight-5d3754bbf1a6">My flutter 2.0 migration story : Still better story than twilight 🔮</a> was originally published in <a href="https://medium.com/geekculture">Geek Culture</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Deploying Strapi MongoBD for Flutter on Heroku ]]></title>
            <link>https://medium.com/geekculture/deploying-strapi-mongobd-for-flutter-on-heroku-f399bb3396a7?source=rss-c32d69521c27------2</link>
            <guid isPermaLink="false">https://medium.com/p/f399bb3396a7</guid>
            <category><![CDATA[flutter]]></category>
            <category><![CDATA[strapi]]></category>
            <category><![CDATA[mobile-app-development]]></category>
            <category><![CDATA[computer-science]]></category>
            <category><![CDATA[development]]></category>
            <dc:creator><![CDATA[Siddhesh Shivdikar]]></dc:creator>
            <pubDate>Thu, 08 Jul 2021 08:30:22 GMT</pubDate>
            <atom:updated>2021-07-09T17:28:54.148Z</atom:updated>
            <content:encoded><![CDATA[<h3>Deploying Strapi MongoDB for Flutter on Heroku 🚀</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*WZIVXtVYET-f-5_ZpDWE8A.png" /></figure><p><strong>Yet another Introduction : Strapi, MongoDB, Heroku and Flutter</strong></p><p>Strapi is headless CMS and works like a charm for creating api where you can manage your connected database to your application with ease 🔮</p><p>While hosting the server I have seen many articles which were okayish 😪 but not completely informative for providing you with the steps for setting up your Strapi server. Let’s simplify the whole process in this post for someone who has never hosted Strapi.</p><p>I’ll assume that you have set up Strapi locally in your development environment and everything is working like a charm, In my case I have used Strapi with Mongo DB so we’ll be hosting our Strapi Server on Heroku.</p><p><strong>Step 1 : Uploading repo on git :</strong></p><p>Our Fist step would be to upload our server file on Github You may recall the name of the Strapi folder that you have created in your Flutter app directory in my case the name is Server, Should look similar to this 🤷‍♂️</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*L2jj6lAI-0Ak9K1h6Vr_hw.png" /></figure><p>Let’s initialise GIT by using the following initialisation command inside the server folder. We need to have GIT installed and initialised on our machine, Then we can open Terminal or Power Shell on the machiene.</p><p>Now we can create a directory on Github, Initialise git and set the origin to newly created directory by typing the following on terminal. we’ll get this commands after creating a repo but lets mention them.</p><pre>git init<br>git remote add origin *here_will_be_link_to_your_repo*</pre><p>Now let’s add all the folders in server directory</p><pre>git add.</pre><p>let’s make sure that we commit the changes</p><pre>git commit -m &quot;Strapi server initial commit&quot;</pre><p>We are ready to push our existing files on Github</p><pre>git push --set-upstream origin master</pre><p>from here there are preferably two ways for hosting the server on heroku in both the ways you will have to create an account on heroku proceeding forward you can create a new project on heroku.</p><p><strong>Method 1 : Connect Github from Heroku</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*zKkOjJsHuJqoc6Mq5hc4hw.png" /></figure><p>For this example Let’s use the name my-app-something choose the region you are closest to and then hit create app 😬</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*EGZICGh8aLOOSoQKnyzPPQ.png" /></figure><p>The simplest way is to connect your Heroku Project with your Github repo that you just created just one click solution 🤩, Just find your repo click search and then Hit connect button.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*eWUdq3fyRtTsd7bzswe9Rw.png" /></figure><p>We would encounter an error since the environment is production and we haven&#39;t set our environment variables. Let’s discuss after doing it through CLI you can skip the CLI method and Jump to the section Environment Variables</p><p><strong>Method 2 : Heroku CLI</strong></p><p>The second way is to complete the same with the terminal or command prompt</p><p>follow the following commands to link your github repo with Heroku we need to have Heroku CLI installed</p><pre>heroku git:remote -a my-app-something<br>git push heroku master<br>heroku open<br>heroku logs --tail</pre><p>When using command “heroku open” after completing the process we would face an error which would relate to an empty string passing which can be found by “heroku logs — tail” this is because in the production environment of strapi you will have to specify the environment variables inside heroku which will help to establish a connection to Mongo DB</p><p><strong>Step 3 : Enviornment Variables</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*exKvwJj6vbsLakj6sOZS7A.png" /></figure><p>let’s add environment variable’s on Heroku By going on to setting and then Reveal Config Vars.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*HYWlObF7srIaSbkV_5hnVQ.png" /></figure><p>Here are the following environment variables that you will need to add inside Heroku make sure you remove access to the development environment inside the Strapisince it would reveal your credentials of Mongo DB server to public, Which we don’t want to incase if we gonna use it for production 🤗.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Xep4aZDj7ZMAu_7RUcDlNQ.png" /></figure><p>Quick hack you already have the environment values present in your development server here’s the path just copy pasta the values from development files 😜</p><pre>/server/config/environments/development/database.json</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*eWTeP--amksx1yjzG7mzgw.png" /></figure><p><strong>Step 4 : Replacing The Links</strong></p><p>We can open our Strapi dashboard from Heroku now we are ready to use our API inside our flutter application you just have to replace your API links with the server link that you have uploaded on Heroku here is an example</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*HeewGQklPATA07HllSvKNw.png" /></figure><p>Make sure to replace all the api requests to the server.</p><p><strong>And We Are Done 🎉</strong></p><p>Congratulations 🥳 We have uploaded Strapi flutter server on Heroku you can do the same with Google cloud AWS or Azure.</p><p>Here is a bonus for you all Since Heroku has a limited uptime for the hosted servers changing it state to sleep, so let’s give our app some coffee ☕️</p><p><a href="https://kaffeine.herokuapp.com/">Kaffeine</a></p><p>Appreciate and share if this was useful, Happy Coding 👋</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=f399bb3396a7" width="1" height="1" alt=""><hr><p><a href="https://medium.com/geekculture/deploying-strapi-mongobd-for-flutter-on-heroku-f399bb3396a7">Deploying Strapi MongoBD for Flutter on Heroku 🚀</a> was originally published in <a href="https://medium.com/geekculture">Geek Culture</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
    </channel>
</rss>