visionview-1.cpp
来自「FIRA 3对3 机器人足球PC端控制程序。」· C++ 代码 · 共 2,053 行 · 第 1/5 页
CPP
2,053 行
}
else if(rx > (DispSizeX-1-halfsize) && ry > (rectBoundary.bottom-1-halfsize)){
*offx = DispSizeX-1-size;
*offy = rectBoundary.bottom-1-size;
}
else if(rx < halfsize){
*offx = 0;
*offy = ry-halfsize;
}
else if(rx > (DispSizeX-1-halfsize) ){
*offx = DispSizeX-1-size;
*offy = ry-halfsize;
}
else if(ry < rectBoundary.top+halfsize){
*offx = rx-halfsize;
*offy = rectBoundary.top;
}
else if(ry > (rectBoundary.bottom-1-halfsize)){
*offx = rx-halfsize;
*offy = rectBoundary.bottom-1-size;
}
else {
*offx = rx-halfsize;
*offy = ry-halfsize;
}
if( iteration % 2 == 0 ) {
if( *offy % 2 == 1)
*offy -= 1;
}
else {
if( *offy % 2 == 0)
*offy += 1;
}
}
/*
void CVisionView::LabelingWholeImage(long ImageSizeX, long ImageSizeY)
{
if(bFlagEven)
index_vram = BUF_OFFSET_1*(clientRect.top-1) + (clientRect.left-1);
else
index_vram = BUF_OFFSET_1*(clientRect.top) + (clientRect.left-1);
NoError = TRUE;
for(i=0;i<NUM_COLORS;i++){
indexES[i]=0;
NumberOfLabel[i]=0;
}
for(i=0;i<NUM_COLORS;i++)
for(j=0;j<MAX_NUM_ESET;j++)
ES[i][j][0] = 0; // Initialization of # of labels in j-th ES of i-th color
for(i=0;i<NUM_COLORS;i++)
for(j=0;j<MAX_NUM_LABEL;j++)
whichES[i][j] = 0;
for(i=0;i<rectBoundary.top;i++){ // 0 <= i < rectBoundary.top
index_vram += BUF_OFFSET_1;
for(j=0;j<ImageSizeX;j++) {
label[i][j] = NONE_COLOR;
ColorOfLabel[i][j] = NONE_COLOR;
}
}
for(i=(short)rectBoundary.top;i<=rectBoundary.bottom;i++) { // rectBoundary.top <= i <= rectBoundary.bottom
if(i%2 == 1) {
index_vram += BUF_OFFSET_1;
for(j=0;j<ImageSizeX;j++) {
label[i][j] = label[i-1][j];
ColorOfLabel[i][j] = ColorOfLabel[i-1][j];
}
continue;
}
index_vram++; // j == 0;
label[i][0] = NONE_COLOR;
ColorOfLabel[i][0] = NONE_COLOR;
for(j=1;j<ImageSizeX;j++) { // j > 0
index_lut = ((long *)PointPhys)[index_vram] & 0x00ffffff;
index_vram++;
if(LUTcolor[index_lut] == NONE_COLOR)
whichColor = NONE_COLOR;
else if(LUTcolor[index_lut] == BALL_COLOR)
whichColor = BALL_COLOR;
else if(LUTcolor[index_lut] == TEAM_COLOR)
whichColor = TEAM_COLOR;
else if(LUTcolor[index_lut] == ID1_COLOR)
whichColor = ID1_COLOR;
else if(LUTcolor[index_lut] == ID2_COLOR)
whichColor = ID2_COLOR;
else if(LUTcolor[index_lut] == ID3_COLOR)
whichColor = ID3_COLOR;
else if(LUTcolor[index_lut] == OPPONENT_COLOR)
whichColor = OPPONENT_COLOR;
else // redundant
whichColor = NONE_COLOR;
if(whichColor == NONE_COLOR){
label[i][j] = NONE_COLOR;
ColorOfLabel[i][j] = NONE_COLOR;
}
else { //if(whichColor > NONE_COLOR){ ; //if(i>0 && j>0 && whichColor > -1){
ColorOfLabel[i][j] = whichColor;
UpperLabel = label[i-1][j];
LeftLabel = label[i][j-1];
ColorOfUpperLabel = ColorOfLabel[i-1][j];
ColorOfLeftLabel = ColorOfLabel[i][j-1];
if(whichColor == ColorOfUpperLabel && whichColor != ColorOfLeftLabel)
label[i][j] = UpperLabel;
else if(whichColor != ColorOfUpperLabel && whichColor == ColorOfLeftLabel)
label[i][j] = LeftLabel;
else if(whichColor == ColorOfUpperLabel && whichColor == ColorOfLeftLabel){
if(UpperLabel == LeftLabel)
label[i][j] = UpperLabel;
else{
label[i][j] = UpperLabel;
if(whichES[whichColor][UpperLabel] && !whichES[whichColor][LeftLabel]){
indexES1 = whichES[whichColor][UpperLabel];
ES[whichColor][indexES1][2] = min(ES[whichColor][indexES1][2], LeftLabel);
WhereAppended = ES[whichColor][indexES1][1] + 3;
if(WhereAppended < MAX_NUM_ELABEL){
ES[whichColor][indexES1][WhereAppended] = LeftLabel;
ES[whichColor][indexES1][1]++;
whichES[whichColor][LeftLabel] = indexES1;
}
else
NoError = FALSE;
}
else if(!whichES[whichColor][UpperLabel] && whichES[whichColor][LeftLabel]){
indexES2 = whichES[whichColor][LeftLabel];
ES[whichColor][indexES2][2] = min(ES[whichColor][indexES2][2], UpperLabel);
WhereAppended = ES[whichColor][indexES2][1] + 3;
if(WhereAppended < MAX_NUM_ELABEL){
ES[whichColor][indexES2][WhereAppended] = UpperLabel;
ES[whichColor][indexES2][1]++;
whichES[whichColor][UpperLabel] = indexES2;
}
else
NoError = FALSE;
}
else if(whichES[whichColor][UpperLabel] && whichES[whichColor][LeftLabel] &&
whichES[whichColor][UpperLabel] != whichES[whichColor][LeftLabel] ){
indexES1 = whichES[whichColor][UpperLabel];
indexES2 = whichES[whichColor][LeftLabel];
sizeES1 = ES[whichColor][indexES1][1];
sizeES2 = ES[whichColor][indexES2][1];
ES[whichColor][indexES2][0] = 0; // invalidation of LeftLabel's ES
ES[whichColor][indexES1][1] = sizeES1 + sizeES2; // summation of sizes of two ES's
ES[whichColor][indexES1][2] = min(ES[whichColor][indexES1][2], ES[whichColor][indexES2][2]);
SumOfSize = sizeES1 + sizeES2 + 3;
if(SumOfSize <= MAX_NUM_ELABEL){
index=0;
for(WhereAppended = sizeES1 + 3; WhereAppended < SumOfSize; WhereAppended++){
tmpLabel = ES[whichColor][indexES2][index+3];
index++;
ES[whichColor][indexES1][WhereAppended] = tmpLabel;
whichES[whichColor][tmpLabel] = indexES1;
}
}
else
NoError = FALSE;
}
}
}
else if(whichColor != ColorOfUpperLabel && whichColor != ColorOfLeftLabel){
indexes_whichcolor = indexES[whichColor];
numberoflabel_whichcolor = NumberOfLabel[whichColor];
if(indexes_whichcolor < MAXNUMESET_1 && numberoflabel_whichcolor < MAXNUMLABEL_1){
indexES[whichColor]++;
NumberOfLabel[whichColor]++;
indexes_whichcolor++;
numberoflabel_whichcolor++;
label[i][j] = numberoflabel_whichcolor;
ES[whichColor][indexes_whichcolor][0] = 1; // ES valid flag
ES[whichColor][indexes_whichcolor][1] = 1; // # of label (size of ES)
ES[whichColor][indexes_whichcolor][2] = numberoflabel_whichcolor;
ES[whichColor][indexes_whichcolor][3] = numberoflabel_whichcolor;
whichES[whichColor][numberoflabel_whichcolor] = indexes_whichcolor;
}
else
NoError = FALSE;
}
}
}
index_vram += BUF_OFFSET_2;
//if(i%2 == 1)
// index_vram += BUF_OFFSET_1;
}
for(i=rectBoundary.bottom+1;i<ImageSizeY;i++){ // rectBoundary.bottom < i < ImageSizeY
for(j=0;j<ImageSizeX;j++) {
label[i][j] = NONE_COLOR;
ColorOfLabel[i][j] = NONE_COLOR;
}
}
// Execute only when above labeling operation is all right
if(NoError == TRUE){
// Determine components from valid ES's of each color and Store the number of components of each color
for(whichColor=0;whichColor<NUM_COLORS;whichColor++){
NumberOfComponent[whichColor]=0; // # of components of each color
for(indexes_whichcolor = 1;indexes_whichcolor <= indexES[whichColor];indexes_whichcolor++)
if(ES[whichColor][indexes_whichcolor][0] == 1 ){
// component of a valid ES of each color
whichComponent[whichColor][indexes_whichcolor] = NumberOfComponent[whichColor];
NumberOfComponent[whichColor]++;
}
}
// Initialize the pixel size of every component of each color
for(whichColor=0;whichColor<NUM_COLORS;whichColor++)
for(j=0;j < NumberOfComponent[whichColor]; j++)
PixelSizeOfComponent[whichColor][j] = 0;
// Get X & Y position and number of pixels compromising components of each color
for(i=0;i<ImageSizeY;i++)
for(j=0;j<ImageSizeX;j++)
if(ColorOfLabel[i][j] > NONE_COLOR){
whichColor = ColorOfLabel[i][j];
indexes_whichcolor = whichES[whichColor][label[i][j]];
whichcomponent = whichComponent[whichColor][indexes_whichcolor];
index = PixelSizeOfComponent[whichColor][whichcomponent];
Component[whichColor][whichcomponent][index][0] = j; // Save X position
Component[whichColor][whichcomponent][index][1] = i; // Save Y position
if(index < MAXPIXSIZE_1)
PixelSizeOfComponent[whichColor][whichcomponent]++; // Increase pixel size by 1
else
NoError = FALSE;
}
// Get center position of each component
for(whichColor=0;whichColor<NUM_COLORS;whichColor++)
for(whichcomponent=0;whichcomponent<NumberOfComponent[whichColor];whichcomponent++){
SumOfX[whichColor][whichcomponent] = 0;
SumOfY[whichColor][whichcomponent] = 0;
for(index=0;index<PixelSizeOfComponent[whichColor][whichcomponent];index++){
SumOfX[whichColor][whichcomponent] += Component[whichColor][whichcomponent][index][0];
SumOfY[whichColor][whichcomponent] += Component[whichColor][whichcomponent][index][1];
}
CenterXOfComponent[whichColor][whichcomponent] = SumOfX[whichColor][whichcomponent] / PixelSizeOfComponent[whichColor][whichcomponent];
CenterYOfComponent[whichColor][whichcomponent] = SumOfY[whichColor][whichcomponent] / PixelSizeOfComponent[whichColor][whichcomponent];
}
}
}
*/
// 飘发欧 扩档快 郴狼 捞固瘤 单捞鸥甫 佬绢 扼骇傅 窍绊,
// 扼骇傅 搬苞 掘绢柳 阿 弊缝狼 侨伎 困摹 沥焊, 侨伎 荐 备窍扁
// OffsetX, OffsetY : 飘发欧 扩档快 哭率困
// ImageSizeX, ImageSizeY : 飘发欧 扩档快 农扁
// object : 绢恫 祸
void CVisionView::LabelingPartialImage(long OffsetX, long OffsetY, long ImageSizeX, long ImageSizeY, short object)
{
if(bFlagEven)ぇ
index_vram = BUF_OFFSET_1*(clientRect.top + OffsetY -1) + (clientRect.left + OffsetX-1);
else
index_vram = BUF_OFFSET_1*(clientRect.top + OffsetY) + (clientRect.left + OffsetX-1);
NoError = TRUE;
switch(object) {
case HOME1 :
case HOME2 :
// case HOME3 :
// case HOME4 :
case HGOALIE :
for(i=TEAM_COLOR;i<=ID1_COLOR;i++) {
indexES[i]=0;
NumberOfLabel[i]=0;
}
for(i=TEAM_COLOR;i<=ID1_COLOR;i++) {
for(j=0;j<PARTIAL_MAX_NUM_ESET;j++)
ES[i][j][0] = 0; // Initialization of # of labels in j-th ES of i-th color
for(j=0;j<PARTIAL_MAX_NUM_LABEL;j++)
whichES[i][j] = 0;
}
break;
case BALL :
indexES[BALL_COLOR]=0;
NumberOfLabel[BALL_COLOR]=0;
for(j=0;j<PARTIAL_MAX_NUM_ESET;j++)
ES[BALL_COLOR][j][0] = 0;
for(j=0;j<PARTIAL_MAX_NUM_LABEL;j++)
whichES[BALL_COLOR][j] = 0;
break;
case OPPONENT_C :
indexES[OPPONENT_COLOR]=0;
NumberOfLabel[OPPONENT_COLOR]=0;
for(j=0;j<PARTIAL_MAX_NUM_ESET;j++)
ES[OPPONENT_COLOR][j][0] = 0;
for(j=0;j<PARTIAL_MAX_NUM_LABEL;j++)
whichES[OPPONENT_COLOR][j] = 0;
break;
}
index_vram += BUF_OFFSET_1; // i == 0
for(j=0;j<ImageSizeX;j++) {
label[0][j] = NONE_COLOR;
ColorOfLabel[0][j] = NONE_COLOR;
}
for(i=1;i<ImageSizeY;i++) { // i > 0
if(i%2 == 1) {
index_vram += BUF_OFFSET_1;
for(j=0;j<ImageSizeX;j++) {
label[i][j] = label[i-1][j];
ColorOfLabel[i][j] = ColorOfLabel[i-1][j];
}
continue;
}
index_vram++; // j == 0
label[i][0] = NONE_COLOR;
ColorOfLabel[i][0] = NONE_COLOR;
for(j=1;j<ImageSizeX;j++) { // j > 0
index_lut = ((long *)PointPhys)[index_vram] & 0x00ffffff;
index_vram++;
switch(object) {
case BALL :
if(LUTcolor[index_lut] == NONE_COLOR)
whichColor = NONE_COLOR;
else if(LUTcolor[index_lut] == BALL_COLOR)
whichColor = BALL_COLOR;
else //redunant
whichColor = NONE_COLOR;
break;
case HOME1 :
case HOME2 :
// case HOME3 :
// case HOME4 :
case HGOALIE :
if(LUTcolor[index_lut] == NONE_COLOR)
whichColor = NONE_COLOR;
else if(LUTcolor[index_lut] == TEAM_COLOR)
whichColor = TEAM_COLOR;
else if(LUTcolor[index_lut] == ID1_COLOR)
whichColor = ID1_COLOR;
else
whichColor = NONE_COLOR;
break;
case OPPONENT_C :
if(LUTcolor[index_lut] == NONE_COLOR)
whichColor = NONE_COLOR;
else if(LUTcolor[index_lut] == OPPONENT_COLOR)
whichColor = OPPONENT_COLOR;
else //redunant
whichColor = NONE_COLOR;
break;
}
if(whichColor == NONE_COLOR){
label[i][j] = -1;
ColorOfLabel[i][j] = -1;
}
else { //if(i>0 && j>0 && whichColor > -1){
ColorOfLabel[i][j] = whichColor;
UpperLabel = label[i-1][j];
LeftLabel = label[i][j-1];
ColorOfUpperLabel = ColorOfLabel[i-1][j];
ColorOfLeftLabel = ColorOfLabel[i][j-1];
if(whichColor == ColorOfUpperLabel && whichColor != ColorOfLeftLabel)
label[i][j] = UpperLabel;
else if(whichColor != ColorOfUpperLabel && whichColor == ColorOfLeftLabel)
label[i][j] = LeftLabel;
else if(whichColor == ColorOfUpperLabel && whichColor == ColorOfLeftLabel){
if(UpperLabel == LeftLabel)
label[i][j] = UpperLabel;
else{
label[i][j] = UpperLabel;
if(whichES[whichColor][UpperLabel] && !whichES[whichColor][LeftLabel]){
indexES1 = whichES[whichColor][UpperLabel];
ES[whichColor][indexES1][2] = min(ES[whichColor][indexES1][2], LeftLabel);
WhereAppended = ES[whichColor][indexES1][1] + 3;
if(WhereAppended < MAX_NUM_ELABEL){
ES[whichColor][indexES1][WhereAppended] = LeftLabel;
ES[whichColor][indexES1][1]++;
whichES[whichColor][LeftLabel] = indexES1;
}
else
NoError = FALSE;
}
else if(!whichES[whichColor][UpperLabel] && whichES[whichColor][LeftLabel]){
indexES2 = whichES[whichColor][LeftLabel];
ES[whichColor][indexES2][2] = min(ES[whichColor][indexES2][2], UpperLabel);
WhereAppended = ES[whichColor][indexES2][1] + 3;
if(WhereAppended < MAX_NUM_ELABEL){
ES[whichColor][indexES2][WhereAppended] = UpperLabel;
ES[whichColor][indexES2][1]++;
whichES[whichColor][UpperLabel] = indexES2;
}
else
NoError = FALSE;
}
else if(whichES[whichColor][UpperLabel] && whichES[whichColor][LeftLabel] &&
whichES[whichColor][UpperLabel] != whichES[whichColor][LeftLabel] ){
indexES1 = whichES[whichColor][UpperLabel];
indexES2 = whichES[whichColor][LeftLabel];
sizeES1 = ES[whichColor][indexES1][1];
sizeES2 = ES[whichColor][indexES2][1];
ES[whichColor][indexES2][0] = 0; // invalidation of LeftLabel's ES
ES[whichColor][indexES1][1] = sizeES1 + sizeES2; // summation of sizes of two ES's
ES[whichColor][indexES1][2] = min(ES[whichColor][indexES1][2], ES[whichColor][ind
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?