在图像上画矩形 opencv

IplImage * c_allImage =cvCloneImage(image);

         cv::Matmtx(c_allImage, 0);

//画矩形的上面的边,宽度为5

         for(int j = origin_upToup; j < origin_upToup + 5; j++)

                   for(inti = origin_leftToleft; i < origin_leftToleft + origin_width; i++)

                             for(int n = 0;n < mtx.channels(); n++){

                                     if(n == 0) mtx.at(origin_upToup,i * mtx.channels() + n) = 255;   //取得像素或者赋值

                                     else

                                               mtx.at(j,i* mtx.channels() + n) = 0;

                            }

//画矩形的下面的边,宽度为5

         for(int j = origin_upToup; j < origin_upToup + 5; j++)

                   for(inti = origin_leftToleft; i < origin_leftToleft + origin_width; i++)

                             for(int n = 0; n < mtx.channels(); n++){

                                      if (n == 0)mtx.at(origin_upToup,i * mtx.channels() + n) = 255;   //取得像素或者赋值

                                      else

                                                mtx.at((j + origin_height),i *mtx.channels() + n) = 0;

                            }

//画矩形的左面的边,宽度为5

         for(int j = origin_leftToleft; j < origin_leftToleft + 5; j++)

                   for(inti = origin_upToup; i < origin_upToup + origin_height; i++)

                             for(int n = 0; n < mtx.channels(); n++){

                                      if (n == 0) mtx.at(i,origin_leftToleft* mtx.channels() + n) = 255;   //取得像素或者赋值

                                      else

                                                mtx.at(i,j * mtx.channels() + n)= 0;

                            }

//画矩形的右面的边,宽度为5

         for(int j = origin_leftToleft; j > origin_leftToleft - 5; j--)

                   for(inti = origin_upToup; i < origin_upToup + origin_height; i++)

                             for(int n = 0; n < mtx.channels(); n++){

                                      if (n == 0)mtx.at(i,(origin_leftToleft + origin_width) * mtx.channels() + n)= 255;   //取得像素或者赋值

                                      else

                                                mtx.at(i,(j + origin_width) *mtx.channels() + n) = 0;

                            }

         *c_allImage= IplImage(mtx);

你可能感兴趣的:(opencv)