Counting different ways to create QR code - combinations

I am working on an app that needs to create QR-code through a code, essentialy as for now
I thought on generating something similar to a sudoku board (9X9 squares of 3X3 sections) s.t. every odd number is beeing painted black and every double number is being painted in white.
I am stuck not on a code but rather on trying to figure out how many DIFFERENT options do I have to create images in that manner as for now -
For every 3X3 section I have (9 choose 5) options to place black "tiles" and I have 9 of those
which makes it (9 choose 5)^9 = 126^9 = 8.00451285e18 which is a really big number..
For some reason that seems wrong...any help?
I am using choose since the arrangment of the odd number is irrelvant because the two placments on the attached image gives the same result

Related

What is the best way for rendering a huge voxel object?

I am trying to display 3d model of a human in opengl. The human object is represented by a 3D array[n][n][n] (height, width and depth), where n = 300. Each element of array has value either 1 or 0. If element is 0 then it should be ignored else drawn.
Problem: due to the fact that I have to iterate through 3D array using 3 nested for loops and then create vertices for each individual voxel it takes a lot of time.
My idea of how to solve the problem: write another program that would iterate through array, create vertices and write them to the file. And then whenever I need to render I would read vertices from the file.
Question: What is the best way to render such an object? Would be great if you could suggest any algorithm or technic.
Many years ago I made a school project where I did something similar.
I had a 3D volume representation with 0s and 1s which represents a room. 0 means the cube is empty, 1 means the cube is full. It's the same problem you are facing but flipping the normal of the quads.
So I made an algorithm that turns the cube of bits into the minimum number of quads.
I've been digging in my old code repository and found the function that does that. I feel a bit ashamed of the code I wrote back then, but hopefully you can grab some inspiration from it.
I'm going to try to give a brief explanation of what the algorithm does.
We slice the volume with planes in each direction X, Y and Z.
For each plane we check all the cells it touches on each side.
If both sides have the same number (both 0, or both 1), we do nothing.
Otherwise (we have a different number on each side), we generate a quad in that position, and the normal of that quad will depend on the order of the numbers (01 or 10).
Ignore the colorCount variable, I think it's just a color ID I used for debugging.
My program called this algorithm when it first loads, and whenever you make a change in the scene (it was a live-editor). I didn't notice any slowdowns when editing the scene and the computer I was using back then was not very fast.

Algorithm to edit a complex line in a 2D- Array needed

Short intro: I am working on a 3D laserscanning device, that creates a point cloud using pictures of an object which is illuminated by the laser.
Each picture shows essentially a line which represents the objects surface.
What I do then is store the value of brightness of each pixel in a 2D Array, which in the end results in a Matrix that puts a number on the position of the illuminated line. This I can take to further calculate the point cloud. All of this I'm doing in C++.
Now to the problem at hand:
After storing the brightness information inside the matrix, I get a complex line which is several pixels thick (thickness not uniform). I need it to be exactly 1 Pixel wide. Up until now I calculated either the mean value of the line, or used a weight function.
This only works well as long as your line mostly runs vertically or horizontally throughout the picture/matrix, because you can calculate the right value for each seperate line or column.
I have now pictures/matrices where the line has a more complex shape, so these simple solutions won't work anymore. Here are two examples:
How can I calculate the mean value or put a weight function on these lines, so i can bring them down to a thickness of 1px? I need an algorithm that does this automatically because I have sets of hundreds of pictures, where this line can be differently shaped, so it would be too timeconsuming/impossible to edit all of them seperately.
I hope I somehow talked sense rather then complicate things ;)

How to make people with different distances to the camera appear to be the same sizes?

Now I am doing a project which is called crowd estimation. I am focused on estimating the crowd levels in canteens. My approach is based on subtracting the background and only keeping the people in the foreground. The people are represented by white pixels and the background is black. So I can estimate the crowd level by counting the white pixels in the foreground. However, this needs people with different distances to the camera appear to be the same sizes. Otherwise, the white pixels for the people sitting near to the camera may be 5 times another person who sits far away from the camera. This is not I want, I want their pixels to be almost the same. Below is a screenshot of the canteen:
The first way I have tried is by segmenting the scene into different regions, the near regions are assigned with less weights, the far regions are assigned with more weights. However, the segmentation and weights assigning are all done manually, and it's hard to judge the line to segment and the weights assigned to each region. I use a picture below to show how it is done:
Another way I have tried is the perceptive transform, choosing four points on the input image and mapping them to the 4 points on the output image. However it's hard to choose the 4 points and it's hard to decide whether the people's sizes are the same after the transformation. It's shown below:
Can anyone provide a good way to solve this people's sizes problem(due too different distances)? Your reply is greatly appreciated.

