如何解决使用 mips 查找图像标记
我是火星模拟器的新手。 我一直致力于使用 mips 在图像上查找标记。在这里,红色区域是标记。该程序未检测到红色部分。你能帮我解决这个问题吗?
输入 BMP 图像 1(24 位 RGB)包含如下所示的标记。图像可能 包含其他元素。任务是检测给定类型的所有标记。 我的十六进制详细信息是:
#00000000 89 50 4E 47 0D 0A 1A 0A 00 00 00 0D
#00000010 00 00 01 40 00 00 00 F0 08 06 00 00
#00000020 6B 00 00 00 01 73 52 47 42 00 AE CE
#00000030 00 04 67 41 4D 41 00 00 B1 8F 0B FC
#00000040 00 09 70 48 59 73 00 00 12 74 00 00
#00000050 66 1F 78 00 00 06 00 49 44 41 54 78
标记为黑色,由两条臂组成。给定的标记类型具有宽度到高度,并且这些是恒定的。它们可以是各种尺寸。如果保持手臂尺寸的比例。标记位置由臂相交的点确定。控制台窗口 - 纯文本 - 后续行包含检测到的标记的坐标,例如。 5,5. 点 (0,0) 位于图像的左上角。 如何检查输入和输出错误。我最多会使用 10 个标记。
表 1. 不同标记类型的宽高比。
Marker type
W/H
1 1
2 1
3 1
输入 BMP文件源格式:24位RGB,宽:320px,高:240px,
.align 4
res: .space 2
image: .space BMP_FILE_SIZE
fname: .asciiz "image.bmp"
.text
main:
jal read_bmp
#put red pixel in bottom left corner
li $a0,0 #x
li $a1,0 #y
li $a2,0x00FF0000 #color - 00RRGGBB
jal put_pixel
#get pixel color - $a0=x,$a1=y,result $v0=0x00RRGGBB
li $a0,0 #y
jal get_pixel #color -
#put green pixel one pixel above
li $a0,1 #y
li $a2,0x0000FF00 #color - 00RRGGBB
jal put_pixel
jal save_bmp
exit: li $v0,10 #Terminate the program
syscall
read_bmp:
#description:
# reads the contents of a bmp file into memory
#arguments:
# none
#return value: none
sub $sp,$sp,4 #push $ra to the stack
sw $ra,($sp)
sub $sp,4 #push $s1
sw $s1,($sp)
#open file
li $v0,13
la $a0,fname #file name
li $a1,0 #flags: 0-read file
li $a2,0 #mode: ignored
syscall
move $s1,$v0 # save the file descriptor
#check for errors - if the file was opened
#...
#read file
li $v0,14
move $a0,$s1
la $a1,image
li $a2,BMP_FILE_SIZE
syscall
#close file
li $v0,16
move $a0,$s1
syscall
lw $s1,($sp) #restore (pop) $s1
add $sp,4
lw $ra,($sp) #restore (pop) $ra
add $sp,4
jr $ra
save_bmp:
#description:
# saves bmp file stored in memory to a file
#arguments:
# none
#return value: none
sub $sp,1 #flags: 1-write file
li $a2,$v0 # save the file descriptor
#check for errors - if the file was opened
#...
#save file
li $v0,15
move $a0,4
jr $ra
# ============================================================================
put_pixel:
#description:
# sets the color of specified pixel
#arguments:
# $a0 - x coordinate
# $a1 - y coordinate - (0,0) - bottom left corner
# $a2 - 0RGB - pixel color
#return value: none
sub $sp,($sp)
la $t1,image + 10 #adress of file offset to pixel array
lw $t2,($t1) #file offset to pixel array in $t2
la $t1,image #adress of bitmap
add $t2,$t1,$t2 #adress of pixel array in $t2
#pixel address calculation
mul $t1,$a1,BYTES_PER_ROW #t1= y*BYTES_PER_ROW
move $t3,$a0
sll $a0,$a0,1
add $t3,$t3,$a0 #$t3= 3*x
add $t1,$t3 #$t1 = 3x + y*BYTES_PER_ROW
add $t2,$t2,$t1 #pixel address
#set new color
sb $a2,($t2) #store B
srl $a2,$a2,8
sb $a2,1($t2) #store G
srl $a2,2($t2) #store R
lw $ra,4
jr $ra
get_pixel:
#description:
# returns color of specified pixel
#arguments:
# $a0 - x coordinate
# $a1 - y coordinate - (0,0) - bottom left corner
#return value:
# $v0 - 0RGB - pixel color
sub $sp,$t1 #pixel address
#get color
lbu $v0,($t2) #load B
lbu $t1,1($t2) #load G
sll $t1,8
or $v0,$v0,$t1
lbu $t1,2($t2) #load R
sll $t1,16
or $v0,$t1
lw $ra,4
jr $ra
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。