Barbie is known as a role model for girls. The recognition of Barbie in the world is phenomenal – in Russia it is known by 99%, Barbie occupies the 1st place in sales in the world in the category "classic dolls". The assortment is huge, and it's not only dolls, but also sets of clothes for dolls, as well as themed play sets. Doll collectors create original sets to demonstrate their dolls. I was asked to create a Photo Studio set for Barbie. The set will be used in the Museum of Dolls on the CMS. For greater reality, the Photo Studio takes real photos and prints them in black and white on a real thermal printer, which creates the illusion of a real doll photo studio.
The following components are used for the photo studio:
• OpenMV H7 + board
• OpenMV LCD Shield Expansion Board
• Adafruit Thermal Printer
• 12V power supply
* Step-down stabilizer module for LM2596 – 2 pcs
• Button
* 3d printed parts
Electrical connection diagram:
And the appearance of the device
OpenMV H7+ is a computer vision system in the form of a compact camera module with low power consumption. It differs from conventional cameras by an additional filling with a microcontroller for processing images on the fly and controlling external devices.
The image is captured by the OmniVision OV7725 1/3" light-sensitive CMOS matrix with a resolution of 640×480. The camera shoots video in 8-bit grayscale mode or 16-bit RGB565 color format with a frequency of up to 75 frames per second. MJPEG, GIF, and uncompressed RAW video compression formats are supported. The camera has an RGB LED backlight and two IR LEDs for shooting in the dark.
The lens with a focal length of 2.8 mm and an F2.0 aperture is attached via a bayonet with a standard M12 thread in 0.5 mm increments, so interchangeable lenses from GoPro and other portable cameras are suitable for the OpenMV H7.
A 32-bit STM32H743VI microcontroller from STMicroelectronics with an ARM Cortex-M7 computing core is responsible for image processing. The processor operates at a clock speed of up to 480 MHz, it has 1 MB of SRAM RAM and 2 MB of Flash memory on board.
The filling copes with computer vision algorithms of varying complexity, including:
* Image analysis via TensorFlow Lite;
• motion detection in the frame;
• face recognition;
* tracking colored objects and markers;
* tracking the movement of the pupils;
* detection and reading of QR codes, barcodes and AprilTags;
• high-speed line tracking;
* recognition of geometric objects;
* comparison of the image with the specified template.
A microSD memory card is used to record video and store working data. The speed of reading and writing up to 100 Mbit / s allows you to quickly load objects for machine vision
LCD Shield for instant image display from the OpenMV camera module without the use of external wires and multimedia devices. The display resolution is 128×160 pixels and a depth of 65536 colors.
The Openmp LCD Shield expansion board is connected to the contacts to the Openmw H7+, and to connect the OpenMV H7+ board to the button and the thermal printer, we will make a homemade shield
We will print the case and place the power supply and stabilizer modules at the bottom of the case.
We will place the Adafruit thermal printer in the case, and we will place the Openmw H7+ board with nameplates on the panel and connect it to the case with hot glue
The smart camera is programmed in MicroPython in the OpenMV IDE development environment with support for the Russian language. It combines a program code editor, viewing the camera's video buffer and building RGB histograms in real time to simplify the debugging process.
To work with the Adafruit thermal printer, you need to download the Adafruit_Thermal library.
The Adafruit thermal printer allows you to print text (including Russian), barcodes and images on receipt tapes made of thermal paper with a standard width of 57 mm and a roll diameter of up to 36 mm. The printing method consists in using a special incandescent head, which literally burns the text on the paper. The temperature of the head reaches up to 200 degrees Celsius. In places of exposure, the paper darkens and the necessary text is obtained. The result is a black-and-white printer with a resolution of 8 dots per mm = 384 dots per line.
But we don't need black and white printing. Let's try to implement printing an image in grayscale. We will receive a color image of RG565 with a resolution of 128x160 from the camera and save it in a bmp file.
sensor.set_pixformat(sensor.RGB565) #
sensor.set_framesize(sensor.LCD) # 128x160
For each point in the image, we will calculate the value in grayscale. We read the data from the bmp file. BMP file format
File contents analysis
Byte 1, 2 should be [0x4D 0x42]: 424D
Bytes 3-6 (Images Size) 0000073E
Bytes 7, 8 (Must be zero) 0000
Bytes 9, 10 (Must be zero) 0000
Bytes 11-14 (Image offset) 00000036
Bytes 15-18 (sizeof BITMAPINFOHEADER structure, must be 40 [0x28]) 00000028
Bytes 19-22 (image width) 00000018
Bytes 23-26 (image height) 00000019
Bytes 27, 28 (number of planes in the image, must be 1) 0001
Bytes 29, 30 (number of bits per pixel (1, 4, 8, or 24 [0x18])) 0018
-- -- Note 24 bit color, is three bites of red, green and blue, each
File signature analysis (Header analysis)
BMP file (Starts with 0x42 0x4D)
RGB565 format – each point is represented by 2 bytes.
r = ((color >> 11) & 0x1F);
g = ((color >> 5) & 0x3F);
b = (color & 0x1F);
grey=(3*r+6*g+1*b)/2
Then, to simulate the gray color, we will output a 3x3 matrix to a black-and-white printer, a pixel of the gray scale with a value from 0 to 255 will be converted into a 3x3 black-and-white matrix, for example:
But since printing takes place line by line, we will first create a bitmap file, and then print it using the Adafruit_Thermal library.
Creating a bitmap file from a bmp
mask=[[1,1,1,1,1,1,1,1,1],[1,1,1,1,0,1,1,1,1],[0,1,1,1,1,1,1,1,0],
[0,1,1,1,0,1,1,1,0],[0,1,0,1,0,1,0,1,0],[1,0,1,0,0,0,1,0,1],
[0,0,1,0,1,0,1,0,0],[0,0,1,0,0,0,1,0,0],[0,0,0,0,1,0,0,0,0],
[0,0,0,0,0,0,0,0,0],[0,0,0,0,0,0,0,0,0]]
def convertBMP_toBitmap(fbmp):
global arr1;
pyb.LED(GREEN_LED_PIN).on()
img=image.Image(fbmp)
img1=img
lcd.display(img1)
try:
with open(fbmp, 'rb') as bmp_file:
filenamebitmap=fbmp.replace(".bmp","")
#fbitmap=open("bitmap","wb")
fbitmap=open(filenamebitmap,"wb")
arr1 = [[0 for x in range(384)] for y in range(3)]
# BitmapHeader
headerbmp = bmp_file.read(14)
filesize=int.from_bytes(headerbmp[2:6], 'little')
fileoffset=int.from_bytes(headerbmp[-4:], 'little')
print("filesize = ",filesize)
print("fileoffset = ",fileoffset)
width=128
height=160
#
bmp_file.seek(fileoffset)
col=0;row=0;
#for d in range (0,(filesize-fileoffset)/2,1):
print("create bitmap ",filenamebitmap)
for row in range (0,160,1):
for col in range (0,128,1):
bytecolor=bmp_file.read(2)
color=int.from_bytes(bytecolor,"little")
#print("color= ",hex(color))
r = ((color >> 11) & 0x1F);
g = ((color >> 5) & 0x3F);
b = (color & 0x1F);
grey=(3*r+6*g+1*b)/2
setBits(col,grey)
arr2 = [[0 for x in range(48)] for y in range(3)]
for b1 in range (0,3):
for b2 in range (0,48):
bb=0x00;
for b3 in range (0,8):
bb=bb+(arr1[b1][b2*8+b3]<<(8-b3-1))
arr2[b1][b2]=bb;
fbitmap.write(bb.to_bytes(1,sys.byteorder));
fbitmap.close()
except OSError as e:
print('error: {}'.format(e))
pyb.LED(GREEN_LED_PIN).off()
def setBits(col,g):
global arr1;
g=int(g // 25)
for i in range(0,3):
for j in range(0,3):
arr1[i][col*3+j]=mask[g][i*3+j]
And printing a bitmap file
def print_snaphot(ff):
pyb.LED(BLUE_LED_PIN).on()
filenamebitmap=ff.replace(".bmp","")
img1=image.Image(ff)
printer.printBitmapFromFile(384, 480, filenamebitmap)
pyb.LED(BLUE_LED_PIN).off()
And the main cycle is printing when the button is pressed
startphoto = Pin('P9', Pin.IN, Pin.PULL_UP)
while(True):
lcd.display(sensor.snapshot())
if startphoto.value()==0:
#
filename=save_snaphot()
print(filename)
#
convertBMP_toBitmap(filename)
#
print_snaphot(filename)
The entire script and libraries can be downloaded from attachments (main.py).
And a video.
Comments