Printing an equilateral triangle to Terminal

I've been trying to do something that seems surprisingly challenging --- printing an equilateral triangle to the command line (Terminal for Mac OS X). I have a program that can compute the nth row of Pascal's triangle up to some user-specified constant. As is well known, if one takes the values of Pascal's triangle modulo two, there is a correlation between that and Sierpinski's triangle.
I have been setting odd values to be 1 and even values to be 0, and when I print the results on the Terminal and zoom out, it looks nice, apart from the fact that it's clearly not equilateral. Here is an example output of my program after zooming way out (so zeroes and ones look much different):
But I'm wondering ... is there a way to get this triangle to look equilateral? Or do I have to print the output somewhere else? I've been experimenting with different fonts, different line width levels, but I can't get anything to look close to equilateral, and even if it does, I don't have a reliable way of checking for this. Part of the problem is also that zooming in/out on the Terminal results in different line width and height scales.
My code takes in as input the number of rows to generate. Then, it takes that number into account when printing out each row. So the first row (which is just a single "1") would have n-1 spaces to print before printing the 1. Then the second row has to print n-2 spaces before printing its actual contents (which are "1 1"), which includes a space between each number, and so on. It's in C++, but I don't think that should matter.
I suspect that I'll need to find some other way of getting the image out, so any advice about libraries to use would be great.
A good option is to render the triangle to an raster format of your choice, and use aalib or libcaca to render that image to the terminal.
I would try to (and I think you already have) figure out the actual width and height of what the image would ultimately be, and generate the 2D matrix defining that images dimensions. This matrix can be a 2D set of integers (no less than 24 bits wide giving space for 8 bit color components), or 3 separate 2D matrices, one for each color component. Set all of those values to whatever you want the background color to be.
Move through your algorithm setting the appropriate pixels to whatever OTHER color your want your actual triangle to show up as.
Look here for writing such a matrix out to a .bmp (or bitmap) file.
Writing BMP image in pure c/c++ without other libraries

Counting objects on a grid with OpenCV

I'm relatively new to OpenCV, and I'm working on a project where I need to count the number of objects on a grid. the grid is the background of the image, and there's either an object in each space or there isn't; I need to count the number present, and I don't really know where to start. I've searched here and other places, but can't seem to find what I'm looking for. I will need to be tracking the space numbers of the grid in the future, so I will also eventually need to know whether each grid space is occupied or empty. I'm not going so far as to ask for a coded example, but does anybody know of any source or tutorials to accomplish this task or one similar to it? Thanks for your help!
Further Details: images will come from a stable-mounted camera, objects are of relatively uniform shape, but varying size and color.
I would first answer a few questions:
Will an object be completely enclosed in a grid cell? Or can it be placed on top of a grid line? (In other words, will the object hide a line from the camera?)
Will more than one object be in one cell?
Can an object occupy more than one cell? (closely related to question 1)
Given reasonable answers to those questions, I believe the problem can be broken into two parts: first, identify the centers of each grid space. To count objects, you can then sample that region to see if anything "not background" is there.
You can then assume that a grid space is defined by four strong, regularly-placed, corner features. (For the sake of discussion, I'll assume you've performed the initial image preparation as needed: histogram equalization, gaussian blur for noise reduction, etc.) From there, you might try some of OpenCV's methods for finding corners (Harris corner detector, cvGoodFeaturesToTrack, etc). It's likely that you can borrow some of the techniques found in OpenCV's square finding example (samples/c/square.c). For this task, it's probably sufficient to assume that the grid center is just the centroid of each set of "adjacent" (or sufficiently near) corners.
Alternatively, you might use the Hough transform to identify the principal horizontal and vertical lines in the image. You can then determine the intersection points to identify the extents of each grid cell. This implementation might be more challenging since inferring structure (or adjacency) from "nearby" vertices in order to find a grid center seems more difficult.