<?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 Vinicius Carvalho on Medium]]></title>
        <description><![CDATA[Stories by Vinicius Carvalho on Medium]]></description>
        <link>https://medium.com/@vccarvalho?source=rss-2a783700652f------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/0*TWbjlf_yicy6LJOG.jpeg</url>
            <title>Stories by Vinicius Carvalho on Medium</title>
            <link>https://medium.com/@vccarvalho?source=rss-2a783700652f------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Wed, 02 Dec 2026 01:09:34 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@vccarvalho/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[How many programmers do you need to change a light bulb (color) — Part I]]></title>
            <link>https://medium.com/@vccarvalho/how-many-programmers-do-you-need-to-change-a-light-bulb-color-part-i-1750bb6e455?source=rss-2a783700652f------2</link>
            <guid isPermaLink="false">https://medium.com/p/1750bb6e455</guid>
            <category><![CDATA[cloud]]></category>
            <category><![CDATA[iot]]></category>
            <category><![CDATA[streaming]]></category>
            <category><![CDATA[computer-vision]]></category>
            <category><![CDATA[spring-boot]]></category>
            <dc:creator><![CDATA[Vinicius Carvalho]]></dc:creator>
            <pubDate>Thu, 28 Sep 2017 13:51:22 GMT</pubDate>
            <atom:updated>2017-09-28T13:51:22.236Z</atom:updated>
            <content:encoded><![CDATA[<p>Of all IoT things, the last one I decided to purchased was Phillips Hue bulbs, I knew back then the moment I got the first one I’d be addicted.</p><p>So, in preparation for Halloween 2017, I decided to spice up the house with some cool lighting effects and got myself a few bulbs and the bridge.</p><p>Of course the first thing I checked was how to interface with this, and easy enough the bridge offers a nice <a href="https://developers.meethue.com/philips-hue-api">REST</a> endpoint that allows control of the bulbs, no need to understand Zigbee.</p><p>Ok, so now I needed a project right? And it had to be bigger than life, otherwise what’s the fun on that?</p><p>So I came upon the news on Phillips soon enabling TVs and videogames to interact with the api and change your lights according to the images on the TV. There’s also a bunch of apps out there that use your phone camera to do the same. I knew now what I wanted to do.</p><p>So my challenge is: <strong>Stream my PS4 game to </strong><a href="http://www.twitch.tv/"><strong>twitch.tv</strong></a><strong>, capture frames from the stream, create a color histogram, update the bulbs with the proper color.</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*j5WGeN2dPP_Mil4aMwpB7w.png" /><figcaption>Twitch To Hue Streaming project</figcaption></figure><p>The real annoying part of this project was really taping into twitch, which requires a lot of hacking, and it’s still rough in the edges. Figuring out a best approach to find the common color was interesting, and finally matching RGB to Phillips own HUE and Gamut was a massive issue. I had no idea how complex color is, it’s way more than just 3 bytes.</p><h3>Counting Colors</h3><p>The first part of this series I’ll talk how I managed the histogram part of the problem. It’s the easiest one to tackle and it was a fun ride.</p><p>I read a lot around on how to count colors in an image, a very naive approach is to iterate over each pixel and store the color in a map. The problem with this approach is that you don’t really factor color families that could really represent the most dominant spectrum in an image.</p><p>Another approach is to create some bins just like in a histogram, and then for each pixel find the nearest bin and increment it’s counter. The problem I found here was to create a color sample that could truly represent my image.</p><p>So finally I decided to use some machine learning. Add every color point to a 3D space (R,G,B) and then cluster it using kmeans and for each centroid of the cluster, that would be my most dominant color. Most likely that specific color point was not the dominant color, but most colors would be around that spectrum. In the end I was very satisfied with the result.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*0zrxydZsi7uIbknPgFAKjg.jpeg" /><figcaption>Zelda Breath of Wild sample screenshot</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/500/1*nylTwOkJ2PI1OGXjwvWoeQ.png" /><figcaption>Scatter plot of colors found in image (sampling at 10% of pixels)</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/800/1*uBw0-aaNNdU1wms4EHYPGw.png" /><figcaption>Each color represents a cluster and it’s width it’s relative number of points</figcaption></figure><p>The application that creates the histogram takes an image as an input, traverse each every other pixel (identified via a step argument) creates the cluster using apache’s common-maths <a href="http://commons.apache.org/proper/commons-math/userguide/ml.html">machine learning</a> support and outputs a ColorStats entity that contains the color distribution information that should be read downstream.</p><p>The code can be found at <a href="https://github.com/viniciusccarvalho/commons-cv">https://github.com/viniciusccarvalho/commons-cv</a>. I’ve added a few support classes to generate the plot as well as to create a color palette such as those found in color pickers. The color histogram is generated via a javascript canvas function on the client side, we will look into the client app on the next part.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/4323b2977023142e99996ced0899e115/href">https://medium.com/media/4323b2977023142e99996ced0899e115/href</a></iframe><p>On the next part we will look into a sample Spring boot app to test this library, how to create our processor using Spring Cloud Stream and how to use ffmpeg and java to capture video sources and take snapshots.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=1750bb6e455" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[From List<T> query → Flux<T> query on Spring]]></title>
            <link>https://medium.com/@vccarvalho/from-list-t-query-flux-t-query-on-spring-e1b06afa7818?source=rss-2a783700652f------2</link>
            <guid isPermaLink="false">https://medium.com/p/e1b06afa7818</guid>
            <category><![CDATA[reactive-programming]]></category>
            <category><![CDATA[event-sourcing]]></category>
            <category><![CDATA[spring]]></category>
            <dc:creator><![CDATA[Vinicius Carvalho]]></dc:creator>
            <pubDate>Thu, 02 Jun 2016 01:10:32 GMT</pubDate>
            <atom:updated>2016-06-02T01:10:32.529Z</atom:updated>
            <content:encoded><![CDATA[<iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/533da5df9b24b7f499b335038167e120/href">https://medium.com/media/533da5df9b24b7f499b335038167e120/href</a></iframe><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=e1b06afa7818" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>